Page.stories.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import type { Meta, StoryObj } from '@storybook/react';
  2. import { within, userEvent, expect } from '@storybook/test';
  3. import { Page } from './Page';
  4. const meta = {
  5. title: 'Example/Page',
  6. component: Page,
  7. parameters: {
  8. // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
  9. layout: 'fullscreen',
  10. },
  11. } satisfies Meta<typeof Page>;
  12. export default meta;
  13. type Story = StoryObj<typeof meta>;
  14. export const LoggedOut: Story = {};
  15. // More on interaction testing: https://storybook.js.org/docs/writing-tests/interaction-testing
  16. export const LoggedIn: Story = {
  17. play: async ({ canvasElement }) => {
  18. const canvas = within(canvasElement);
  19. const loginButton = canvas.getByRole('button', { name: /Log in/i });
  20. await expect(loginButton).toBeInTheDocument();
  21. await userEvent.click(loginButton);
  22. await expect(loginButton).not.toBeInTheDocument();
  23. const logoutButton = canvas.getByRole('button', { name: /Log out/i });
  24. await expect(logoutButton).toBeInTheDocument();
  25. },
  26. };