Skip to content

Commit

Permalink
chore: add detox e2e tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
yusinto committed Dec 29, 2023
1 parent 040c5d4 commit c81c900
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
25 changes: 23 additions & 2 deletions packages/sdk/react-native/example/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## LaunchDarkly React Native SDK example app
# LaunchDarkly React Native SDK example app

To run the example app:
## Quickstart

1. At the js-core repo root:

Expand Down Expand Up @@ -28,3 +28,24 @@ yarn && yarn ios-go
# android
yarn && yarn android-release
```

## Running Detox e2e tests

1. Install the required tools on OS X:

```shell
brew tap wix/brew
brew install applesimutils
```

2. On a terminal:

```shell
yarn && yarn start
```

3. On another terminal:

```shell
yarn detox-ios
```
41 changes: 28 additions & 13 deletions packages/sdk/react-native/example/e2e/starter.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
import { by, device, element, expect } from 'detox';
import { by, device, element, expect, waitFor } from 'detox';

describe('Example', () => {
beforeAll(async () => {
await device.launchApp();
await device.launchApp({
newInstance: true,
launchArgs: {
detoxURLBlacklistRegex: '\\("^https://clientstream.launchdarkly.com/meval"\\)',
},
});
});

beforeEach(async () => {
await device.reloadReactNative();
});
// For speed, all tests are sequential and dependent.
// beforeEach(async () => {
// await device.reloadReactNative();
// });

it('should have welcome screen', async () => {
await expect(element(by.id('welcome'))).toBeVisible();
test('app loads and renders correctly', async () => {
await expect(element(by.text(/welcome to launchdarkly/i))).toBeVisible();
await expect(element(by.text(/dev-test-flag: false/i))).toBeVisible();
});

it('should show hello screen after tap', async () => {
await element(by.id('hello_button')).tap();
await expect(element(by.text('Hello!!!'))).toBeVisible();
test('identify', async () => {
await element(by.id('userKey')).typeText('test-user');
await element(by.text(/identify/i)).tap();

await waitFor(element(by.text(/dev-test-flag: true/i)))
.toBeVisible()
.withTimeout(2000);
});

it('should show world screen after tap', async () => {
await element(by.id('world_button')).tap();
await expect(element(by.text('World!!!'))).toBeVisible();
test('variation', async () => {
await element(by.id('flagKey')).replaceText('test-flag-1');
await element(by.text(/get flag value/i)).tap();

await waitFor(element(by.text(/test-flag-1: true/i)))
.toBeVisible()
.withTimeout(2000);
});
});
7 changes: 5 additions & 2 deletions packages/sdk/react-native/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"start": "expo start --reset-cache",
"expo-clean": "expo prebuild --clean",
"android": "yarn link-dev && expo run:android",
"android-release": "yarn link-dev && expo run:android --variant release",
Expand All @@ -16,7 +16,10 @@
"web": "yarn link-dev && expo start --web --clear",
"clean": "expo prebuild --clean && yarn cache clean && rm -rf node_modules && rm -rf .expo",
"link-dev": "(cd .. && yarn build)",
"postinstall": "yarn link-dev"
"postinstall": "yarn link-dev",
"detox-build-ios": "detox build -c ios.sim.debug",
"detox-run-ios": "detox test -c ios.sim.debug",
"detox-ios": "yarn detox-build-ios && yarn detox-run-ios"
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.21.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/react-native/example/src/welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function Welcome() {
onChangeText={setUserKey}
onSubmitEditing={onIdentify}
value={userKey}
testID="userKey"
/>
<TouchableOpacity onPress={onIdentify} style={styles.buttonContainer}>
<Text style={styles.buttonText}>identify</Text>
Expand All @@ -37,6 +38,7 @@ export default function Welcome() {
autoCapitalize="none"
onChangeText={setFlagKey}
value={flagKey}
testID="flagKey"
/>
<TouchableOpacity style={styles.buttonContainer}>
<Text style={styles.buttonText}>get flag value</Text>
Expand Down

0 comments on commit c81c900

Please sign in to comment.