From ca5b6e26aeb9d0dbde00c85892e9f1d6c0ecdf7f Mon Sep 17 00:00:00 2001 From: zyoshoka Date: Sat, 18 May 2024 18:33:14 +0900 Subject: [PATCH 01/14] test(storybook): add `components/MkC.*` stories --- packages/frontend/.storybook/fakes.ts | 60 +++++++++ packages/frontend/.storybook/generate.tsx | 2 +- packages/frontend/package.json | 2 + .../MkChannelFollowButton.stories.impl.ts | 55 ++++++++ .../src/components/MkChannelFollowButton.vue | 5 +- .../components/MkChannelList.stories.impl.ts | 61 +++++++++ .../MkChannelPreview.stories.impl.ts | 43 ++++++ .../src/components/MkChart.stories.impl.ts | 117 ++++++++++++++++ packages/frontend/src/components/MkChart.vue | 90 +++++++------ .../components/MkChartLegend.stories.impl.ts | 7 + .../components/MkChartTooltip.stories.impl.ts | 7 + .../components/MkClickerGame.stories.impl.ts | 62 +++++++++ .../components/MkClipPreview.stories.impl.ts | 43 ++++++ .../components/MkCode.core.stories.impl.ts | 7 + .../src/components/MkCode.stories.impl.ts | 44 ++++++ .../components/MkCodeEditor.stories.impl.ts | 62 +++++++++ .../components/MkCodeInline.stories.impl.ts | 37 +++++ .../components/MkColorInput.stories.impl.ts | 50 +++++++ .../components/MkContainer.stories.impl.ts | 7 + .../components/MkContextMenu.stories.impl.ts | 52 ++++++++ .../MkCropperDialog.stories.impl.ts | 66 +++++++++ ...kCustomEmojiDetailedDialog.stories.impl.ts | 38 ++++++ .../src/components/MkCwButton.stories.impl.ts | 48 +++++++ pnpm-lock.yaml | 126 ++++++++---------- 24 files changed, 981 insertions(+), 110 deletions(-) create mode 100644 packages/frontend/src/components/MkChannelFollowButton.stories.impl.ts create mode 100644 packages/frontend/src/components/MkChannelList.stories.impl.ts create mode 100644 packages/frontend/src/components/MkChannelPreview.stories.impl.ts create mode 100644 packages/frontend/src/components/MkChart.stories.impl.ts create mode 100644 packages/frontend/src/components/MkChartLegend.stories.impl.ts create mode 100644 packages/frontend/src/components/MkChartTooltip.stories.impl.ts create mode 100644 packages/frontend/src/components/MkClickerGame.stories.impl.ts create mode 100644 packages/frontend/src/components/MkClipPreview.stories.impl.ts create mode 100644 packages/frontend/src/components/MkCode.core.stories.impl.ts create mode 100644 packages/frontend/src/components/MkCode.stories.impl.ts create mode 100644 packages/frontend/src/components/MkCodeEditor.stories.impl.ts create mode 100644 packages/frontend/src/components/MkCodeInline.stories.impl.ts create mode 100644 packages/frontend/src/components/MkColorInput.stories.impl.ts create mode 100644 packages/frontend/src/components/MkContainer.stories.impl.ts create mode 100644 packages/frontend/src/components/MkContextMenu.stories.impl.ts create mode 100644 packages/frontend/src/components/MkCropperDialog.stories.impl.ts create mode 100644 packages/frontend/src/components/MkCustomEmojiDetailedDialog.stories.impl.ts create mode 100644 packages/frontend/src/components/MkCwButton.stories.impl.ts diff --git a/packages/frontend/.storybook/fakes.ts b/packages/frontend/.storybook/fakes.ts index 3a24ccb248ed..fdb155261bdc 100644 --- a/packages/frontend/.storybook/fakes.ts +++ b/packages/frontend/.storybook/fakes.ts @@ -22,6 +22,66 @@ export function abuseUserReport() { }; } +export function channel(id = 'somechannelid', name = 'Some Channel', bannerUrl: string | null = 'https://github.com/misskey-dev/misskey/blob/master/packages/frontend/assets/fedi.jpg?raw=true'): entities.Channel { + return { + id, + createdAt: '2016-12-28T22:49:51.000Z', + lastNotedAt: '2016-12-28T22:49:51.000Z', + name, + description: null, + userId: null, + bannerUrl, + pinnedNoteIds: [], + color: '#000', + isArchived: false, + usersCount: 1, + notesCount: 1, + isSensitive: false, + allowRenoteToExternal: false, + }; +} + +export function clip(id = 'someclipid', name = 'Some Clip'): entities.Clip { + return { + id, + createdAt: '2016-12-28T22:49:51.000Z', + lastClippedAt: null, + userId: 'someuserid', + user: { + id: 'someuserid', + name: 'Misskey User', + username: 'miskist', + host: 'misskey-hub.net', + avatarUrl: 'https://github.com/misskey-dev/misskey/blob/master/packages/frontend/assets/about-icon.png?raw=true', + avatarBlurhash: 'eQFRshof5NWBRi},juayfPju53WB?0ofs;s*a{ofjuay^SoMEJR%ay', + avatarDecorations: [], + emojis: {}, + badgeRoles: [], + onlineStatus: 'unknown', + }, + notesCount: undefined, + name, + description: 'Some clip description', + isPublic: false, + favoritedCount: 0, + }; +} + +export function emojiDetailed(id = 'someemojiid', name = 'some_emoji'): entities.EmojiDetailed { + return { + id, + aliases: ['alias1', 'alias2'], + name, + category: 'emojiCategory', + host: null, + url: '/client-assets/about-icon.png', + license: null, + isSensitive: false, + localOnly: false, + roleIdsThatCanBeUsedThisEmojiAsReaction: ['roleId1', 'roleId2'], + }; +} + export function galleryPost(isSensitive = false) { return { id: 'somepostid', diff --git a/packages/frontend/.storybook/generate.tsx b/packages/frontend/.storybook/generate.tsx index d74c83a50007..d21eea9d1713 100644 --- a/packages/frontend/.storybook/generate.tsx +++ b/packages/frontend/.storybook/generate.tsx @@ -397,7 +397,7 @@ function toStories(component: string): Promise { const globs = await Promise.all([ glob('src/components/global/Mk*.vue'), glob('src/components/global/RouterView.vue'), - glob('src/components/Mk{A,B}*.vue'), + glob('src/components/Mk[A-C]*.vue'), glob('src/components/MkDigitalClock.vue'), glob('src/components/MkGalleryPostPreview.vue'), glob('src/components/MkSignupServerRules.vue'), diff --git a/packages/frontend/package.json b/packages/frontend/package.json index a482373200ef..c7bfdd71f355 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -104,6 +104,7 @@ "@types/node": "20.12.7", "@types/punycode": "2.1.4", "@types/sanitize-html": "2.11.0", + "@types/seedrandom": "3.0.8", "@types/throttle-debounce": "5.0.2", "@types/tinycolor2": "1.4.6", "@types/uuid": "9.0.8", @@ -128,6 +129,7 @@ "prettier": "3.2.5", "react": "18.3.1", "react-dom": "18.3.1", + "seedrandom": "3.0.5", "start-server-and-test": "2.0.3", "storybook": "8.0.9", "storybook-addon-misskey-theme": "github:misskey-dev/storybook-addon-misskey-theme", diff --git a/packages/frontend/src/components/MkChannelFollowButton.stories.impl.ts b/packages/frontend/src/components/MkChannelFollowButton.stories.impl.ts new file mode 100644 index 000000000000..08357ce7368c --- /dev/null +++ b/packages/frontend/src/components/MkChannelFollowButton.stories.impl.ts @@ -0,0 +1,55 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable import/no-default-export */ +import { StoryObj } from '@storybook/vue3'; +import { HttpResponse, http } from 'msw'; +import { action } from '@storybook/addon-actions'; +import { channel } from '../../.storybook/fakes.js'; +import { commonHandlers } from '../../.storybook/mocks.js'; +import MkChannelFollowButton from './MkChannelFollowButton.vue'; +export const Default = { + render(args) { + return { + components: { + MkChannelFollowButton, + }, + setup() { + return { + args, + }; + }, + computed: { + props() { + return { + ...this.args, + }; + }, + }, + template: '', + }; + }, + args: { + channel: channel(), + full: true, + }, + parameters: { + layout: 'centered', + msw: { + handlers: [ + ...commonHandlers, + http.post('/api/channels/follow', async ({ request }) => { + action('POST /api/channels/follow')(await request.json()); + return HttpResponse.json({}); + }), + http.post('/api/channels/unfollow', async ({ request }) => { + action('POST /api/channels/unfollow')(await request.json()); + return HttpResponse.json({}); + }), + ], + }, + }, +} satisfies StoryObj; diff --git a/packages/frontend/src/components/MkChannelFollowButton.vue b/packages/frontend/src/components/MkChannelFollowButton.vue index 6b1b380e4118..841d37a56847 100644 --- a/packages/frontend/src/components/MkChannelFollowButton.vue +++ b/packages/frontend/src/components/MkChannelFollowButton.vue @@ -26,17 +26,18 @@ SPDX-License-Identifier: AGPL-3.0-only