Skip to content

Commit

Permalink
test: add story
Browse files Browse the repository at this point in the history
  • Loading branch information
zenoplex committed Jun 10, 2023
1 parent 5816f57 commit eaed9ad
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions apps/workshop/src/stories/UseAsyncTracker.stories.ts
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 }
);
},
};

0 comments on commit eaed9ad

Please sign in to comment.