Skip to content

Commit

Permalink
use @storybook/test in CLI templates
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf authored and kasperpeulen committed Oct 27, 2023
1 parent 4e993be commit 11d1e03
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 19 deletions.
9 changes: 8 additions & 1 deletion 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 @@ -41,6 +41,13 @@ export const LoggedIn: Story = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -19,6 +19,13 @@ export const LoggedIn = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -24,6 +24,13 @@ export const LoggedIn: Story = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -24,6 +24,13 @@ export const LoggedIn: Story = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await 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
9 changes: 8 additions & 1 deletion 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 @@ -19,6 +19,13 @@ export const LoggedIn = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -22,6 +22,13 @@ export const LoggedIn: StoryObj = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -22,6 +22,13 @@ export const LoggedIn: StoryObj = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 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, expect } from '@storybook/test';

import { Page } from './Page';

Expand All @@ -20,6 +20,13 @@ export const LoggedIn = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -20,6 +20,13 @@ export const LoggedIn = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -24,6 +24,13 @@ export const LoggedIn: Story = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -24,6 +24,13 @@ export const LoggedIn: Story = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -20,6 +20,13 @@ export const LoggedIn = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -24,6 +24,13 @@ export const LoggedIn: Story = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -24,6 +24,13 @@ export const LoggedIn: Story = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion 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 @@ -22,6 +22,13 @@ export const LoggedIn = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion code/renderers/vue3/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 MyPage from './Page.vue';

export default {
Expand All @@ -25,6 +25,13 @@ export const LoggedIn = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = await canvas.getByRole('button', {
name: /Log out/i,
});
await expect(logoutButton).toBeInTheDocument();
},
};
9 changes: 8 additions & 1 deletion code/renderers/vue3/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/vue3';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';
import MyPage from './Page.vue';

const meta: Meta<typeof MyPage> = {
Expand Down Expand Up @@ -27,7 +27,14 @@ export const LoggedIn: Story = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

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

Expand Down
9 changes: 8 additions & 1 deletion code/renderers/vue3/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/vue3';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';
import MyPage from './Page.vue';

const meta = {
Expand Down Expand Up @@ -27,7 +27,14 @@ export const LoggedIn: Story = {
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

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

Expand Down

0 comments on commit 11d1e03

Please sign in to comment.