Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: fix InternalCanvas story tests #20521

Merged
merged 3 commits into from
Jan 6, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 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('Button');
await expect(booleanControlNodes).toHaveLength(amount);
};

export const MultipleChildren: Story = {
Expand Down