Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import android.os.Bundle
import android.widget.DatePicker
import android.widget.TextView
import com.facebook.react.bridge.ReadableMap
import com.magicleap.magicscript.ar.renderable.ViewRenderableLoader
import com.magicleap.magicscript.ar.clip.Clipper
import com.magicleap.magicscript.ar.renderable.ViewRenderableLoader
import com.magicleap.magicscript.scene.nodes.base.UiDateTimePickerBaseNode
import com.magicleap.magicscript.scene.nodes.views.DialogProvider
import com.magicleap.magicscript.utils.VerySimpleDateFormat
Expand Down Expand Up @@ -147,6 +147,7 @@ open class UiDatePickerNode(
private fun applyDate(props: Bundle) {
if (props.containsKey(PROP_DATE)) {
date = dateFormat.parse(props.getString(PROP_DATE))
view.value.setText(dateFormat.format(date), TextView.BufferType.EDITABLE)
}
}

Expand All @@ -159,7 +160,7 @@ open class UiDatePickerNode(
if (props.getBoolean(PROP_SHOW_HINT)) {
view.value.hint = dateFormat.pattern
} else {
if(defaultDate == null) {
if (defaultDate == null) {
defaultDate = Date()
}
view.value.hint = dateFormat.format(defaultDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ open class UiTimePickerNode(
showing = false
}

protected val onTimeChangeListener: (Int, Int) -> Unit = { hourOfDay: Int, minute: Int ->
private val onTimeChangeListener: (Int, Int) -> Unit = { hourOfDay: Int, minute: Int ->
onTimeChanged?.invoke("$hourOfDay:$minute")
}


init {
properties.putDefault(PROP_TIME_FORMAT, TIME_FORMAT_DEFAULT)
}
Expand Down Expand Up @@ -128,8 +127,7 @@ open class UiTimePickerNode(
private fun applyDefaultTime(props: BaseBundle) {
if (props.containsKey(PROP_DEFAULT_TIME)) {
props.getString(PROP_DEFAULT_TIME)?.let {
time = defaultTimeFormat.parse(it)
view.value.setText(timeFormat.format(time), TextView.BufferType.EDITABLE)
defaultTime = defaultTimeFormat.parse(it)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class UiDatePickerNodeTest {
private val datePickerDialogProvider = mock<DialogProviderImpl>().apply {
whenever(provideDatePickerDialog(any())).doReturn(datePickerDialog)
}
var tested: TestableUiDatePickerNode = TestableUiDatePickerNode(datePickerDialogProvider)
private val tested: TestableUiDatePickerNode =
TestableUiDatePickerNode(datePickerDialogProvider)

@After
fun validate() {
Expand All @@ -78,56 +79,81 @@ class UiDatePickerNodeTest {
tested.getProperty(PROP_DATE_FORMAT) shouldEqual DATE_FORMAT_DEFAULT
}

@Test
fun `should apply date property`() {
val dateText = "01/05/2011"

tested.update(
reactMapOf(
PROP_DATE, dateText,
PROP_DATE_FORMAT, DATE_FORMAT_DEFAULT
)
)

verify(tested.dateText).setText(eq(dateText), any())
}

@Test
fun `should apply label text`() {
val label = "test test test"
tested.update(reactMapOf(
PROP_LABEL, label,
PROP_DATE_FORMAT, DATE_FORMAT_DEFAULT))

tested.update(reactMapOf(PROP_LABEL, label, PROP_DATE_FORMAT, DATE_FORMAT_DEFAULT))

verify(tested.titleText).text = label
}

@Test
fun `should set vertical orientation when label side is top`() {
tested.update(reactMapOf(
PROP_LABEL_SIDE, LABEL_SIDE_TOP,
PROP_DATE_FORMAT, DATE_FORMAT_DEFAULT))
tested.update(
reactMapOf(
PROP_LABEL_SIDE, LABEL_SIDE_TOP,
PROP_DATE_FORMAT, DATE_FORMAT_DEFAULT
)
)

verify(tested.mainView).orientation = LinearLayout.VERTICAL
}

@Test
fun `should set horizontal orientation when label side is left`() {
tested.update(reactMapOf(
PROP_LABEL_SIDE, LABEL_SIDE_LEFT,
PROP_DATE_FORMAT, DATE_FORMAT_DEFAULT))
tested.update(
reactMapOf(
PROP_LABEL_SIDE, LABEL_SIDE_LEFT,
PROP_DATE_FORMAT, DATE_FORMAT_DEFAULT
)
)

verify(tested.mainView).orientation = LinearLayout.HORIZONTAL
}

@Test
fun `dateFormat should update hint on date text`() {
val dateFormat = "DD/YYYY"
tested.update(reactMapOf(
PROP_DATE_FORMAT, dateFormat,
PROP_SHOW_HINT, true))
tested.update(
reactMapOf(
PROP_DATE_FORMAT, dateFormat,
PROP_SHOW_HINT, true
)
)

verify(tested.dateText).hint = dateFormat
}

@Test
fun `on view click should create dialog with default date`() {
val dateText = "01/08/2150"
tested.update(
reactMapOf(
PROP_DEFAULT_DATE, "13/12/2011",
PROP_DEFAULT_DATE, dateText,
PROP_DATE_FORMAT, DATE_FORMAT_DEFAULT
)
)
val date = SimpleDateFormat(DATE_FORMAT_DEFAULT).parse(dateText)

tested.performClick()

verify(datePickerDialogProvider).provideDatePickerDialog(any())
verify(datePickerDialog).updateDate(date)
}

@Test
Expand Down Expand Up @@ -163,7 +189,6 @@ class UiDatePickerNodeTest {
PROP_DATE_FORMAT, DATE_FORMAT_DEFAULT
)
)

val date = SimpleDateFormat(DATE_FORMAT_DEFAULT).parse(textDate)

tested.performClick()
Expand Down Expand Up @@ -209,21 +234,18 @@ class UiDatePickerNodeTest {
}

@Test
fun `should update dateValue when date set`() {
fun `should set date text selected from picker`() {
tested.update(
reactMapOf(
PROP_DEFAULT_DATE, "13/12/2011",
PROP_DATE_FORMAT, DATE_FORMAT_DEFAULT
)
)
val dateFormat = VerySimpleDateFormat(DATE_FORMAT_DEFAULT, Locale.getDefault())

tested.performClick()
tested.onDateConfirmed = mock()
tested.provideDialogOnDateSetListener().invoke(datePicker, 2019, Calendar.NOVEMBER, 12)
val dateFormat = VerySimpleDateFormat(
DATE_FORMAT_DEFAULT,
Locale.getDefault()
)

verify(tested.dateText).setText(eq(dateFormat.format(2019, 11, 12)), any())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ import java.util.*

@RunWith(RobolectricTestRunner::class)
class UiTimePickerNodeTest {
val timePickerDialog = mock<NotifiableTimePickerDialog>(defaultAnswer = Mockito.RETURNS_MOCKS)
val datePickerDialogProvider = mock<DialogProviderImpl>().apply {
private val timePickerDialog =
mock<NotifiableTimePickerDialog>(defaultAnswer = Mockito.RETURNS_MOCKS)
private val datePickerDialogProvider = mock<DialogProviderImpl>().apply {
whenever(provideTimePickerDialog(any(), any(), any())).doReturn(timePickerDialog)
}
var tested: TestableUiTimePickerNode = TestableUiTimePickerNode(datePickerDialogProvider)
private val tested: TestableUiTimePickerNode =
TestableUiTimePickerNode(datePickerDialogProvider)

@After
fun validate() {
Expand All @@ -58,15 +60,31 @@ class UiTimePickerNodeTest {
tested.getProperty(UiTimePickerNode.PROP_TIME_FORMAT) shouldEqual UiTimePickerNode.TIME_FORMAT_DEFAULT
}

@Test
fun `should apply date property`() {
val textTime = "12:40:58"

tested.update(
reactMapOf(
UiTimePickerNode.PROP_TIME_FORMAT, UiTimePickerNode.TIME_FORMAT_DEFAULT,
UiTimePickerNode.PROP_TIME, textTime
)
)

verify(tested.dateText).setText(eq(textTime), any())
}

@Test
fun `should apply label text`() {
val label = "test test test"
tested.update(reactMapOf(
UiDateTimePickerBaseNode.PROP_LABEL,
label,
UiTimePickerNode.PROP_TIME_FORMAT,
UiTimePickerNode.TIME_FORMAT_DEFAULT
))
tested.update(
reactMapOf(
UiDateTimePickerBaseNode.PROP_LABEL,
label,
UiTimePickerNode.PROP_TIME_FORMAT,
UiTimePickerNode.TIME_FORMAT_DEFAULT
)
)

verify(tested.titleText).text = label
}
Expand Down Expand Up @@ -102,10 +120,12 @@ class UiTimePickerNodeTest {
@Test
fun `time should update hint on date text`() {
val timeFormat = "HH:MM"
tested.update(reactMapOf(
UiTimePickerNode.PROP_TIME_FORMAT, timeFormat,
UiDateTimePickerBaseNode.PROP_SHOW_HINT, true
))
tested.update(
reactMapOf(
UiTimePickerNode.PROP_TIME_FORMAT, timeFormat,
UiDateTimePickerBaseNode.PROP_SHOW_HINT, true
)
)

verify(tested.dateText).hint = timeFormat
}
Expand All @@ -122,6 +142,7 @@ class UiTimePickerNodeTest {
tested.performClick()

verify(datePickerDialogProvider).provideTimePickerDialog(any(), any(), any())
verify(timePickerDialog).updateTime(14, 10)
}

@Test
Expand Down Expand Up @@ -174,22 +195,19 @@ class UiTimePickerNodeTest {
}

@Test
fun `should update timeValue when date set`() {
fun `should set time text selected from picker`() {
tested.update(
reactMapOf(
UiTimePickerNode.PROP_DEFAULT_TIME, "14:15:00",
UiTimePickerNode.PROP_TIME_FORMAT, UiTimePickerNode.TIME_FORMAT_DEFAULT
)
)
val dateFormat =
VerySimpleDateFormat(UiTimePickerNode.TIME_FORMAT_DEFAULT, Locale.getDefault())

tested.performClick()
tested.onTimeChanged = mock()
tested.provideDialogOnTimeSetListener().onTimeSet(mock(), 15, 16)
val dateFormat =
VerySimpleDateFormat(
UiTimePickerNode.TIME_FORMAT_DEFAULT,
Locale.getDefault()
)

verify(tested.dateText).setText(eq(dateFormat.format(15, 16)), any())
}
Expand Down