-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This follows the template that [we previously coded in react-native-templates](https://github.com/thoughtbot/react-native-templates/pull/1/files#diff-fc130cd2eebfc7cbeb229f509cb090c6fb5837a169b9270709cfa73ff46c9a56). * Installs React Query * Installs testing/mocking utility, MSW * Creates a mocking and testing strategy * Adds an example API call and mock and test For now, the "create" command automatically uses React Query, but we will likely decide to prompt the user if they'd like to use this or Apollo (for GraphQL) in the future. --------- Co-authored-by: Frida Casas <[email protected]> Co-authored-by: Rakesh Arunachalam <[email protected]>
- Loading branch information
1 parent
302f80e
commit 21bfc00
Showing
18 changed files
with
378 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 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,12 +1,8 @@ | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import getProjectDir from './getProjectDir'; | ||
import appendToFile from './appendToFile'; | ||
|
||
/** | ||
* lines should be separated by newlines | ||
*/ | ||
export default async function addToGitignore(lines: string) { | ||
return fs.appendFile( | ||
path.join(await getProjectDir(), '.gitignore'), | ||
`\n${lines}`, | ||
); | ||
return appendToFile('.gitignore', lines); | ||
} |
This file contains 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,12 @@ | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import getProjectDir from './getProjectDir'; | ||
/** | ||
* lines should be separated by newlines | ||
*/ | ||
export default async function appendToFile(filename: string, lines: string) { | ||
return fs.appendFile( | ||
path.join(await getProjectDir(), filename), | ||
`\n${lines}`, | ||
); | ||
} |
This file contains 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 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 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 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,10 +1,31 @@ | ||
import { screen } from '@testing-library/react-native'; | ||
|
||
import RootNavigator from 'src/navigators/RootNavigator'; | ||
import render from 'src/test/render'; | ||
import mock from 'src/test/mock'; | ||
import { renderApplication } from 'src/test/render'; | ||
|
||
test('renders', async () => { | ||
// We would not normally recommend fake timers, but the tests are currently | ||
// throwing a "not wrapped in act" warning after this test finishes. One | ||
// option is to put a `await waitForUpdates()` at the end of the test, but | ||
// fake timers also work here until we find a better solution. The stack trace | ||
// seems to point to React Navigation bottom tabs. | ||
jest.useFakeTimers(); | ||
render(<RootNavigator />); | ||
expect(await screen.findByText(/Open up App.tsx/)).toBeDefined(); | ||
|
||
const mocks = [mockCoffees()]; | ||
|
||
renderApplication({ mocks }); | ||
|
||
expect(await screen.findByRole('header', { name: 'Mocha' })).toBeDefined(); | ||
}); | ||
|
||
function mockCoffees() { | ||
return mock.get('coffee/hot', { | ||
response: [ | ||
{ | ||
id: 1, | ||
title: 'Mocha', | ||
image: 'htps://placehold.it/200x200', | ||
}, | ||
], | ||
}); | ||
} |
This file contains 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,49 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { FlatList, Image, Text, View } from 'react-native'; | ||
import api, { Coffee as CoffeeType } from 'src/util/api/api'; | ||
|
||
// TODO: sample data, remove | ||
export default function ExampleCoffees() { | ||
const { data } = useQuery({ queryKey: ['coffee'], queryFn: api.coffee }); | ||
|
||
return ( | ||
<> | ||
<Text style={{ fontWeight: '600', fontSize: 24 }}>Coffees</Text> | ||
<FlatList | ||
data={data?.slice(0, 4)} | ||
numColumns={2} | ||
scrollEnabled={false} | ||
renderItem={({ item }) => <Coffee coffee={item} />} | ||
keyExtractor={(item) => item.id.toString()} | ||
style={{ flexGrow: 0 }} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
function Coffee({ coffee }: { coffee: CoffeeType }) { | ||
const { title, image } = coffee; | ||
|
||
return ( | ||
<View | ||
style={{ | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
backgroundColor: 'salmon', | ||
borderRadius: 10, | ||
padding: 16, | ||
margin: 10, | ||
}} | ||
> | ||
<Text accessibilityRole="header" style={{ fontWeight: '600' }}> | ||
{title} | ||
</Text> | ||
<Image | ||
width={100} | ||
height={100} | ||
source={{ uri: image }} | ||
accessibilityIgnoresInvertColors | ||
/> | ||
</View> | ||
); | ||
} |
This file contains 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
Oops, something went wrong.