-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
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,57 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { userEvent, waitFor, within } from '@storybook/testing-library'; | ||
import { expect } from '@storybook/jest'; | ||
import { UseAsyncTracker } from './UseAsyncTracker'; | ||
|
||
const meta = { | ||
component: UseAsyncTracker, | ||
} satisfies Meta<typeof UseAsyncTracker>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
|
||
expect(canvas.getByTestId('global-count').textContent).toBe( | ||
'Global count: 0' | ||
); | ||
expect(canvas.getByTestId('other-count').textContent).toBe( | ||
'Other count: 0' | ||
); | ||
|
||
await userEvent.click(canvas.getByText('load other')); | ||
await waitFor(() => { | ||
expect(canvas.getByTestId('other-count').textContent).toBe( | ||
'Other count: 1' | ||
); | ||
expect(canvas.getByText('loading...')).toBeDisabled(); | ||
}); | ||
await waitFor( | ||
() => { | ||
expect(canvas.getByTestId('other-count').textContent).toBe( | ||
'Other count: 0' | ||
); | ||
}, | ||
{ timeout: 5000 } | ||
); | ||
|
||
await userEvent.click(canvas.getByText('load global')); | ||
await waitFor(() => { | ||
expect(canvas.getByTestId('global-count').textContent).toBe( | ||
'Global count: 1' | ||
); | ||
expect(canvas.getByText('loading...')).toBeDisabled(); | ||
}); | ||
await waitFor( | ||
() => { | ||
expect(canvas.getByTestId('global-count').textContent).toBe( | ||
'Global count: 0' | ||
); | ||
}, | ||
{ timeout: 5000 } | ||
); | ||
}, | ||
}; |