Skip to content

Commit

Permalink
Merge pull request #20521 from storybookjs/norbert/fix-next
Browse files Browse the repository at this point in the history
Build: fix InternalCanvas story tests
  • Loading branch information
ndelangen authored Jan 6, 2023
2 parents 131f72f + 55a1607 commit af847ba
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions code/ui/blocks/src/blocks/internal/InternalCanvas.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference types="@testing-library/jest-dom" />;
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { userEvent, waitFor, within } from '@storybook/testing-library';
import { userEvent, within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { Canvas } from '../Canvas';
import { Story as StoryComponent } from '../Story';
Expand All @@ -12,6 +12,7 @@ const meta: Meta<typeof Canvas> = {
title: 'Blocks/Internal/Canvas',
component: Canvas,
parameters: {
theme: 'light',
relativeCsfPaths: ['../examples/Button.stories'],
},
render: (args) => {
Expand All @@ -32,20 +33,15 @@ const expectAmountOfStoriesInSource =
const canvas = within(canvasElement);

// Arrange - find the "Show code" button
let showCodeButton = canvas.getByText('Show code');
await waitFor(() => {
showCodeButton = canvas.getByText('Show code');
expect(showCodeButton).toBeInTheDocument();
});
const showCodeButton = await canvas.findByText('Show code');
await expect(showCodeButton).toBeInTheDocument();

// Act - click button to show code
await userEvent.click(showCodeButton);

// Assert - check that the correct amount of stories' source is shown
await waitFor(async () => {
const booleanControlNodes = await canvas.findAllByText('BooleanControl');
expect(booleanControlNodes).toHaveLength(amount);
});
const booleanControlNodes = await canvas.findAllByText('onClick');
await expect(booleanControlNodes).toHaveLength(amount);
};

export const MultipleChildren: Story = {
Expand Down Expand Up @@ -115,6 +111,6 @@ export const MixedChildrenStories: Story = {
const canvas = within(args.canvasElement);

// Assert - only find two headlines, those in the story, and none in the source code
expect(canvas.queryAllByText(/Headline for Boolean Controls/i)).toHaveLength(2);
expect(canvas.queryAllByText(/Headline for /i)).toHaveLength(2);
},
};

0 comments on commit af847ba

Please sign in to comment.