Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add detox with a simple e2e test #396

Merged
merged 20 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Try on Github action
  • Loading branch information
amaury1093 committed Apr 10, 2020
commit 05e05c4e41d461e26a5d646515c32f7af1ffed62
28 changes: 28 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,31 @@ jobs:
run: |
yarn install
yarn test
test:e2e:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- uses: expo/expo-github-action@v5
with:
expo-version: 3.x
expo-cache: true
- name: Install applesimutils
run: |
brew tap wix/brew
brew install applesimutils
- run: yarn install
- name: Download ExpoClient binary
run: ./e2e/dl_expo_bins.sh
- name: Run E2E Tests
run: |
# Start packager in background
yarn start >/dev/null &
PID=$(ps $! | tail -1 | awk '{print $1}')
# Run e2e test
yarn test:e2e
# Kill packager
kill $PID
- uses: actions/upload-artifact@master
with:
name: e2e-artifacts
path: ./artifacts
8 changes: 6 additions & 2 deletions App/Screens/ErrorScreen/ErrorScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { t } from '../../localization';
import { ErrorContext } from '../../stores';
import { track, trackScreen } from '../../util/amplitude';
import { sentryError } from '../../util/sentry';
import { testIds } from '../../util/testId';
import * as theme from '../../util/theme';
import { ErrorStackParams } from '../routeParams';

Expand Down Expand Up @@ -72,7 +73,7 @@ export function ErrorScreen(props: ErrorScreenProps): React.ReactElement {
}, [error]);

return (
<View style={styles.container}>
<View style={styles.container} testID={testIds.Error.screen}>
<Image source={errorPicture} />
<View>
<Text style={styles.errorText}>
Expand All @@ -92,7 +93,10 @@ export function ErrorScreen(props: ErrorScreenProps): React.ReactElement {
</Button>
<Text style={theme.text}>{t('error_screen_error_description')}</Text>
<ScrollView style={styles.errorScrollView}>
<TouchableOpacity onPress={(): void => setShowDetails(!showDetails)}>
<TouchableOpacity
onPress={(): void => setShowDetails(!showDetails)}
testID={testIds.Error.showDetails}
>
{showDetails ? (
<Text style={styles.errorMessage}>
{t('error_screen_error_message', {
Expand Down
3 changes: 1 addition & 2 deletions App/Screens/Loading/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { t } from '../../localization';
import { Api, ApiContext, GpsLocationContext } from '../../stores';
import { Location } from '../../stores/util/fetchGpsPosition';
import { trackScreen } from '../../util/amplitude';
import { testIds } from '../../util/testId';
import * as theme from '../../util/theme';
import { Background } from './Background';

Expand Down Expand Up @@ -59,7 +58,7 @@ function renderText(
if (api) ++coughs;

return (
<Text testID={testIds.Loading.coughText}>
<Text>
{t('loading_title_loading')}
<Text style={styles.dots}>...</Text>
{Array.from({ length: coughs }, (_, index) => index + 1).map(
Expand Down
21 changes: 19 additions & 2 deletions App/util/testId.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2020 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <https://www.gnu.org/licenses/>.

/**
* Ids used for detox
*/
export const testIds = {
Loading: {
coughText: 'Loading.coughText',
Error: {
screen: 'Error.screen',
showDetails: 'Error.showDetails',
},
};
16 changes: 16 additions & 0 deletions e2e/ambiend.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2020 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <https://www.gnu.org/licenses/>.

declare module 'detox-expo-helpers';
14 changes: 0 additions & 14 deletions e2e/first.spec.ts

This file was deleted.

18 changes: 17 additions & 1 deletion e2e/init.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2020 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <https://www.gnu.org/licenses/>.

import { cleanup, init } from 'detox';
import adapter from 'detox/runners/jest/adapter';

Expand All @@ -9,7 +25,7 @@ jest.setTimeout(120000);
jasmine.getEnv().addReporter(adapter);

beforeAll(async () => {
await init(config, { initGlobals: false });
await init(config);
});

beforeEach(async () => {
Expand Down
41 changes: 41 additions & 0 deletions e2e/locationDenied.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2020 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <https://www.gnu.org/licenses/>.

import { by, element, expect } from 'detox';
import { reloadApp } from 'detox-expo-helpers';

import { testIds } from '../App/util/testId';

describe('Location denied', () => {
it('should go to Error page if location not allowed', async () => {
await reloadApp({
permissions: { location: 'never' },
});

await expect(element(by.id(testIds.Error.screen))).toBeVisible();
});

it('should show the error details', async () => {
await reloadApp({
permissions: { location: 'never' },
});

await element(by.id(testIds.Error.showDetails)).tap();
await expect(element(by.id(testIds.Error.showDetails))).toHaveLabel(
'Error: Permission to access location was denied'
);
});
});
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ module.exports = {
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js' // https://github.com/facebook/react-native/issues/21075#issuecomment-441332894
}
},
};