-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add story unit tests with compose story (#551)
- Loading branch information
Showing
36 changed files
with
9,065 additions
and
8,418 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Checks | ||
|
||
on: | ||
push: | ||
branches: | ||
- next | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
build: | ||
name: Check everything! | ||
strategy: | ||
fail-fast: false | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set node version | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- name: install and compile | ||
run: yarn | ||
- name: build | ||
run: yarn build | ||
- name: lint | ||
run: yarn lint | ||
- name: test | ||
run: yarn test |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
yarnPath: .yarn/releases/yarn-3.6.1.cjs | ||
nodeLinker: node-modules | ||
compressionLevel: mixed | ||
|
||
enableGlobalCache: false | ||
|
||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-4.1.0.cjs |
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,15 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
|
||
import App from './App'; | ||
|
||
describe('<App />', () => { | ||
it('has 1 child', () => { | ||
const tree = renderer.create(<App />).toJSON(); | ||
if (!Array.isArray(tree) && tree.children) { | ||
expect(tree.children.length).toBe(1); | ||
} else { | ||
throw new Error('App has no children'); | ||
} | ||
}); | ||
}); |
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
21 changes: 21 additions & 0 deletions
21
examples/expo-example/components/ActionExample/Actions.test.tsx
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,21 @@ | ||
import { render, screen, userEvent } from '@testing-library/react-native'; | ||
import { composeStory } from '@storybook/react'; | ||
import Meta, { Basic } from './Actions.stories'; | ||
|
||
const ActionsStory = composeStory(Basic, Meta); | ||
|
||
test('action story renders and onpress works', async () => { | ||
jest.useFakeTimers(); | ||
|
||
const onPress = jest.fn(); | ||
|
||
render(<ActionsStory onPress={onPress} />); | ||
|
||
const user = userEvent.setup({}); | ||
|
||
const actionButton = screen.getByText('Press me!'); | ||
|
||
await user.press(actionButton); | ||
|
||
expect(onPress).toHaveBeenCalled(); | ||
}); |
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
14 changes: 14 additions & 0 deletions
14
examples/expo-example/components/BackgroundExample/BackgroundCsf.test.tsx
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,14 @@ | ||
import '@testing-library/react-native/extend-expect'; | ||
import { render, screen } from '@testing-library/react-native'; | ||
import { composeStory } from '@storybook/react'; | ||
import Meta, { Basic } from './BackgroundCsf.stories'; | ||
|
||
const BackgroundCsfStory = composeStory(Basic, Meta); | ||
|
||
test('Background colour is hotpink', () => { | ||
render(<BackgroundCsfStory />); | ||
|
||
expect(screen.getByTestId('addon-backgrounds-container')).toHaveStyle({ | ||
backgroundColor: 'hotpink', | ||
}); | ||
}); |
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
11 changes: 11 additions & 0 deletions
11
examples/expo-example/components/ControlExamples/Array/Array.test.tsx
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,11 @@ | ||
import { render, screen } from '@testing-library/react-native'; | ||
import { composeStory } from '@storybook/react'; | ||
import Meta, { Basic } from './Array.stories'; | ||
|
||
const ArrayStory = composeStory(Basic, Meta); | ||
|
||
test('array story renders', () => { | ||
render(<ArrayStory />); | ||
|
||
expect(screen.getByTestId('array-story-container')).toHaveTextContent(/abc/); | ||
}); |
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
18 changes: 18 additions & 0 deletions
18
examples/expo-example/components/ControlExamples/Boolean/Boolean.test.tsx
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,18 @@ | ||
import { render, screen } from '@testing-library/react-native'; | ||
import { composeStory } from '@storybook/react'; | ||
import Meta, { Basic, On } from './Boolean.stories'; | ||
|
||
const BooleanStory = composeStory(Basic, Meta); | ||
const OnStory = composeStory(On, Meta); | ||
|
||
test('boolean story renders', () => { | ||
render(<BooleanStory />); | ||
|
||
screen.getByText('off'); | ||
}); | ||
|
||
test('boolean story renders on', () => { | ||
render(<OnStory />); | ||
|
||
screen.getByText('on'); | ||
}); |
11 changes: 11 additions & 0 deletions
11
examples/expo-example/components/ControlExamples/Color/Color.test.tsx
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,11 @@ | ||
import { render, screen } from '@testing-library/react-native'; | ||
import { composeStory } from '@storybook/react'; | ||
import Meta, { ColorExample } from './Color.stories'; | ||
|
||
const ColorStory = composeStory(ColorExample, Meta); | ||
|
||
test('color story renders', () => { | ||
render(<ColorStory />); | ||
|
||
expect(screen.getByTestId('color-story-container')).toHaveStyle({ backgroundColor: '#a819b9' }); | ||
}); |
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
13 changes: 13 additions & 0 deletions
13
examples/expo-example/components/ControlExamples/Date/Date.test.tsx
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,13 @@ | ||
import { render, screen } from '@testing-library/react-native'; | ||
import { composeStory } from '@storybook/react'; | ||
import Meta, { Basic } from './Date.stories'; | ||
|
||
const DateStory = composeStory(Basic, Meta); | ||
|
||
test('date story renders', () => { | ||
render(<DateStory />); | ||
|
||
const date = new Date(1983, 1, 25); | ||
|
||
screen.getByText(date.toString()); | ||
}); |
18 changes: 18 additions & 0 deletions
18
examples/expo-example/components/ControlExamples/Number/Number.test.tsx
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,18 @@ | ||
import { render, screen } from '@testing-library/react-native'; | ||
import { composeStory } from '@storybook/react'; | ||
import Meta, { Basic, Range } from './Number.stories'; | ||
|
||
const BasicStory = composeStory(Basic, Meta); | ||
const RangeStory = composeStory(Range, Meta); | ||
|
||
test('basic story renders', async () => { | ||
render(<BasicStory />); | ||
|
||
await screen.findByText(/5 x 3 = 15/); | ||
}); | ||
|
||
test('range story renders', async () => { | ||
render(<RangeStory />); | ||
|
||
await screen.findByText(/6 x 7 = 42/); | ||
}); |
13 changes: 13 additions & 0 deletions
13
examples/expo-example/components/ControlExamples/Object/Object.test.tsx
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,13 @@ | ||
import { render, screen } from '@testing-library/react-native'; | ||
import { composeStory } from '@storybook/react'; | ||
import Meta, { Basic } from './Object.stories'; | ||
|
||
const ObjectStory = composeStory(Basic, Meta); | ||
|
||
test('object story renders', () => { | ||
render(<ObjectStory />); | ||
|
||
screen.getByText('title: Blade Runner'); | ||
screen.getByText('genre: Sci Fi'); | ||
screen.getByText('release year: 1982'); | ||
}); |
11 changes: 11 additions & 0 deletions
11
examples/expo-example/components/ControlExamples/Radio/Radio.test.tsx
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,11 @@ | ||
import { render, screen } from '@testing-library/react-native'; | ||
import { composeStory } from '@storybook/react'; | ||
import Meta, { Basic } from './Radio.stories'; | ||
|
||
const RadioStory = composeStory(Basic, Meta); | ||
|
||
test('radio story renders', () => { | ||
render(<RadioStory />); | ||
|
||
screen.getByText('104.8MHz'); | ||
}); |
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.