Skip to content

Commit

Permalink
test: add /@:acct stories (misskey-dev#10517)
Browse files Browse the repository at this point in the history
* test: add `/@:acct` stories

* test: add mocks
  • Loading branch information
acid-chicken authored and na2na-p committed Apr 11, 2023
1 parent 8b1362a commit 01b9df8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/frontend/.storybook/fakes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/.storybook/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
74 changes: 74 additions & 0 deletions packages/frontend/src/pages/user/home.stories.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* 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: '<home_ v-bind="props" />',
};
},
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),
},
}));
}),
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: {
// `XActivity` is not compatible with Chromatic for now
disableSnapshot: true,
},
},
} satisfies StoryObj<typeof home_>;

0 comments on commit 01b9df8

Please sign in to comment.