This repository has been archived by the owner on May 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/agoda-com/Kakao into rele…
…ase/2.1.0
- Loading branch information
Showing
15 changed files
with
465 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
kakao/src/main/kotlin/com/agoda/kakao/picker/date/DatePickerAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.agoda.kakao.picker.date | ||
|
||
import androidx.test.espresso.contrib.PickerActions | ||
import com.agoda.kakao.common.actions.BaseActions | ||
|
||
/** | ||
* Provides actions for date picker | ||
*/ | ||
interface DatePickerAction : BaseActions { | ||
/** | ||
* Set date to picker dialog | ||
* Month number will be normalized | ||
* | ||
* @param year year | ||
* @param monthOfYear month | ||
* @param day day | ||
*/ | ||
fun setDate(year: Int, monthOfYear: Int, day: Int) = view.perform(PickerActions.setDate(year, monthOfYear, day)) | ||
} |
80 changes: 80 additions & 0 deletions
80
kakao/src/main/kotlin/com/agoda/kakao/picker/date/DatePickerAssertion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.agoda.kakao.picker.date | ||
|
||
import android.widget.DatePicker | ||
import androidx.test.espresso.ViewAssertion | ||
import com.agoda.kakao.common.actions.BaseActions | ||
|
||
/** | ||
* Provides assertions for date picker | ||
*/ | ||
interface DatePickerAssertion : BaseActions { | ||
|
||
/** | ||
* Check if picker dialog contain selected date | ||
* Month number will be normalized | ||
* | ||
* @param year year | ||
* @param monthOfYear month | ||
* @param day day | ||
*/ | ||
fun hasDate(year: Int, monthOfYear: Int, day: Int) { | ||
hasYear(year) | ||
hasMonth(monthOfYear) | ||
hasDay(day) | ||
} | ||
|
||
/** | ||
* Check if picker dialog contain selected day | ||
* | ||
* @param day day | ||
*/ | ||
fun hasDay(day: Int) { | ||
view.check(ViewAssertion { view, notFoundException -> | ||
if (view is DatePicker) { | ||
if (day != view.dayOfMonth) { | ||
throw AssertionError("Expected day is $day," + | ||
" but actual is ${view.dayOfMonth}") | ||
} | ||
} else { | ||
notFoundException?.let { throw AssertionError(it) } | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Check if picker dialog contain selected month | ||
* | ||
* @param monthOfYear month | ||
*/ | ||
fun hasMonth(monthOfYear: Int) { | ||
val normalizedMonthOfYear = monthOfYear - 1 | ||
view.check(ViewAssertion { view, notFoundException -> | ||
if (view is DatePicker) { | ||
if (normalizedMonthOfYear != view.month) { | ||
throw AssertionError("Expected month is $normalizedMonthOfYear," + | ||
" but actual is ${view.month}") | ||
} | ||
} else { | ||
notFoundException?.let { throw AssertionError(it) } | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Check if picker dialog contain selected year | ||
* | ||
* @param year year | ||
*/ | ||
fun hasYear(year: Int) { | ||
view.check(ViewAssertion { view, notFoundException -> | ||
if (view is DatePicker) { | ||
if (year != view.year) { | ||
throw AssertionError("Expected year is $year," + | ||
" but actual is ${view.year}") | ||
} | ||
} else { | ||
notFoundException?.let { throw AssertionError(it) } | ||
} | ||
}) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
kakao/src/main/kotlin/com/agoda/kakao/picker/date/KDatePicker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.agoda.kakao.picker.date | ||
|
||
import android.view.View | ||
import android.widget.DatePicker | ||
import androidx.test.espresso.DataInteraction | ||
import com.agoda.kakao.common.builders.ViewBuilder | ||
import com.agoda.kakao.common.views.KBaseView | ||
import org.hamcrest.Matcher | ||
|
||
/** | ||
* View for interact with default date picker | ||
* | ||
* @see DatePicker | ||
*/ | ||
class KDatePicker : KBaseView<KDatePicker>, DatePickerAction, DatePickerAssertion { | ||
constructor(function: ViewBuilder.() -> Unit) : super(function) | ||
constructor(parent: Matcher<View>, function: ViewBuilder.() -> Unit) : super(parent, function) | ||
constructor(parent: DataInteraction, function: ViewBuilder.() -> Unit) : super(parent, function) | ||
} |
27 changes: 27 additions & 0 deletions
27
kakao/src/main/kotlin/com/agoda/kakao/picker/date/KDatePickerDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.agoda.kakao.picker.date | ||
|
||
import android.app.DatePickerDialog | ||
import android.widget.DatePicker | ||
import com.agoda.kakao.common.views.KBaseView | ||
import com.agoda.kakao.text.KButton | ||
|
||
/** | ||
* View for interact with default date picker dialog | ||
* | ||
* @see DatePickerDialog | ||
*/ | ||
class KDatePickerDialog : KBaseView<KDatePickerDialog>({ isRoot() }) { | ||
|
||
init { | ||
inRoot { isDialog() } | ||
} | ||
|
||
val datePicker = KDatePicker { isInstanceOf(DatePicker::class.java) } | ||
.also { it.inRoot { isDialog() } } | ||
|
||
val okButton = KButton { withId(android.R.id.button1) } | ||
.also { it.inRoot { isDialog() } } | ||
|
||
val cancelButton = KButton { withId(android.R.id.button2) } | ||
.also { it.inRoot { isDialog() } } | ||
} |
19 changes: 19 additions & 0 deletions
19
kakao/src/main/kotlin/com/agoda/kakao/picker/time/KTimePicker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.agoda.kakao.picker.time | ||
|
||
import android.view.View | ||
import android.widget.TimePicker | ||
import androidx.test.espresso.DataInteraction | ||
import com.agoda.kakao.common.builders.ViewBuilder | ||
import com.agoda.kakao.common.views.KBaseView | ||
import org.hamcrest.Matcher | ||
|
||
/** | ||
* View for interact with default time picker | ||
* | ||
* @see TimePicker | ||
*/ | ||
class KTimePicker : KBaseView<KTimePicker>, TimePickerAction, TimePickerAssertion { | ||
constructor(function: ViewBuilder.() -> Unit) : super(function) | ||
constructor(parent: Matcher<View>, function: ViewBuilder.() -> Unit) : super(parent, function) | ||
constructor(parent: DataInteraction, function: ViewBuilder.() -> Unit) : super(parent, function) | ||
} |
28 changes: 28 additions & 0 deletions
28
kakao/src/main/kotlin/com/agoda/kakao/picker/time/KTimePickerDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.agoda.kakao.picker.time | ||
|
||
import android.app.TimePickerDialog | ||
import android.widget.TimePicker | ||
import com.agoda.kakao.common.views.KBaseView | ||
import com.agoda.kakao.text.KButton | ||
|
||
/** | ||
* View for interact with default date picker dialog | ||
* | ||
* @see TimePickerDialog | ||
*/ | ||
class KTimePickerDialog : KBaseView<KTimePickerDialog>({ isRoot() }) { | ||
|
||
init { | ||
inRoot { isDialog() } | ||
} | ||
|
||
val timePicker = KTimePicker { isInstanceOf(TimePicker::class.java) }.also { | ||
it.inRoot { isDialog() } | ||
} | ||
|
||
val okButton = KButton { withId(android.R.id.button1) } | ||
.also { it.inRoot { isDialog() } } | ||
|
||
val cancelButton = KButton { withId(android.R.id.button2) } | ||
.also { it.inRoot { isDialog() } } | ||
} |
16 changes: 16 additions & 0 deletions
16
kakao/src/main/kotlin/com/agoda/kakao/picker/time/TimePickerAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.agoda.kakao.picker.time | ||
|
||
import androidx.test.espresso.contrib.PickerActions | ||
import com.agoda.kakao.common.actions.BaseActions | ||
|
||
/** | ||
* Provides actions for time picker | ||
*/ | ||
interface TimePickerAction : BaseActions { | ||
/** | ||
* Set time to picker dialog | ||
* | ||
* @param | ||
*/ | ||
fun setTime(hour: Int, minutes: Int) = view.perform(PickerActions.setTime(hour, minutes)) | ||
} |
58 changes: 58 additions & 0 deletions
58
kakao/src/main/kotlin/com/agoda/kakao/picker/time/TimePickerAssertion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.agoda.kakao.picker.time | ||
|
||
import android.widget.TimePicker | ||
import androidx.test.espresso.ViewAssertion | ||
import com.agoda.kakao.common.actions.BaseActions | ||
|
||
/** | ||
* Provides assertions for time picker | ||
*/ | ||
interface TimePickerAssertion : BaseActions { | ||
|
||
/** | ||
* Check if picker dialog contain selected time | ||
* | ||
* @param hour hour | ||
* @param minute monute | ||
*/ | ||
fun hasTime(hour: Int, minute: Int) { | ||
hasHour(hour) | ||
hasMinute(minute) | ||
} | ||
|
||
/** | ||
* Check if picker dialog contain selected hour | ||
* | ||
* @param hour hour | ||
*/ | ||
fun hasHour(hour: Int) { | ||
view.check(ViewAssertion { view, notFoundException -> | ||
if (view is TimePicker) { | ||
if (hour != view.currentHour) { | ||
throw AssertionError("Expected hour is $hour," + | ||
" but actual is ${view.currentHour}") | ||
} | ||
} else { | ||
notFoundException?.let { throw AssertionError(it) } | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Check if picker dialog contain selected minute | ||
* | ||
* @param minute month | ||
*/ | ||
fun hasMinute(minute: Int) { | ||
view.check(ViewAssertion { view, notFoundException -> | ||
if (view is TimePicker) { | ||
if (minute != view.currentMinute) { | ||
throw AssertionError("Expected minutes is $minute," + | ||
" but actual is ${view.currentMinute}") | ||
} | ||
} else { | ||
notFoundException?.let { throw AssertionError(it) } | ||
} | ||
}) | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
sample/src/androidTest/kotlin/com/agoda/sample/PickersTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.agoda.sample | ||
|
||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner | ||
import androidx.test.rule.ActivityTestRule | ||
import com.agoda.kakao.screen.Screen | ||
import com.agoda.sample.screen.PickersActivityScreen | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4ClassRunner::class) | ||
class PickersTest { | ||
@Rule | ||
@JvmField | ||
val rule = ActivityTestRule(PickersActivity::class.java) | ||
|
||
@Test | ||
fun testDatePickerDialog() { | ||
Screen.onScreen<PickersActivityScreen> { | ||
selectDateButton { | ||
click() | ||
} | ||
|
||
datePickerDialog { | ||
datePicker { | ||
setDate(1955, 11, 12) | ||
hasDate(1955, 11, 12) | ||
} | ||
cancelButton { | ||
click() | ||
} | ||
} | ||
|
||
selectDateButton { | ||
click() | ||
} | ||
|
||
datePickerDialog { | ||
datePicker { | ||
setDate(1955, 11, 12) | ||
} | ||
okButton { | ||
click() | ||
} | ||
} | ||
|
||
dateText { | ||
hasText("12 11 1955") | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun testTimePickerDialog() { | ||
Screen.onScreen<PickersActivityScreen> { | ||
selectTimeButton { | ||
click() | ||
} | ||
|
||
timePickerDialog { | ||
timePicker { | ||
setTime(22, 4) | ||
hasTime(22, 4) | ||
} | ||
cancelButton { | ||
click() | ||
} | ||
} | ||
|
||
selectTimeButton { | ||
click() | ||
} | ||
|
||
timePickerDialog { | ||
timePicker { | ||
setTime(22, 4) | ||
} | ||
okButton { | ||
click() | ||
} | ||
} | ||
|
||
timeText { | ||
hasText("22:4") | ||
} | ||
|
||
selectDateButton { | ||
click() | ||
} | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
sample/src/androidTest/kotlin/com/agoda/sample/screen/PickersActivityScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.agoda.sample.screen | ||
|
||
import com.agoda.kakao.common.views.KView | ||
import com.agoda.kakao.picker.date.KDatePickerDialog | ||
import com.agoda.kakao.picker.time.KTimePickerDialog | ||
|
||
import com.agoda.kakao.screen.Screen | ||
import com.agoda.kakao.text.KTextView | ||
import com.agoda.sample.R | ||
|
||
open class PickersActivityScreen : Screen<PickersActivityScreen>() { | ||
val selectDateButton: KView = KView { withId(R.id.select_date) } | ||
val selectTimeButton: KView = KView { withId(R.id.select_time) } | ||
|
||
val dateText: KTextView = KTextView { | ||
withId(R.id.date_field) | ||
} | ||
|
||
val timeText: KTextView = KTextView { | ||
withId(R.id.time_field) | ||
} | ||
|
||
val datePickerDialog: KDatePickerDialog = KDatePickerDialog() | ||
val timePickerDialog: KTimePickerDialog = KTimePickerDialog() | ||
} |
Oops, something went wrong.