Skip to content

Commit 7d02596

Browse files
authored
e2e: consistent tests across platforms (#690)
## 📜 Description Made e2e tests better 🙂 ## 💡 Motivation and Context The main motivation to do that was to have `device.tap()` method - it would allow us to test switch to emoji keyboard. I added this, but then realized, that flag `SOFT_CHECK` doesn't satisfy for previous goals, so I decided to create `devicePreferences` mechanism. Then I tried to enable `OverKeyboardView` tests and suddenly they started to work 😲 Last piece was updating `KeyboardToolbar` tests 🙂 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### E2E - enable emoji keyboard tests on iOS; - enable `OverKeyboardView` tests on iOS; - update detox to latest version; - fix `KeyboardToolbar` incompatibility with new Detox version; - add `getDevicePreference` method; - generate missing assets; ## 🤔 How Has This Been Tested? Tested on CI. ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent c334a33 commit 7d02596

38 files changed

+114
-52
lines changed

docs/docs/api/over-keyboard-view/index.mdx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,3 @@ const styles = StyleSheet.create({
120120
},
121121
});
122122
```
123-
124-
## Limitations
125-
126-
- at the moment it's not possible to write e2e tests using [Detox](https://github.com/wix/Detox) on **iOS** (Android tests are working fine) because clicks are not propagated to the `OverKeyboardView` component (I'm actively working to fix that).

docs/versioned_docs/version-1.14.0/api/over-keyboard-view/index.mdx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,3 @@ const styles = StyleSheet.create({
120120
},
121121
});
122122
```
123-
124-
## Limitations
125-
126-
- at the moment it's not possible to write e2e tests using [Detox](https://github.com/wix/Detox) on **iOS** (Android tests are working fine) because clicks are not propagated to the `OverKeyboardView` component (I'm actively working to fix that).

e2e/kit/001-keyboard-animation.e2e.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expectBitmapsToBeEqual } from "./asserts";
22
import {
3-
Env,
43
closeKeyboard,
54
switchToEmojiKeyboard,
65
waitAndTap,
@@ -22,21 +21,19 @@ describe("Simple keyboard animation", () => {
2221
});
2322

2423
it("should have expected state when emoji keyboard is opened", async () => {
25-
// this is available only on Android 12 right now:
26-
// - Android 9 AOSP image can not switch to emoji
27-
// - on iOS we are waiting for new API: https://github.com/wix/Detox/issues/4331
28-
if (Env.softCheck) {
29-
await switchToEmojiKeyboard();
30-
await waitForExpect(async () => {
31-
await expectBitmapsToBeEqual("KeyboardAnimationEmojiKeyboard");
32-
});
33-
}
24+
await switchToEmojiKeyboard();
25+
await waitForExpect(async () => {
26+
await expectBitmapsToBeEqual("KeyboardAnimationEmojiKeyboard");
27+
});
3428
});
3529

3630
it("should have expected state when keyboard is closed", async () => {
31+
// only on iOS 15 we get busy loop...
32+
await device.disableSynchronization();
3733
await closeKeyboard("keyboard_animation_text_input");
3834
await waitForExpect(async () => {
3935
await expectBitmapsToBeEqual("KeyboardAnimationKeyboardIsHidden");
4036
});
37+
await device.enableSynchronization();
4138
});
4239
});

