storybook/docs/snippets/vue/login-form-with-play-function.2.js.mdx
2022-07-07 18:50:21 +01:00

58 lines
1.8 KiB
Plaintext

```js
// LoginForm.stories.js
import { userEvent, within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import LoginForm from './LoginForm.vue';
export default {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/7.0/vue/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
title: 'Form',
component: LoginForm,
};
/*
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
* See https://storybook.js.org/docs/7.0/vue/api/csf
* to learn how to use render functions.
*/
export const EmptyForm = {
render: (args, { argTypes }) => ({
components: { LoginForm },
props: Object.keys(argTypes),
template: `<LoginForm v-bind="$props" v-on="$props" />`,
}),
};
export const FilledForm = {
render: (args, { argTypes }) => ({
components: { LoginForm },
props: Object.keys(argTypes),
template: `<LoginForm v-bind="$props" v-on="$props" />`,
}),
play: async ({ canvasElement }) => {
// Starts querying the component from its root element
const canvas = within(canvasElement);
// 👇 Simulate interactions with the component
await userEvent.type(canvas.getByTestId('email'), 'email@provider.com');
await userEvent.type(canvas.getByTestId('password'), 'a-random-password');
// See https://storybook.js.org/docs/7.0/vue/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
// 👇 Assert DOM structure
await expect(
canvas.getByText(
'Everything is perfect. Your account is ready and we should probably get you started!'
)
).toBeInTheDocument();
},
};
```