Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Aug 16, 2024
1 parent 5e0860d commit c28463b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
- name: Install dependencies
run: yarn install

- name: Install playwright dependencies
run: yarn exec playwright install chromium --with-deps

- name: Run tests
run: |
yarn test:ci
10 changes: 5 additions & 5 deletions src/components/RestaurantCard/RestaurantCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ const { Default, Loading, New, Closed } = composeStories(stories)

describe('RestaurantCard', () => {
test('should render correctly', async () => {
await Default.play()
await Default.run()

expect(screen.getByText('Burger Kingdom')).toBeInTheDocument()
})

test('should provide a loading skeleton', async () => {
await Loading.play()
await Loading.run()
expect(screen.getByTestId('loading')).toBeInTheDocument()
})

test('should show a "new" tag', async () => {
await New.play()
await New.run()
expect(screen.getByText('new')).toBeInTheDocument()
})

test('should not trigger onclick when restaurant is closed', async () => {
const onClickSpy = vi.fn()
await Closed.play({ args: { ...Closed.args, onClick: onClickSpy } })
await Closed.run({ args: { ...Closed.args, onClick: onClickSpy } })

// display closed message
expect(screen.getByText('This restaurant is closed.')).toBeInTheDocument()
Expand All @@ -46,7 +46,7 @@ const testCases = Object.values(composeStories(stories)).map((Story) => [

// Go through all test cases to batch test accessibility
test.each(testCases)('%s story should be accessible', async (_storyName, Story) => {
await (Story as any).play()
await (Story as any).run()
// @ts-ignore TODO fix Property 'toHaveNoViolations' does not exist on type 'Assertion<AxeResults>
expect(await axe(document.body.firstChild)).toHaveNoViolations()
})
10 changes: 5 additions & 5 deletions src/pages/RestaurantDetailPage/RestaurantDetailPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { Success, Loading, Error, NotFound, WithModalOpen } = composeStories(stor

describe('RestaurantDetailPage', () => {
test('Should add an item to cart', async () => {
await Success.play()
await Success.run()

const foodItem = await screen.findByText(/Cheeseburger/i)
userEvent.click(foodItem)
Expand All @@ -20,19 +20,19 @@ describe('RestaurantDetailPage', () => {
expect(foodQuantity.textContent).toEqual('1')
})
test('Should display an error screen', async () => {
await Error.play()
await Error.run()
await waitFor(() => expect(screen.getByText('Something went wrong!')).toBeInTheDocument())
})
test('Should display a loading screen', async () => {
await Loading.play()
await Loading.run()
await waitFor(() => expect(screen.getByText('Looking for some food...')).toBeInTheDocument())
})
test('Should display a 404 screen', async () => {
await NotFound.play()
await NotFound.run()
await waitFor(() => expect(screen.getByText("We can't find this page")).toBeInTheDocument())
})
test('Should execute story tests', async () => {
await WithModalOpen.play()
await WithModalOpen.run()
})
})

Expand Down

0 comments on commit c28463b

Please sign in to comment.