e2e/kit/005-keyboard-toolbar.e2e.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import {
88
doActionNTimes,
99
scrollDownUntilElementIsVisible,
10+
tap,
1011
waitAndTap,
1112
waitForElementById,
1213
waitForExpect,
@@ -28,14 +29,14 @@ describe("`KeyboardToolbar` specification", () => {
2829
});
2930

3031
it("should show bottom sheet when `AutoFill Contacts` is pressed", async () => {
31-
await waitAndTap("autofill_contacts");
32+
await tap("autofill_contacts");
3233
await waitForElementById("autofill_contacts_close");
3334
});
3435

3536
it("should set focus back when modal closed", async () => {
3637
await waitAndTap("autofill_contacts_close");
3738
await expect(element(by.id("TextInput#1"))).toBeFocused();
38-
await waitAndTap("autofill_contacts");
39+
await tap("autofill_contacts");
3940
});
4041

4142
it("should do correct actions when contact gets selected", async () => {
@@ -56,22 +57,22 @@ describe("`KeyboardToolbar` specification", () => {
5657
});
5758

5859
it("should skip a disabled fields", async () => {
59-
await waitAndTap("keyboard.toolbar.next");
60+
await tap("keyboard.toolbar.next");
6061
await expect(element(by.id("TextInput#5"))).toBeFocused();
6162
});
6263

6364
it("should handle multiple clicks in row", async () => {
64-
await doActionNTimes(() => waitAndTap("keyboard.toolbar.next"), 3);
65+
await doActionNTimes(() => tap("keyboard.toolbar.next"), 3);
6566
await expect(element(by.id("TextInput#8"))).toBeFocused();
6667
});
6768

6869
it("should handle `previous` clicks correctly", async () => {
69-
await waitAndTap("keyboard.toolbar.previous");
70+
await tap("keyboard.toolbar.previous");
7071
await expect(element(by.id("TextInput#7"))).toBeFocused();
7172
});
7273

7374
it("should have expected UI state when end of form reached", async () => {
74-
await doActionNTimes(() => waitAndTap("keyboard.toolbar.next"), 6);
75+
await doActionNTimes(() => tap("keyboard.toolbar.next"), 6);
7576
await expect(element(by.id("TextInput#13"))).toBeFocused();
7677
await expectElementBitmapsToBeEqual(
7778
"keyboard.toolbar",
@@ -80,7 +81,7 @@ describe("`KeyboardToolbar` specification", () => {
8081
});
8182

8283
it("should enable next button when go to previous field from the last one", async () => {
83-
await waitAndTap("keyboard.toolbar.previous");
84+
await tap("keyboard.toolbar.previous");
8485
await expect(element(by.id("TextInput#12"))).toBeFocused();
8586
await expectElementBitmapsToBeEqual(
8687
"keyboard.toolbar",
@@ -89,7 +90,7 @@ describe("`KeyboardToolbar` specification", () => {
8990
});
9091

9192
it("should close keyboard when press `Done`", async () => {
92-
await waitAndTap("keyboard.toolbar.done");
93+
await tap("keyboard.toolbar.done");
9394
await waitForExpect(async () => {
9495
await expectBitmapsToBeEqual("ToolbarKeyboardClosed");
9596
});

e2e/kit/009-native-stack.e2e.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expectBitmapsToBeEqual } from "./asserts";
22
import {
3-
Env,
43
closeKeyboard,
54
scrollDownUntilElementIsVisible,
65
switchToEmojiKeyboard,
@@ -24,21 +23,19 @@ describe("Native stack", () => {
2423
});
2524

2625
it("should have expected state when emoji keyboard is opened", async () => {
27-
// this is available only on Android 12 right now:
28-
// - Android 9 AOSP image can not switch to emoji
29-
// - on iOS we are waiting for new API: https://github.com/wix/Detox/issues/4331
30-
if (Env.softCheck) {
31-
await switchToEmojiKeyboard();
32-
await waitForExpect(async () => {
33-
await expectBitmapsToBeEqual("NativeStackEmojiKeyboard");
34-
});
35-
}
26+
await switchToEmojiKeyboard();
27+
await waitForExpect(async () => {
28+
await expectBitmapsToBeEqual("NativeStackEmojiKeyboard");
29+
});
3630
});
3731

3832
it("should have expected state when keyboard is closed", async () => {
33+
// only on iOS 15 we get busy loop...
34+
await device.disableSynchronization();
3935
await closeKeyboard("keyboard_animation_text_input");
4036
await waitForExpect(async () => {
4137
await expectBitmapsToBeEqual("NativeStackKeyboardIsHidden");
4238
});
39+
await device.enableSynchronization();
4340
});
4441
});

e2e/kit/011-over-keyboard-view.e2e.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import {
66
waitForExpect,
77
} from "./helpers";
88

9-
const test = device.getPlatform() === "ios" ? describe.skip : describe;
10-
11-
test("`OverKeyboardView` specification", () => {
9+
describe("`OverKeyboardView` specification", () => {
1210
it("should navigate to `OverKeyboardView` screen", async () => {
1311
await scrollDownUntilElementIsVisible(
1412
"main_scroll_view",
@@ -20,7 +18,8 @@ test("`OverKeyboardView` specification", () => {
2018
it("should have expected state when view is not visible", async () => {
2119
await waitForElementById("over_keyboard_view.input");
2220
await waitForExpect(async () => {
23-
await expectBitmapsToBeEqual("OverKeyboardViewNotShown");
21+
// iOS home indicator may have different color
22+
await expectBitmapsToBeEqual("OverKeyboardViewNotShown", 0.28);
2423
});
2524
});
2625

e2e/kit/asserts/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import pixelmatch from "pixelmatch";
66
import { PNG } from "pngjs";
77

88
import { delay } from "../helpers";
9+
import parseDeviceName from "../utils/parseDeviceName";
910

10-
const parseDeviceName = (name: string) =>
11-
name.split("(").pop()?.replace(")", "");
1211
const getDirFromFilePath = (path: string) =>
1312
path.substring(0, path.lastIndexOf("/"));
1413

Loading
Loading
Loading

0 commit comments

Comments
 (0)