From 563b930982b3b9db7d90fef056b0856512fe1111 Mon Sep 17 00:00:00 2001 From: Henning Hall Date: Mon, 17 Apr 2023 20:56:01 +0200 Subject: [PATCH] chore: move some detox tests to mastro (#642) --- .maestro/display-text.yml | 2 + .maestro/timezone-offset-in-minutes.yml | 120 ++++++++++++++++++ .maestro/utils/change-prop.yml | 1 + .maestro/utils/disable-network-time-zone.yml | 4 + .../utils/goto-settings-from-app-info.yml | 7 + .maestro/utils/launch.yml | 2 - .maestro/utils/reset.yml | 4 + .maestro/utils/select-region.yml | 4 + .maestro/utils/select-utc-offset.yml | 7 + .maestro/utils/set-timezone-us.yml | 8 ++ .maestro/utils/set-timezone.yml | 32 +++++ .maestro/utils/swipe-wheel-3.yml | 5 + ...wipe-wheel-am-pm.yml => swipe-wheel-4.yml} | 0 .maestro/utils/tap-if-visible.yml | 8 ++ .maestro/utils/tap.yml | 3 + .npmignore | 1 + .../Rn069/e2e/tests/timezoneOffset.spec.js | 82 ------------ examples/Rn069/src/App.js | 4 +- examples/Rn069/src/CustomPropValue.js | 9 ++ .../detox/e2e/tests/timezoneOffset.spec.js | 81 ------------ package.json | 4 + 21 files changed, 221 insertions(+), 167 deletions(-) create mode 100644 .maestro/timezone-offset-in-minutes.yml create mode 100644 .maestro/utils/disable-network-time-zone.yml create mode 100644 .maestro/utils/goto-settings-from-app-info.yml create mode 100644 .maestro/utils/reset.yml create mode 100644 .maestro/utils/select-region.yml create mode 100644 .maestro/utils/select-utc-offset.yml create mode 100644 .maestro/utils/set-timezone-us.yml create mode 100644 .maestro/utils/set-timezone.yml create mode 100644 .maestro/utils/swipe-wheel-3.yml rename .maestro/utils/{swipe-wheel-am-pm.yml => swipe-wheel-4.yml} (100%) create mode 100644 .maestro/utils/tap-if-visible.yml create mode 100644 .maestro/utils/tap.yml delete mode 100644 examples/Rn069/e2e/tests/timezoneOffset.spec.js delete mode 100644 examples/detox/e2e/tests/timezoneOffset.spec.js diff --git a/.maestro/display-text.yml b/.maestro/display-text.yml index c85e233..3ab6290 100644 --- a/.maestro/display-text.yml +++ b/.maestro/display-text.yml @@ -1,6 +1,8 @@ appId: com.rn069 --- - runFlow: utils/launch.yml +- tapOn: androidVariant +- tapOn: nativeAndroid - runFlow: file: utils/change-prop.yml env: diff --git a/.maestro/timezone-offset-in-minutes.yml b/.maestro/timezone-offset-in-minutes.yml new file mode 100644 index 0000000..c52a107 --- /dev/null +++ b/.maestro/timezone-offset-in-minutes.yml @@ -0,0 +1,120 @@ +appId: com.rn069 +--- +- runFlow: + file: utils/set-timezone.yml + env: + TIMEZONE: Sweden + GMT: GMT+01:00 + +- runFlow: utils/launch.yml + +# test: timezone offset with undefined +- runFlow: utils/swipe-wheel-3.yml +- assertVisible: '2000-01-01 00:01:00' +- assertVisible: 'Sat Jan 11201 AM ' + +- runFlow: utils/reset.yml + +# test: timezone offset with 0 +- runFlow: + file: utils/change-prop.yml + env: + PROP: timeZoneOffsetInMinutes + VALUE: 0 +- runFlow: utils/swipe-wheel-3.yml +- assertVisible: '2000-01-01 00:01:00' +- assertVisible: 'Fri Dec 311101 PM ' + +- runFlow: utils/reset.yml + +# test: timezone offset with 180 +- runFlow: + file: utils/change-prop.yml + env: + PROP: timeZoneOffsetInMinutes + VALUE: 180 +- runFlow: utils/swipe-wheel-3.yml +- assertVisible: '2000-01-01 00:01:00' +- assertVisible: 'Sat Jan 1201 AM ' + +- runFlow: utils/reset.yml + +# test: timezone offset with -180 +- runFlow: + file: utils/change-prop.yml + env: + PROP: timeZoneOffsetInMinutes + VALUE: -180 +- runFlow: utils/swipe-wheel-3.yml +- assertVisible: '2000-01-01 00:01:00' +- assertVisible: 'Fri Dec 31801 PM ' + +########## describe: DAYLIGHT SAVING +- runFlow: + file: utils/set-timezone.yml + env: + TIMEZONE: Sweden + GMT: GMT+02:00 + +- runFlow: utils/launch.yml + +# test: timezone offset undefined +- runFlow: + file: utils/change-prop.yml + env: + PROP: maximumDate + VALUE: '2000-07-01T00:00:00' +- runFlow: + file: utils/change-prop.yml + env: + PROP: date + VALUE: '2000-06-01T00:00:00+02:00' +- runFlow: utils/swipe-wheel-3.yml +- assertVisible: '2000-06-01 00:01:00' +- assertVisible: 'Thu Jun 11201 AM ' + +- runFlow: utils/reset.yml + +# # test: timezone offset 0 +- runFlow: + file: utils/change-prop.yml + env: + PROP: maximumDate + VALUE: '2000-07-01T00:00:00' +- runFlow: + file: utils/change-prop.yml + env: + PROP: date + VALUE: '2000-06-01T00:00:00+02:00' +- runFlow: + file: utils/change-prop.yml + env: + PROP: timeZoneOffsetInMinutes + VALUE: 0 +- runFlow: utils/swipe-wheel-3.yml +- assertVisible: '2000-06-01 00:01:00' +- assertVisible: 'Wed May 311001 PM ' + +- runFlow: utils/reset.yml + +# test: timezone offset 180 +- runFlow: + file: utils/change-prop.yml + env: + PROP: maximumDate + VALUE: '2000-07-01T00:00:00' +- runFlow: + file: utils/change-prop.yml + env: + PROP: date + VALUE: '2000-06-01T00:00:00+02:00' +- runFlow: + file: utils/change-prop.yml + env: + PROP: timeZoneOffsetInMinutes + VALUE: 180 +- runFlow: utils/swipe-wheel-3.yml +- assertVisible: '2000-06-01 00:01:00' +- assertVisible: 'Thu Jun 1101 AM ' + +- runFlow: utils/reset.yml diff --git a/.maestro/utils/change-prop.yml b/.maestro/utils/change-prop.yml index 5356f06..556ed01 100644 --- a/.maestro/utils/change-prop.yml +++ b/.maestro/utils/change-prop.yml @@ -1,5 +1,6 @@ appId: com.rn069 --- +- tapOn: clear - tapOn: id: propName - inputText: ${PROP} diff --git a/.maestro/utils/disable-network-time-zone.yml b/.maestro/utils/disable-network-time-zone.yml new file mode 100644 index 0000000..581c132 --- /dev/null +++ b/.maestro/utils/disable-network-time-zone.yml @@ -0,0 +1,4 @@ +appId: com.android.settings +--- +- tapOn: 'Use network-provided time zone' +- tapOn: 'Time zone' diff --git a/.maestro/utils/goto-settings-from-app-info.yml b/.maestro/utils/goto-settings-from-app-info.yml new file mode 100644 index 0000000..5e725c4 --- /dev/null +++ b/.maestro/utils/goto-settings-from-app-info.yml @@ -0,0 +1,7 @@ +appId: com.android.settings +--- +- scrollUntilVisible: + element: + text: 'Settings' +- tapOn: 'Settings' +- tapOn: 'Open' diff --git a/.maestro/utils/launch.yml b/.maestro/utils/launch.yml index a1ee4d6..aed90f5 100644 --- a/.maestro/utils/launch.yml +++ b/.maestro/utils/launch.yml @@ -3,5 +3,3 @@ appId: com.rn069 - launchApp: stopApp: true - tapOn: Advanced -- tapOn: androidVariant -- tapOn: nativeAndroid diff --git a/.maestro/utils/reset.yml b/.maestro/utils/reset.yml new file mode 100644 index 0000000..1b7b8fe --- /dev/null +++ b/.maestro/utils/reset.yml @@ -0,0 +1,4 @@ +appId: com.rn069 +--- +- tapOn: 'Go back' +- tapOn: Advanced diff --git a/.maestro/utils/select-region.yml b/.maestro/utils/select-region.yml new file mode 100644 index 0000000..388778f --- /dev/null +++ b/.maestro/utils/select-region.yml @@ -0,0 +1,4 @@ +appId: com.android.settings +--- +- tapOn: Region +- inputText: ${TIMEZONE} diff --git a/.maestro/utils/select-utc-offset.yml b/.maestro/utils/select-utc-offset.yml new file mode 100644 index 0000000..534bfb1 --- /dev/null +++ b/.maestro/utils/select-utc-offset.yml @@ -0,0 +1,7 @@ +appId: com.android.settings +--- +- tapOn: 'Select UTC offset' +- scrollUntilVisible: + element: + text: ${GMT} +- tapOn: ${GMT} diff --git a/.maestro/utils/set-timezone-us.yml b/.maestro/utils/set-timezone-us.yml new file mode 100644 index 0000000..d5fefe9 --- /dev/null +++ b/.maestro/utils/set-timezone-us.yml @@ -0,0 +1,8 @@ +appId: com.android.settings +--- +- runFlow: + file: set-timezone.yml + env: + TIMEZONE: 'United states' + GMT: ${GMT} +- tapOn: ${STATE} diff --git a/.maestro/utils/set-timezone.yml b/.maestro/utils/set-timezone.yml new file mode 100644 index 0000000..c84193e --- /dev/null +++ b/.maestro/utils/set-timezone.yml @@ -0,0 +1,32 @@ +appId: com.android.settings +--- +- launchApp +- runFlow: + when: + visible: 'App info' + file: goto-settings-from-app-info.yml +- tapOn: 'Search settings' +- inputText: 'Date' +- tapOn: 'Date & time' +- tapOn: 'Date & time' +- tapOn: 'Time zone' +- runFlow: + when: + notVisible: 'Select time zone' + file: disable-network-time-zone.yml + +# on some devices (maestro cloud) "Select UTC offset" is displayed instead of Region +- runFlow: + when: + visible: 'Select UTC offset' + file: select-utc-offset.yml + env: + GMT: ${GMT} + +# on most(?) devices timezone is selected by picking region +- runFlow: + when: + visible: Region + file: select-region.yml + env: + TIMEZONE: ${TIMEZONE} diff --git a/.maestro/utils/swipe-wheel-3.yml b/.maestro/utils/swipe-wheel-3.yml new file mode 100644 index 0000000..63e6f44 --- /dev/null +++ b/.maestro/utils/swipe-wheel-3.yml @@ -0,0 +1,5 @@ +appId: com.rn069 +--- +- swipe: + start: 63%, 40% + end: 63%, 35% diff --git a/.maestro/utils/swipe-wheel-am-pm.yml b/.maestro/utils/swipe-wheel-4.yml similarity index 100% rename from .maestro/utils/swipe-wheel-am-pm.yml rename to .maestro/utils/swipe-wheel-4.yml diff --git a/.maestro/utils/tap-if-visible.yml b/.maestro/utils/tap-if-visible.yml new file mode 100644 index 0000000..9981828 --- /dev/null +++ b/.maestro/utils/tap-if-visible.yml @@ -0,0 +1,8 @@ +appId: com.android.settings +--- +- runFlow: + when: + visible: ${TEXT} + file: tap.yml + env: + TEXT: ${TEXT} diff --git a/.maestro/utils/tap.yml b/.maestro/utils/tap.yml new file mode 100644 index 0000000..317223d --- /dev/null +++ b/.maestro/utils/tap.yml @@ -0,0 +1,3 @@ +appId: com.android.settings +--- +- tapOn: ${TEXT} diff --git a/.npmignore b/.npmignore index c092bc3..01a5b58 100644 --- a/.npmignore +++ b/.npmignore @@ -6,3 +6,4 @@ examples githubREADME.md .gitignore scripts +.maestro \ No newline at end of file diff --git a/examples/Rn069/e2e/tests/timezoneOffset.spec.js b/examples/Rn069/e2e/tests/timezoneOffset.spec.js deleted file mode 100644 index ba31215..0000000 --- a/examples/Rn069/e2e/tests/timezoneOffset.spec.js +++ /dev/null @@ -1,82 +0,0 @@ -const { - setTimeZoneOffsetInMinutes, - expectDate, - scrollWheel, - expectDateString, - setMaximumDate, - setDate, - init, -} = require('../utils'); - -const scrollMinuteWheel = () => scrollWheel(2, 1); - -// I haven't found a way to change the timezone on the emulator to be able to run these tests. -// Until possible, run these tests locally when needed with Europe/Stockholm timezone. -describe.skip('Timezone offset', () => { - beforeAll(async () => { - await init(); - await element(by.text('Advanced')).tap(); - }); - - it('undefined (default)', async () => { - await setTimeZoneOffsetInMinutes(undefined); - await scrollMinuteWheel(); - await expectDate('2000-01-01 00:01:00'); - await expectDateString('Sat Jan 11201 AM '); - }); - - it('0', async () => { - await setTimeZoneOffsetInMinutes(0); - await scrollMinuteWheel(); - await expectDate('2000-01-01 00:01:00'); - await expectDateString('Fri Dec 311101 PM '); - }); - - it('180', async () => { - await setTimeZoneOffsetInMinutes(180); - await scrollMinuteWheel(); - await expectDate('2000-01-01 00:01:00'); - await expectDateString('Sat Jan 1201 AM '); - }); - - it('-180', async () => { - await setTimeZoneOffsetInMinutes(-180); - await scrollMinuteWheel(); - await expectDate('2000-01-01 00:01:00'); - await expectDateString('Fri Dec 31801 PM '); - }); - - describe('daylight saving', () => { - const firstOfJuly = new Date(2000, 6, 1, 0, 0); - const firstOfJune = new Date(2000, 5, 1, 0, 0); - - beforeAll(async () => { - await setMaximumDate(firstOfJuly); - await setDate(firstOfJune); - }); - - it('undefined', async () => { - await setDate(firstOfJune); - await setTimeZoneOffsetInMinutes(undefined); - await scrollMinuteWheel(); - await expectDate('2000-06-01 00:01:00'); - await expectDateString('Thu Jun 11201 AM '); - }); - - it('0', async () => { - await setDate(firstOfJune); - await setTimeZoneOffsetInMinutes(0); - await scrollMinuteWheel(); - await expectDate('2000-06-01 00:01:00'); - await expectDateString('Wed May 311001 PM '); - }); - - it('180', async () => { - await setDate(firstOfJune); - await setTimeZoneOffsetInMinutes(180); - await scrollMinuteWheel(); - await expectDate('2000-06-01 00:01:00'); - await expectDateString('Thu Jun 1101 AM '); - }); - }); -}); diff --git a/examples/Rn069/src/App.js b/examples/Rn069/src/App.js index 127a506..46fdc67 100644 --- a/examples/Rn069/src/App.js +++ b/examples/Rn069/src/App.js @@ -18,7 +18,7 @@ export default class App extends Component { @@ -64,7 +64,7 @@ export default class App extends Component { onPress={() => this.setState({picker: undefined})} style={{margin: 10, position: 'absolute', top: 30, left: 0}} > - Back + Go back ); } diff --git a/examples/Rn069/src/CustomPropValue.js b/examples/Rn069/src/CustomPropValue.js index 25cd537..d06f07c 100644 --- a/examples/Rn069/src/CustomPropValue.js +++ b/examples/Rn069/src/CustomPropValue.js @@ -35,6 +35,15 @@ export default function CustomPropValue(props) { testID={"changeProp"} onPress={() => props.changeProp({ propName, propValue: getPropValue() })} >Change + + { + setPropName(''); + setPropValue(''); + }} + > + Clear + ) } diff --git a/examples/detox/e2e/tests/timezoneOffset.spec.js b/examples/detox/e2e/tests/timezoneOffset.spec.js deleted file mode 100644 index 469a47d..0000000 --- a/examples/detox/e2e/tests/timezoneOffset.spec.js +++ /dev/null @@ -1,81 +0,0 @@ -const { - setTimeZoneOffsetInMinutes, - expectDate, - scrollWheel, - expectDateString, - setMaximumDate, - setDate, -} = require('../utils') - -const scrollMinuteWheel = () => scrollWheel(2, 1) - -// I haven't found a way to change the timezone on the emulator to be able to run these tests. -// Until possible, run these tests locally when needed with Europe/Stockholm timezone. -describe.skip('Timezone offset', () => { - before(async () => { - await device.reloadReactNative() - await element(by.text('Advanced')).tap() - }) - - it('undefined (default)', async () => { - await setTimeZoneOffsetInMinutes(undefined) - await scrollMinuteWheel() - await expectDate('2000-01-01 00:01:00') - await expectDateString('Sat Jan 11201 AM ') - }) - - it('0', async () => { - await setTimeZoneOffsetInMinutes(0) - await scrollMinuteWheel() - await expectDate('2000-01-01 00:01:00') - await expectDateString('Fri Dec 311101 PM ') - }) - - it('180', async () => { - await setTimeZoneOffsetInMinutes(180) - await scrollMinuteWheel() - await expectDate('2000-01-01 00:01:00') - await expectDateString('Sat Jan 1201 AM ') - }) - - it('-180', async () => { - await setTimeZoneOffsetInMinutes(-180) - await scrollMinuteWheel() - await expectDate('2000-01-01 00:01:00') - await expectDateString('Fri Dec 31801 PM ') - }) - - describe('daylight saving', () => { - const firstOfJuly = new Date(2000, 6, 1, 0, 0) - const firstOfJune = new Date(2000, 5, 1, 0, 0) - - before(async () => { - await setMaximumDate(firstOfJuly) - await setDate(firstOfJune) - }) - - it('undefined', async () => { - await setDate(firstOfJune) - await setTimeZoneOffsetInMinutes(undefined) - await scrollMinuteWheel() - await expectDate('2000-06-01 00:01:00') - await expectDateString('Thu Jun 11201 AM ') - }) - - it('0', async () => { - await setDate(firstOfJune) - await setTimeZoneOffsetInMinutes(0) - await scrollMinuteWheel() - await expectDate('2000-06-01 00:01:00') - await expectDateString('Wed May 311001 PM ') - }) - - it('180', async () => { - await setDate(firstOfJune) - await setTimeZoneOffsetInMinutes(180) - await scrollMinuteWheel() - await expectDate('2000-06-01 00:01:00') - await expectDateString('Thu Jun 1101 AM ') - }) - }) -}) diff --git a/package.json b/package.json index 29ffb9b..ea25156 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,10 @@ "prepublishOnly": "mv README.md githubREADME.md && mv npmREADME.md README.md", "postpublish": "mv README.md npmREADME.md && mv githubREADME.md README.md", "test": "jest src", + "install:release": "adb install examples/Rn069/android/app/build/outputs/apk/release/app-release.apk", + "install:debug": "adb install examples/Rn069/android/app/build/outputs/apk/debug/app-debug.apk", + "build:release": "(cd examples/Rn069/android && ./gradlew assembleRelease) && yarn install:release", + "build:debug": "(cd examples/Rn069/android && ./gradlew assembleDebug) && yarn install:debug", "emulator": "bash ./scripts/start-android-emulator.sh" }, "repository": {