Skip to content

Commit

Permalink
Navigation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wyne committed Sep 2, 2023
1 parent 653f28f commit 4a19939
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 11 deletions.
4 changes: 0 additions & 4 deletions __mocks__/@react-navigation/native-stack.ts

This file was deleted.

8 changes: 6 additions & 2 deletions jest.config.js → jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
import type { Config } from 'jest';

const config: Config = {
preset: 'jest-expo',
transform: {
'^.+\\.tsx?$': 'babel-jest',
Expand All @@ -9,6 +11,8 @@ module.exports = {
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
setupFilesAfterEnv: [
"@testing-library/jest-native/extend-expect"
"@testing-library/jest-native/extend-expect",
]
};

export default config;
128 changes: 127 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"jest": "^29.5.0",
"prettier": "^3.0.1",
"react-test-renderer": "^18.2.0",
"redux-mock-store": "^1.5.4"
"redux-mock-store": "^1.5.4",
"ts-node": "^10.9.1"
},
"overrides": {},
"homepage": "/scorepad-app",
Expand Down
29 changes: 29 additions & 0 deletions src/Navigation.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { render, screen } from '@testing-library/react-native';
import { Navigation } from './Navigation';
import { Provider } from 'react-redux';
import { store } from '../redux/store';
import { setOnboardedVersion } from '../redux/SettingsSlice';

describe('Navigation', () => {
it('does not show the onboarding screen when onboardedSemVer 1.0.0', () => {
render(
<Provider store={store}>
<Navigation />
</Provider>
);

expect(screen.queryByTestId('onboarding')).toBeOnTheScreen();
});

it('does not show the onboarding screen when onboardedSemVer is equal or greater than 2.2.2', () => {
store.dispatch(setOnboardedVersion());
render(
<Provider store={store}>
<Navigation />
</Provider>
);

expect(screen.queryByTestId('onboarding')).not.toBeOnTheScreen();
});
});
2 changes: 1 addition & 1 deletion src/screens/OnboardingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const OnboardingScreen: React.FunctionComponent<Props> = ({ navigation, route })
}, [activeIndex]);

return (
<Animated.View style={[styles.container]} entering={FadeIn}>
<Animated.View style={[styles.container]} entering={FadeIn} testID={'onboarding'}>
<SafeAreaView edges={(['top', 'bottom'])} style={onboarding ? { paddingTop: 40 } : {}}>
<View style={[StyleSheet.absoluteFillObject]}>
{data.map((item, index) => {
Expand Down
8 changes: 6 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"strict": true,
"jsx": "react-native"
"jsx": "react-native",
"types": [
"@testing-library/jest-native",
"jest",
],
},
"extends": "expo/tsconfig.base",
"include": [
Expand All @@ -10,4 +14,4 @@
"./src/**/*.js",
"./redux/**/*.ts",
],
}
}

0 comments on commit 4a19939

Please sign in to comment.