Skip to content

Commit

Permalink
Merge branch 'norbert/fast-build-toggles' of github.com:storybookjs/s…
Browse files Browse the repository at this point in the history
…torybook into norbert/fast-build-toggles
  • Loading branch information
ndelangen committed Nov 1, 2023
2 parents bbcf2bc + dd598b4 commit fc00057
Show file tree
Hide file tree
Showing 23 changed files with 136 additions and 77 deletions.
4 changes: 2 additions & 2 deletions code/e2e-tests/addon-interactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ test.describe('addon-interactions', () => {
await expect(welcome).toContainText('Welcome, Jane Doe!');

const interactionsTab = await page.locator('#tabbutton-storybook-interactions-panel');
await expect(interactionsTab).toContainText(/(1)/);
await expect(interactionsTab).toContainText(/(\d)/);
await expect(interactionsTab).toBeVisible();

const panel = sbPage.panelContent();
await expect(panel).toContainText(/Pass/);
await expect(panel).toContainText(/userEvent.click/);
await expect(panel).toBeVisible();

const done = await panel.locator('[data-testid=icon-done]');
const done = await panel.locator('[data-testid=icon-done]').nth(0);
await expect(done).toBeVisible();
});

Expand Down
11 changes: 7 additions & 4 deletions code/frameworks/angular/template/cli/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/angular';
import { moduleMetadata } from '@storybook/angular';
import { within, userEvent } from '@storybook/testing-library';
import { CommonModule } from '@angular/common';
import { within, userEvent, expect } from '@storybook/test';

import Button from './button.component';
import Header from './header.component';
Expand Down Expand Up @@ -38,9 +38,12 @@ export const LoggedIn: Story = {
}),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/frameworks/nextjs/template/cli/js/Page.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';
import { Page } from './Page';

export default {
Expand All @@ -16,9 +16,12 @@ export const LoggedOut = {};
export const LoggedIn = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/frameworks/nextjs/template/cli/ts-3-8/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';

import { Page } from './Page';

Expand All @@ -21,9 +21,12 @@ export const LoggedOut: Story = {};
export const LoggedIn: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/frameworks/nextjs/template/cli/ts-4-9/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';

import { Page } from './Page';

Expand All @@ -21,9 +21,12 @@ export const LoggedOut: Story = {};
export const LoggedIn: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion code/lib/cli/src/generators/baseGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,14 @@ export async function baseGenerator(

if (hasInteractiveStories(rendererId)) {
addons.push('@storybook/addon-interactions');
addonPackages.push('@storybook/addon-interactions', '@storybook/testing-library@^0.2.0-next.0');
addonPackages.push('@storybook/addon-interactions');

// TODO: migrate template stories in solid and qwik to use @storybook/test
if (['solid', 'qwik'].includes(rendererId)) {
addonPackages.push('@storybook/testing-library');
} else {
addonPackages.push('@storybook/test');
}
}

const files = await fse.readdir(process.cwd());
Expand Down
8 changes: 4 additions & 4 deletions code/lib/test/src/expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import {
setState,
} from '@vitest/expect';
import * as matchers from '@testing-library/jest-dom/matchers';
import type { TestingLibraryMatchers } from '@testing-library/jest-dom/types/matchers';
import type { PromisifyObject } from './utils';

type Matchers<T> = PromisifyObject<JestAssertion<T>> &
matchers.TestingLibraryMatchers<ReturnType<ExpectStatic['stringContaining']>, Promise<void>>;

// We only expose the jest compatible API for now
export interface Assertion<T>
extends PromisifyObject<JestAssertion<T>>,
TestingLibraryMatchers<ReturnType<ExpectStatic['stringContaining']>, Promise<void>> {
export interface Assertion<T> extends Matchers<T> {
toHaveBeenCalledOnce(): Promise<void>;
toSatisfy<E>(matcher: (value: E) => boolean, message?: string): Promise<void>;
resolves: Assertion<T>;
Expand Down
1 change: 1 addition & 0 deletions code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
],
"resolutions": {
"@playwright/test": "1.36.0",
"@testing-library/jest-dom/aria-query": "5.1.3",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/experimental-utils": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
Expand Down
11 changes: 7 additions & 4 deletions code/renderers/html/template/cli/js/Page.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';
import { createPage } from './Page';

export default {
Expand All @@ -16,9 +16,12 @@ export const LoggedOut = {};
export const LoggedIn = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/renderers/html/template/cli/ts-3-8/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/html';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';
import { createPage } from './Page';

const meta: Meta = {
Expand All @@ -19,9 +19,12 @@ export const LoggedOut: StoryObj = {};
export const LoggedIn: StoryObj = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/renderers/html/template/cli/ts-4-9/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/html';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';
import { createPage } from './Page';

const meta = {
Expand All @@ -19,9 +19,12 @@ export const LoggedOut: StoryObj = {};
export const LoggedIn: StoryObj = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
2 changes: 1 addition & 1 deletion code/renderers/preact/template/cli/Page.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent } from '@storybook/test';

import { Page } from './Page';

Expand Down
11 changes: 7 additions & 4 deletions code/renderers/react/template/cli/js/Page.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';

import { Page } from './Page';

Expand All @@ -17,9 +17,12 @@ export const LoggedOut = {};
export const LoggedIn = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/renderers/react/template/cli/ts-3-8/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';

import { Page } from './Page';

Expand All @@ -21,9 +21,12 @@ export const LoggedOut: Story = {};
export const LoggedIn: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/renderers/react/template/cli/ts-4-9/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';

import { Page } from './Page';

Expand All @@ -21,9 +21,12 @@ export const LoggedOut: Story = {};
export const LoggedIn: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/renderers/svelte/template/cli/js/Page.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';

import Page from './Page.svelte';

Expand All @@ -17,9 +17,12 @@ export const LoggedOut = {};
export const LoggedIn = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/renderers/svelte/template/cli/ts-3-8/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/svelte';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';

import Page from './Page.svelte';

Expand All @@ -21,9 +21,12 @@ export const LoggedOut: Story = {};
export const LoggedIn: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/renderers/svelte/template/cli/ts-4-9/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/svelte';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';

import Page from './Page.svelte';

Expand All @@ -21,9 +21,12 @@ export const LoggedOut: Story = {};
export const LoggedIn: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/renderers/vue/template/cli/Page.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';
import MyPage from './Page.vue';

export default {
Expand All @@ -19,9 +19,12 @@ export const LoggedOut = {};
export const LoggedIn = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
Loading

0 comments on commit fc00057

Please sign in to comment.