From 01c4dddb591c472b227c178dd505a9ebe0ed9fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Sat, 8 Apr 2023 16:02:41 +0900 Subject: [PATCH 1/2] test: add `/@:acct` stories --- packages/frontend/.storybook/fakes.ts | 1 + packages/frontend/.storybook/generate.tsx | 1 + .../src/pages/user/home.stories.impl.ts | 61 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 packages/frontend/src/pages/user/home.stories.impl.ts diff --git a/packages/frontend/.storybook/fakes.ts b/packages/frontend/.storybook/fakes.ts index 23b82a8ac523..5fd21cdf0a45 100644 --- a/packages/frontend/.storybook/fakes.ts +++ b/packages/frontend/.storybook/fakes.ts @@ -77,6 +77,7 @@ export function userDetailed(id = 'someuserid', username = 'miskist', host = 'mi createdAt: '2016-12-28T22:49:51.000Z', description: 'I am a cool user!', ffVisibility: 'public', + roles: [], fields: [ { name: 'Website', diff --git a/packages/frontend/.storybook/generate.tsx b/packages/frontend/.storybook/generate.tsx index b3bbeeb51cf1..dd40bac2ccd2 100644 --- a/packages/frontend/.storybook/generate.tsx +++ b/packages/frontend/.storybook/generate.tsx @@ -398,6 +398,7 @@ function toStories(component: string): string { Promise.all([ glob('src/components/global/*.vue'), glob('src/components/MkGalleryPostPreview.vue'), + glob('src/pages/user/home.vue'), ]) .then((globs) => globs.flat()) .then((components) => Promise.all(components.map((component) => { diff --git a/packages/frontend/src/pages/user/home.stories.impl.ts b/packages/frontend/src/pages/user/home.stories.impl.ts new file mode 100644 index 000000000000..1ba55a237e66 --- /dev/null +++ b/packages/frontend/src/pages/user/home.stories.impl.ts @@ -0,0 +1,61 @@ +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +import { StoryObj } from '@storybook/vue3'; +import { rest } from 'msw'; +import { userDetailed } from '../../../.storybook/fakes'; +import { commonHandlers } from '../../../.storybook/mocks'; +import home_ from './home.vue'; +export const Default = { + render(args) { + return { + components: { + home_, + }, + setup() { + return { + args, + }; + }, + computed: { + props() { + return { + ...this.args, + }; + }, + }, + template: '', + }; + }, + args: { + user: userDetailed(), + disableNotes: false, + }, + parameters: { + layout: 'fullscreen', + msw: { + handlers: [ + ...commonHandlers, + rest.post('/api/users/notes', (req, res, ctx) => { + return res(ctx.json([])); + }), + rest.get('/api/charts/user/notes', (req, res, ctx) => { + const length = Math.max(Math.min(parseInt(req.url.searchParams.get('limit') ?? '30', 10), 1), 300); + return res(ctx.json({ + total: Array.from({ length }, () => 0), + inc: Array.from({ length }, () => 0), + dec: Array.from({ length }, () => 0), + diffs: { + normal: Array.from({ length }, () => 0), + reply: Array.from({ length }, () => 0), + renote: Array.from({ length }, () => 0), + withFile: Array.from({ length }, () => 0), + }, + })); + }), + ], + }, + chromatic: { + // `XActivity` is not compatible with Chromatic for now + disableSnapshot: true, + }, + }, +} satisfies StoryObj; From 127be7ece6cbe02338cc295eb46fc6a9db457456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Sat, 8 Apr 2023 16:59:29 +0900 Subject: [PATCH 2/2] test: add mocks --- .../frontend/src/pages/user/home.stories.impl.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/frontend/src/pages/user/home.stories.impl.ts b/packages/frontend/src/pages/user/home.stories.impl.ts index 1ba55a237e66..50da0c699187 100644 --- a/packages/frontend/src/pages/user/home.stories.impl.ts +++ b/packages/frontend/src/pages/user/home.stories.impl.ts @@ -51,6 +51,19 @@ export const Default = { }, })); }), + rest.get('/api/charts/user/pv', (req, res, ctx) => { + const length = Math.max(Math.min(parseInt(req.url.searchParams.get('limit') ?? '30', 10), 1), 300); + return res(ctx.json({ + upv: { + user: Array.from({ length }, () => 0), + visitor: Array.from({ length }, () => 0), + }, + pv: { + user: Array.from({ length }, () => 0), + visitor: Array.from({ length }, () => 0), + }, + })); + }), ], }, chromatic: {