mirror of
https://github.com/gotson/komga.git
synced 2026-05-08 12:35:30 +02:00
add story for login page
This commit is contained in:
parent
d098fac602
commit
e8cb931d31
2 changed files with 101 additions and 0 deletions
|
|
@ -19,3 +19,6 @@ export const handlers = [
|
|||
|
||||
export const response401Unauthorized = () =>
|
||||
HttpResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
|
||||
export const response502BadGateway = () =>
|
||||
HttpResponse.json({ error: 'Bad gateway' }, { status: 502 })
|
||||
|
|
|
|||
98
next-ui/src/pages/login.stories.ts
Normal file
98
next-ui/src/pages/login.stories.ts
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
||||
|
||||
import login from './login.vue'
|
||||
import { http, delay } from 'msw'
|
||||
|
||||
import { response401Unauthorized, response502BadGateway } from '@/mocks/api/handlers'
|
||||
import { expect, waitFor } from 'storybook/test'
|
||||
import { useMessagesStore } from '@/stores/messages'
|
||||
|
||||
const meta = {
|
||||
component: login,
|
||||
render: (args: object) => ({
|
||||
components: { login },
|
||||
setup() {
|
||||
return { args }
|
||||
},
|
||||
template: '<login />',
|
||||
}),
|
||||
parameters: {
|
||||
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
||||
},
|
||||
args: {},
|
||||
} satisfies Meta<typeof login>
|
||||
|
||||
export default meta
|
||||
type Story = StoryObj<typeof meta>
|
||||
|
||||
export const Default: Story = {
|
||||
args: {},
|
||||
}
|
||||
|
||||
export const Invalid: Story = {
|
||||
parameters: {
|
||||
msw: {
|
||||
handlers: [http.get('*/api/v2/users/me', response401Unauthorized)],
|
||||
},
|
||||
},
|
||||
play: async ({ canvas, userEvent }) => {
|
||||
const login = canvas.getByLabelText(/email/i, {
|
||||
selector: 'input',
|
||||
})
|
||||
await userEvent.type(login, 'test@example.org')
|
||||
|
||||
const password = canvas.getByLabelText(/password/i, {
|
||||
selector: 'input',
|
||||
})
|
||||
await userEvent.type(password, 'abc')
|
||||
|
||||
await userEvent.click(canvas.getByRole('button', { name: /sign in/i }))
|
||||
|
||||
await waitFor(() => expect(canvas.getByText(/invalid login/i)).toBeVisible())
|
||||
},
|
||||
}
|
||||
|
||||
export const Loading: Story = {
|
||||
parameters: {
|
||||
msw: {
|
||||
handlers: [http.all('*', async () => await delay(5_000))],
|
||||
},
|
||||
},
|
||||
play: async ({ canvas, userEvent }) => {
|
||||
const login = canvas.getByLabelText(/email/i, {
|
||||
selector: 'input',
|
||||
})
|
||||
await userEvent.type(login, 'test@example.org')
|
||||
|
||||
const password = canvas.getByLabelText(/password/i, {
|
||||
selector: 'input',
|
||||
})
|
||||
await userEvent.type(password, 'abc')
|
||||
|
||||
await userEvent.click(canvas.getByRole('button', { name: /sign in/i }))
|
||||
},
|
||||
}
|
||||
|
||||
export const Error: Story = {
|
||||
parameters: {
|
||||
msw: {
|
||||
handlers: [http.all('*', response502BadGateway)],
|
||||
},
|
||||
},
|
||||
play: async ({ canvas, userEvent }) => {
|
||||
const login = canvas.getByLabelText(/email/i, {
|
||||
selector: 'input',
|
||||
})
|
||||
await userEvent.type(login, 'test@example.org')
|
||||
|
||||
const password = canvas.getByLabelText(/password/i, {
|
||||
selector: 'input',
|
||||
})
|
||||
await userEvent.type(password, 'abc')
|
||||
|
||||
await userEvent.click(canvas.getByRole('button', { name: /sign in/i }))
|
||||
|
||||
const messagesStore = useMessagesStore()
|
||||
await waitFor(() => expect(messagesStore.messages.length).toBe(1))
|
||||
},
|
||||
}
|
||||
Loading…
Reference in a new issue