-
Notifications
You must be signed in to change notification settings - Fork 276
refactor: update example apps #1024
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cec8875
chore: update Redux example deps
mdjastrzebski 31d4e2a
chore: update React Navigation deps
mdjastrzebski b8f564b
refactor: apply screen, cleanup
mdjastrzebski c16da2a
chore: update deps, update AppNavigator tests
mdjastrzebski 35f660f
refactor: remove drawer example as it does not add to overall example
mdjastrzebski edec516
refactor: tweaks
mdjastrzebski 08e29f6
refactor: extract custom renders to test-utils
mdjastrzebski 0000f10
refactor: tweaks
mdjastrzebski f6fa655
chore: remove commented setting
mdjastrzebski ea1c6e2
Update examples/redux/components/AddTodo.test.js
mdjastrzebski 44b3ca1
Update examples/redux/jest.config.js
mdjastrzebski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,2 @@ | ||
import 'react-native-gesture-handler/jestSetup'; | ||
|
||
jest.mock('react-native-reanimated', () => { | ||
const Reanimated = require('react-native-reanimated/mock'); | ||
|
||
// The mock for `call` immediately calls the callback which is incorrect | ||
// So we override it with a no-op | ||
Reanimated.default.call = () => {}; | ||
|
||
return Reanimated; | ||
}); | ||
|
||
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing | ||
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
module.exports = { | ||
preset: 'react-native', | ||
setupFiles: ['./jest-setup.js'], | ||
// setupFiles: ['./node_modules/react-native-gesture-handler/jestSetup.js'], | ||
setupFilesAfterEnv: ['./jest-setup.js'], | ||
transformIgnorePatterns: [ | ||
'node_modules/(?!(jest-)?react-native|@react-native-community|@react-navigation)', | ||
'node_modules/(?!(jest-)?react-native|@react-native|@react-native-community|@react-navigation)', | ||
], | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import * as React from 'react'; | ||
import { createStackNavigator } from '@react-navigation/stack'; | ||
|
||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
import HomeScreen from './screens/HomeScreen'; | ||
import DetailsScreen from './screens/DetailsScreen'; | ||
|
||
const { Screen, Navigator } = createStackNavigator(); | ||
const Stack = createNativeStackNavigator(); | ||
|
||
export default function Navigation() { | ||
const options = {}; | ||
|
||
return ( | ||
<Navigator> | ||
<Screen name="Home" component={HomeScreen} /> | ||
<Screen options={options} name="Details" component={DetailsScreen} /> | ||
</Navigator> | ||
<Stack.Navigator> | ||
<Stack.Screen name="Home" component={HomeScreen} /> | ||
<Stack.Screen name="Details" component={DetailsScreen} /> | ||
</Stack.Navigator> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from 'react'; | ||
import { screen, fireEvent } from '@testing-library/react-native'; | ||
import { renderWithNavigation } from './test-utils'; | ||
import AppNavigator from './AppNavigator'; | ||
|
||
test('page contains the header and 10 items', async () => { | ||
renderWithNavigation(<AppNavigator />); | ||
|
||
const header = await screen.findByText('List of numbers from 1 to 20'); | ||
expect(header).toBeTruthy(); | ||
|
||
const items = screen.getAllByText(/Item number/); | ||
expect(items.length).toBe(10); | ||
}); | ||
|
||
test('clicking on one item takes you to the details screen', async () => { | ||
renderWithNavigation(<AppNavigator />); | ||
|
||
const toClick = await screen.findByText('Item number 5'); | ||
fireEvent(toClick, 'press'); | ||
|
||
expect(screen.getByText('Showing details for 5')).toBeTruthy(); | ||
expect(screen.getByText('the number you have chosen is 5')).toBeTruthy(); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
examples/reactnavigation/src/__tests__/AppNavigator.test.js
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
examples/reactnavigation/src/__tests__/DrawerAppNavigator.test.js
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import * as React from 'react'; | ||
import { NavigationContainer } from '@react-navigation/native'; | ||
import { render } from '@testing-library/react-native'; | ||
|
||
/** Render helper that renders `ui` within `NavigationContainer`. */ | ||
export function renderWithNavigation(ui) { | ||
return render(<NavigationContainer>{ui}</NavigationContainer>); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,27 @@ | ||
import * as React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { fireEvent, render } from '@testing-library/react-native'; | ||
import configureStore from '../store'; | ||
import { screen, fireEvent } from '@testing-library/react-native'; | ||
import { renderWithRedux } from '../test-utils'; | ||
import AddTodo from './AddTodo'; | ||
|
||
describe('Application test', () => { | ||
test('adds a new test when entry has been included', () => { | ||
const store = configureStore(); | ||
|
||
const component = ( | ||
<Provider store={store}> | ||
<AddTodo /> | ||
</Provider> | ||
); | ||
|
||
const { getByPlaceholderText, getByText } = render(component); | ||
|
||
const input = getByPlaceholderText(/repository/i); | ||
expect(input).toBeTruthy(); | ||
|
||
const textToEnter = 'This is a random element'; | ||
fireEvent.changeText(input, textToEnter); | ||
fireEvent.press(getByText('Submit form')); | ||
|
||
const todosState = store.getState().todos; | ||
|
||
expect(todosState.length).toEqual(1); | ||
|
||
expect(todosState).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
id: 1, | ||
text: textToEnter, | ||
date: expect.any(Date), | ||
}), | ||
]) | ||
); | ||
}); | ||
test('adds a new test when entry has been included', () => { | ||
mdjastrzebski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { store } = renderWithRedux(<AddTodo />); | ||
|
||
const input = screen.getByPlaceholderText(/repository/i); | ||
expect(input).toBeTruthy(); | ||
|
||
const textToEnter = 'This is a random element'; | ||
fireEvent.changeText(input, textToEnter); | ||
fireEvent.press(screen.getByText('Submit form')); | ||
|
||
const todosState = store.getState().todos; | ||
expect(todosState).toHaveLength(1); | ||
expect(todosState).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
id: 1, | ||
text: textToEnter, | ||
date: expect.any(Date), | ||
}), | ||
]) | ||
); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.