-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid step function in official-storybook for now
- Loading branch information
1 parent
118fe17
commit 7970c89
Showing
2 changed files
with
47 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/* eslint-disable jest/no-standalone-expect */ | ||
import { Meta, ComponentStoryObj } from '@storybook/react'; | ||
import { expect } from '@storybook/jest'; | ||
import { within, waitFor, fireEvent, userEvent } from '@storybook/testing-library'; | ||
|
@@ -26,30 +25,23 @@ export const Standard: CSF3Story = { | |
|
||
export const StandardEmailFilled = { | ||
...Standard, | ||
play: async ({ canvasElement, step }) => { | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
|
||
await step('Enter email', async () => { | ||
await fireEvent.change(canvas.getByTestId('email'), { | ||
target: { value: '[email protected]' }, | ||
}); | ||
await fireEvent.change(canvas.getByTestId('email'), { | ||
target: { value: '[email protected]' }, | ||
}); | ||
}, | ||
}; | ||
|
||
export const StandardEmailFailed = { | ||
...Standard, | ||
play: async ({ args, canvasElement, step }) => { | ||
play: async ({ args, canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
|
||
await step('Enter email and password', async () => { | ||
await userEvent.type(canvas.getByTestId('email'), 'gert@chromatic'); | ||
await userEvent.type(canvas.getByTestId('password1'), 'supersecret'); | ||
}); | ||
|
||
await step('Submit form', async () => { | ||
await userEvent.click(canvas.getByRole('button', { name: /create account/i })); | ||
}); | ||
await userEvent.type(canvas.getByTestId('email'), 'gert@chromatic'); | ||
await userEvent.type(canvas.getByTestId('password1'), 'supersecret'); | ||
await userEvent.click(canvas.getByRole('button', { name: /create account/i })); | ||
|
||
await canvas.findByText('Please enter a correctly formatted email address'); | ||
await expect(args.onSubmit).not.toHaveBeenCalled(); | ||
|
@@ -58,17 +50,12 @@ export const StandardEmailFailed = { | |
|
||
export const StandardEmailSuccess = { | ||
...Standard, | ||
play: async ({ args, canvasElement, step }) => { | ||
play: async ({ args, canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
|
||
await step('Enter email and password', async () => { | ||
await userEvent.type(canvas.getByTestId('email'), '[email protected]'); | ||
await userEvent.type(canvas.getByTestId('password1'), 'testpasswordthatwontfail'); | ||
}); | ||
|
||
await step('Submit form', async () => { | ||
await userEvent.click(canvas.getByTestId('submit')); | ||
}); | ||
await userEvent.type(canvas.getByTestId('email'), '[email protected]'); | ||
await userEvent.type(canvas.getByTestId('password1'), 'testpasswordthatwontfail'); | ||
await userEvent.click(canvas.getByTestId('submit')); | ||
|
||
await waitFor(async () => { | ||
await expect(args.onSubmit).toHaveBeenCalledTimes(1); | ||
|
@@ -86,13 +73,8 @@ export const StandardPasswordFailed = { | |
const canvas = within(context.canvasElement); | ||
await StandardEmailFilled.play(context); | ||
|
||
await context.step('Enter password', async () => { | ||
await userEvent.type(canvas.getByTestId('password1'), 'asdf'); | ||
}); | ||
|
||
await context.step('Submit form', async () => { | ||
await userEvent.click(canvas.getByTestId('submit')); | ||
}); | ||
await userEvent.type(canvas.getByTestId('password1'), 'asdf'); | ||
await userEvent.click(canvas.getByTestId('submit')); | ||
}, | ||
}; | ||
|
||
|
@@ -117,12 +99,9 @@ export const VerificationPassword = { | |
play: async (context) => { | ||
const canvas = within(context.canvasElement); | ||
await StandardEmailFilled.play(context); | ||
await context.step('Enter password', async () => { | ||
await userEvent.type(canvas.getByTestId('password1'), 'asdfasdf'); | ||
}); | ||
await context.step('Submit form', async () => { | ||
await userEvent.click(canvas.getByTestId('submit')); | ||
}); | ||
|
||
await userEvent.type(canvas.getByTestId('password1'), 'asdfasdf'); | ||
await userEvent.click(canvas.getByTestId('submit')); | ||
}, | ||
}; | ||
|
||
|
@@ -131,13 +110,10 @@ export const VerificationPasswordMismatch = { | |
play: async (context) => { | ||
const canvas = within(context.canvasElement); | ||
await StandardEmailFilled.play(context); | ||
await context.step('Enter passwords', async () => { | ||
await userEvent.type(canvas.getByTestId('password1'), 'asdfasdf'); | ||
await userEvent.type(canvas.getByTestId('password2'), 'asdf1234'); | ||
}); | ||
await context.step('Submit form', async () => { | ||
await userEvent.click(canvas.getByTestId('submit')); | ||
}); | ||
|
||
await userEvent.type(canvas.getByTestId('password1'), 'asdfasdf'); | ||
await userEvent.type(canvas.getByTestId('password2'), 'asdf1234'); | ||
await userEvent.click(canvas.getByTestId('submit')); | ||
}, | ||
}; | ||
|
||
|
@@ -147,16 +123,12 @@ export const VerificationSuccess = { | |
const canvas = within(context.canvasElement); | ||
await StandardEmailFilled.play(context); | ||
|
||
await context.step('Enter passwords', async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
await userEvent.type(canvas.getByTestId('password1'), 'helloyou', { delay: 50 }); | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
await userEvent.type(canvas.getByTestId('password2'), 'helloyou', { delay: 50 }); | ||
}); | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
await userEvent.type(canvas.getByTestId('password1'), 'helloyou', { delay: 50 }); | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
await userEvent.type(canvas.getByTestId('password2'), 'helloyou', { delay: 50 }); | ||
|
||
await context.step('Submit form', async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
await userEvent.click(canvas.getByTestId('submit')); | ||
}); | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
await userEvent.click(canvas.getByTestId('submit')); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters