From 4a5450ac25f3aa347ac4027f64d77ddcdc667144 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Mon, 30 Jun 2025 15:00:46 +0800 Subject: [PATCH] more component tests --- next-ui/src/App.vue | 4 +- next-ui/src/components.d.ts | 1 + .../user/form/ChangePassword.stories.ts | 60 ++++++++++++++++ .../components/user/form/ChangePassword.vue | 2 +- .../fragment/user/form/CreateEdit.stories.ts | 61 ++++++++++++++++ .../fragment}/user/form/CreateEdit.vue | 0 next-ui/src/mocks/api/handlers.ts | 10 ++- next-ui/src/mocks/api/handlers/libraries.ts | 72 +++++++++++++++++++ next-ui/src/mocks/api/handlers/referential.ts | 7 ++ next-ui/src/pages/server/users.vue | 2 +- 10 files changed, 214 insertions(+), 5 deletions(-) create mode 100644 next-ui/src/components/user/form/ChangePassword.stories.ts create mode 100644 next-ui/src/fragments/fragment/user/form/CreateEdit.stories.ts rename next-ui/src/{components => fragments/fragment}/user/form/CreateEdit.vue (100%) create mode 100644 next-ui/src/mocks/api/handlers/libraries.ts create mode 100644 next-ui/src/mocks/api/handlers/referential.ts diff --git a/next-ui/src/App.vue b/next-ui/src/App.vue index f39946ec..345ddcf1 100644 --- a/next-ui/src/App.vue +++ b/next-ui/src/App.vue @@ -3,8 +3,8 @@ - - + + diff --git a/next-ui/src/components.d.ts b/next-ui/src/components.d.ts index 0ac26853..fbae7f4b 100644 --- a/next-ui/src/components.d.ts +++ b/next-ui/src/components.d.ts @@ -19,6 +19,7 @@ declare module 'vue' { FragmentLocaleSelector: typeof import('./fragments/fragment/LocaleSelector.vue')['default'] FragmentSnackQueue: typeof import('./fragments/fragment/SnackQueue.vue')['default'] FragmentThemeSelector: typeof import('./fragments/fragment/ThemeSelector.vue')['default'] + FragmentUserFormCreateEdit: typeof import('./fragments/fragment/user/form/CreateEdit.vue')['default'] HelloWorld: typeof import('./components/HelloWorld.vue')['default'] LayoutAppBar: typeof import('./fragments/layout/app/Bar.vue')['default'] LayoutAppDrawer: typeof import('./fragments/layout/app/drawer/Drawer.vue')['default'] diff --git a/next-ui/src/components/user/form/ChangePassword.stories.ts b/next-ui/src/components/user/form/ChangePassword.stories.ts new file mode 100644 index 00000000..4be89916 --- /dev/null +++ b/next-ui/src/components/user/form/ChangePassword.stories.ts @@ -0,0 +1,60 @@ +import type { Meta, StoryObj } from '@storybook/vue3-vite' + +import ChangePassword from './ChangePassword.vue' +import { expect, waitFor } from 'storybook/test' + +const meta = { + component: ChangePassword, + render: (args: object) => ({ + components: { ChangePassword }, + setup() { + return { args } + }, + template: '', + }), + parameters: { + // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout + }, + args: {}, +} satisfies Meta + +export default meta +type Story = StoryObj + +export const Default: Story = { + args: {}, +} + +export const MatchingPasswords: Story = { + args: {}, + play: async ({ canvas, userEvent }) => { + const password1 = canvas.getByLabelText(/new password/i, { + selector: 'input', + }) + await userEvent.type(password1, 'abc') + + const password2 = canvas.getByLabelText(/confirm password/i, { + selector: 'input', + }) + await userEvent.type(password2, 'abc') + + await waitFor(() => expect(canvas.getByText(/must be identical/i)).not.toBeVisible()) + }, +} + +export const DifferentPasswords: Story = { + args: {}, + play: async ({ canvas, userEvent }) => { + const password1 = canvas.getByLabelText(/new password/i, { + selector: 'input', + }) + await userEvent.type(password1, 'abc') + + const password2 = canvas.getByLabelText(/confirm password/i, { + selector: 'input', + }) + await userEvent.type(password2, 'def') + + await waitFor(() => expect(canvas.getByText(/must be identical/i)).toBeVisible()) + }, +} diff --git a/next-ui/src/components/user/form/ChangePassword.vue b/next-ui/src/components/user/form/ChangePassword.vue index da6e85f7..e07f94e9 100644 --- a/next-ui/src/components/user/form/ChangePassword.vue +++ b/next-ui/src/components/user/form/ChangePassword.vue @@ -44,7 +44,7 @@