Skip to content

Commit

Permalink
Fix onboarding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wyne committed Aug 4, 2024
1 parent 5a70a3f commit 9df2c4e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
6 changes: 5 additions & 1 deletion __mocks__/expo-application.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const nativeApplicationVersion = '1.0.0';
const Application = {
nativeApplicationVersion: '1.0.0',
};

export { Application };
38 changes: 30 additions & 8 deletions src/Navigation.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';

import { configureStore } from '@reduxjs/toolkit';
import { render, screen } from '@testing-library/react-native';
import { render, screen, waitFor } from '@testing-library/react-native';

Check failure on line 4 in src/Navigation.test.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'screen' is defined but never used
import { Provider } from 'react-redux';

import gamesReducer, { gameDefaults } from '../redux/GamesSlice';
import settingsReducer, { setOnboardedVersion, initialState as settingsState } from '../redux/SettingsSlice';

Check failure on line 8 in src/Navigation.test.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'setOnboardedVersion' is defined but never used

import { Navigation } from './Navigation';

Check failure on line 10 in src/Navigation.test.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

There should be at least one empty line between import groups

Check failure on line 10 in src/Navigation.test.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'Navigation' is defined but never used
import { useNavigationMock } from '../test/test-helpers';

Check failure on line 11 in src/Navigation.test.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

There should be at least one empty line between import groups

Check failure on line 11 in src/Navigation.test.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

`../test/test-helpers` import should occur before import of `./Navigation`
import ListScreen from './screens/ListScreen';

jest.mock('Analytics');

Expand Down Expand Up @@ -39,28 +41,48 @@ const mockStore = () => {
};

describe('Navigation', () => {
it('does not show the onboarding screen when onboardedSemVer 1.0.0', () => {
it('show the onboarding screen when onboardedSemVer 1.0.0', async () => {
const navigation = useNavigationMock();
const { Application } = require('expo-application');
expect(Application.nativeApplicationVersion).toBe('1.0.0');

const store = mockStore();

render(
<Provider store={store}>
<Navigation />
<ListScreen navigation={navigation} />
</Provider>
);

expect(screen.queryByTestId('onboarding')).toBeOnTheScreen();
await waitFor(() => {
expect(navigation.navigate).toHaveBeenCalledWith('Onboarding', expect.objectContaining({
onboarding: true,
}));
});
});

it('does not show the onboarding screen when onboardedSemVer is equal or greater than 2.2.2', () => {
it('does not show the onboarding screen when onboardedSemVer is equal or greater than 2.2.2', async () => {
const navigation = useNavigationMock();

jest.doMock('expo-application', () => ({
Application: {
nativeApplicationVersion: '2.5.7',
},
}));

const { Application } = require('expo-application');
expect(Application.nativeApplicationVersion).toBe('2.5.7');

const store = mockStore();

store.dispatch(setOnboardedVersion());
render(
<Provider store={store}>
<Navigation />
<ListScreen navigation={navigation} />
</Provider>
);

expect(screen.queryByTestId('onboarding')).not.toBeOnTheScreen();
await waitFor(() => {
expect(navigation.navigate).not.toHaveBeenCalledWith('Onboarding');
});
});
});
1 change: 0 additions & 1 deletion src/screens/ListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const ListScreen: React.FunctionComponent<Props> = ({ navigation }) => {
setRollingGameCounter(gameIds.length);
}


logEvent('game_list', {
onboarded,
gameCount: gameIds.length,
Expand Down

0 comments on commit 9df2c4e

Please sign in to comment.