Skip to content

Commit

Permalink
test(misskey-dev#10336): add components/Mk[A-B].* stories (misskey-…
Browse files Browse the repository at this point in the history
…dev#10475)

* chore(misskey-dev#10336): register snippets

* test(misskey-dev#10336): add `components/Mk[A-B].*` stories

* build: desynced lockfile

* ci(misskey-dev#10336): preload assets

* ci(misskey-dev#10336): use pull_request

* build: update lockfile

* fix: reactivity transform

* chore: track upstream changes

* refactor: avoid temporary previous tapping declarations

* revert: avoid temporary previous tapping declarations

This reverts commit e649b1b.

* test: flaky snapshots

* style: import
  • Loading branch information
acid-chicken authored Apr 13, 2023
1 parent 2a7ba37 commit 9bb6c53
Show file tree
Hide file tree
Showing 21 changed files with 617 additions and 245 deletions.
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ You can override the default story by creating a impl story file (`MyComponent.s

```ts
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable import/no-duplicates */
import { StoryObj } from '@storybook/vue3';
import MyComponent from './MyComponent.vue';
export const Default = {
Expand Down
12 changes: 6 additions & 6 deletions packages/frontend/.storybook/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function toStories(component: string): string {
.replace(/[-.]|^(?=\d)/g, '_')
.replace(/(?<=^[^A-Z_]*$)/, '_')}
/> as estree.Identifier;
const parameters = (
const parameters =
<object-expression
properties={[
<property
Expand All @@ -137,9 +137,8 @@ function toStories(component: string): string {
]
: []),
]}
/>
) as estree.ObjectExpression;
const program = (
/> as estree.ObjectExpression;
const program =
<program
body={[
<import-declaration
Expand Down Expand Up @@ -379,11 +378,11 @@ function toStories(component: string): string {
declaration={(<identifier name='meta' />) as estree.Identifier}
/> as estree.ExportDefaultDeclaration,
]}
/>
) as estree.Program;
/> as estree.Program;
return format(
'/* eslint-disable @typescript-eslint/explicit-function-return-type */\n' +
'/* eslint-disable import/no-default-export */\n' +
'/* eslint-disable import/no-duplicates */\n' +
generate(program, { generator }) +
(hasImplStories ? readFileSync(`${implStories}.ts`, 'utf-8') : ''),
{
Expand All @@ -397,6 +396,7 @@ function toStories(component: string): string {
// glob('src/{components,pages,ui,widgets}/**/*.vue')
Promise.all([
glob('src/components/global/*.vue'),
glob('src/components/Mk{A,B}*.vue'),
glob('src/components/MkGalleryPostPreview.vue'),
glob('src/pages/user/home.vue'),
])
Expand Down
10 changes: 10 additions & 0 deletions packages/frontend/.storybook/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ export const onUnhandledRequest = ((req, print) => {
}) satisfies SharedOptions['onUnhandledRequest'];

export const commonHandlers = [
rest.get('/fluent-emoji/:codepoints.png', async (req, res, ctx) => {
const { codepoints } = req.params;
const value = await fetch(`https://raw.githubusercontent.com/misskey-dev/emojis/main/dist/${codepoints}.png`).then((response) => response.blob());
return res(ctx.set('Content-Type', 'image/png'), ctx.body(value));
}),
rest.get('/fluent-emojis/:codepoints.png', async (req, res, ctx) => {
const { codepoints } = req.params;
const value = await fetch(`https://raw.githubusercontent.com/misskey-dev/emojis/main/dist/${codepoints}.png`).then((response) => response.blob());
return res(ctx.set('Content-Type', 'image/png'), ctx.body(value));
}),
rest.get('/twemoji/:codepoints.svg', async (req, res, ctx) => {
const { codepoints } = req.params;
const value = await fetch(`https://unpkg.com/@discordapp/[email protected]/dist/svg/${codepoints}.svg`).then((response) => response.blob());
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<link rel="preload" href="https://github.com/misskey-dev/misskey/blob/master/packages/frontend/assets/about-icon.png?raw=true" as="image" type="image/png" crossorigin="anonymous">
<link rel="preload" href="https://github.com/misskey-dev/misskey/blob/master/packages/frontend/assets/fedi.jpg?raw=true" as="image" type="image/jpeg" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/@tabler/[email protected]/tabler-icons.min.css">
<link rel="stylesheet" href="https://unpkg.com/@fontsource/m-plus-rounded-1c/index.css">
<style>
Expand Down
84 changes: 84 additions & 0 deletions packages/frontend/.vscode/storybook.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"Storybook Story Impl File": {
"scope": "typescript",
"prefix": "storyimpl",
"body": [
"/* eslint-disable @typescript-eslint/explicit-function-return-type */",
"import { StoryObj } from '@storybook/vue3';",
"import $1 from './$1.vue';",
"export const Default = {",
"\trender(args) {",
"\t\treturn {",
"\t\t\tcomponents: {",
"\t\t\t\t$1,",
"\t\t\t},",
"\t\t\tsetup() {",
"\t\t\t\treturn {",
"\t\t\t\t\targs,",
"\t\t\t\t};",
"\t\t\t},",
"\t\t\tcomputed: {",
"\t\t\t\tprops() {",
"\t\t\t\t\treturn {",
"\t\t\t\t\t\t...this.args,",
"\t\t\t\t\t};",
"\t\t\t\t},",
"\t\t\t},",
"\t\t\ttemplate: '<$1 v-bind=\"props\" />',",
"\t\t};",
"\t},",
"\targs: {",
"\t\t$2",
"\t},",
"\tparameters: {",
"\t\tlayout: 'centered',",
"\t},",
"} satisfies StoryObj<typeof $1>;",
""
]
},
"Storybook Story Impl File (w/ events)": {
"scope": "typescript",
"prefix": "storyimplevent",
"body": [
"/* eslint-disable @typescript-eslint/explicit-function-return-type */",
"import { action } from '@storybook/addon-actions';",
"import { StoryObj } from '@storybook/vue3';",
"import $1 from './$1.vue';",
"export const Default = {",
"\trender(args) {",
"\t\treturn {",
"\t\t\tcomponents: {",
"\t\t\t\t$1,",
"\t\t\t},",
"\t\t\tsetup() {",
"\t\t\t\treturn {",
"\t\t\t\t\targs,",
"\t\t\t\t};",
"\t\t\t},",
"\t\t\tcomputed: {",
"\t\t\t\tprops() {",
"\t\t\t\t\treturn {",
"\t\t\t\t\t\t...this.args,",
"\t\t\t\t\t};",
"\t\t\t\t},",
"\t\t\t\tevents() {",
"\t\t\t\t\treturn {",
"\t\t\t\t\t\t$3",
"\t\t\t\t\t};",
"\t\t\t\t},",
"\t\t\t},",
"\t\t\ttemplate: '<$1 v-bind=\"props\" v-on=\"events\" />',",
"\t\t};",
"\t},",
"\targs: {",
"\t\t$2",
"\t},",
"\tparameters: {",
"\t\tlayout: 'centered',",
"\t},",
"} satisfies StoryObj<typeof $1>;",
""
]
}
}
1 change: 1 addition & 0 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"vuedraggable": "next"
},
"devDependencies": {
"@storybook/addon-actions": "7.0.2",
"@storybook/addon-essentials": "7.0.2",
"@storybook/addon-interactions": "7.0.2",
"@storybook/addon-links": "7.0.2",
Expand Down
49 changes: 49 additions & 0 deletions packages/frontend/src/components/MkAbuseReport.stories.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { action } from '@storybook/addon-actions';
import { StoryObj } from '@storybook/vue3';
import { rest } from 'msw';
import { abuseUserReport } from '../../.storybook/fakes';
import { commonHandlers } from '../../.storybook/mocks';
import MkAbuseReport from './MkAbuseReport.vue';
export const Default = {
render(args) {
return {
components: {
MkAbuseReport,
},
setup() {
return {
args,
};
},
computed: {
props() {
return {
...this.args,
};
},
events() {
return {
resolved: action('resolved'),
};
},
},
template: '<MkAbuseReport v-bind="props" v-on="events" />',
};
},
args: {
report: abuseUserReport(),
},
parameters: {
layout: 'fullscreen',
msw: {
handlers: [
...commonHandlers,
rest.post('/api/admin/resolve-abuse-user-report', async (req, res, ctx) => {
action('POST /api/admin/resolve-abuse-user-report')(await req.json());
return res(ctx.json({}));
}),
],
},
},
} satisfies StoryObj<typeof MkAbuseReport>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { action } from '@storybook/addon-actions';
import { StoryObj } from '@storybook/vue3';
import { rest } from 'msw';
import { userDetailed } from '../../.storybook/fakes';
import { commonHandlers } from '../../.storybook/mocks';
import MkAbuseReportWindow from './MkAbuseReportWindow.vue';
export const Default = {
render(args) {
return {
components: {
MkAbuseReportWindow,
},
setup() {
return {
args,
};
},
computed: {
props() {
return {
...this.args,
};
},
events() {
return {
'closed': action('closed'),
};
},
},
template: '<MkAbuseReportWindow v-bind="props" v-on="events" />',
};
},
args: {
user: userDetailed(),
},
parameters: {
layout: 'centered',
msw: {
handlers: [
...commonHandlers,
rest.post('/api/users/report-abuse', async (req, res, ctx) => {
action('POST /api/users/report-abuse')(await req.json());
return res(ctx.json({}));
}),
],
},
},
} satisfies StoryObj<typeof MkAbuseReportWindow>;
33 changes: 33 additions & 0 deletions packages/frontend/src/components/MkAccountMoved.stories.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { StoryObj } from '@storybook/vue3';
import { userDetailed } from '../../.storybook/fakes';
import MkAccountMoved from './MkAccountMoved.vue';
export const Default = {
render(args) {
return {
components: {
MkAccountMoved,
},
setup() {
return {
args,
};
},
computed: {
props() {
return {
...this.args,
};
},
},
template: '<MkAccountMoved v-bind="props" />',
};
},
args: {
username: userDetailed().username,
host: userDetailed().host,
},
parameters: {
layout: 'centered',
},
} satisfies StoryObj<typeof MkAccountMoved>;
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkAccountMoved.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div :class="$style.root">
<i class="ti ti-plane-departure" style="margin-right: 8px;"></i>
{{ i18n.ts.accountMoved }}
<MkMention :class="$style.link" :username="acct" :host="host ?? localHost"/>
<MkMention :class="$style.link" :username="username" :host="host ?? localHost"/>
</div>
</template>
Expand All @@ -12,7 +12,7 @@ import { i18n } from '@/i18n';
import { host as localHost } from '@/config';
defineProps<{
acct: string;
username: string;
host: string;
}>();
</script>
Expand Down
56 changes: 56 additions & 0 deletions packages/frontend/src/components/MkAchievements.stories.impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* 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 MkAchievements from './MkAchievements.vue';
import { ACHIEVEMENT_TYPES } from '@/scripts/achievements';
export const Empty = {
render(args) {
return {
components: {
MkAchievements,
},
setup() {
return {
args,
};
},
computed: {
props() {
return {
...this.args,
};
},
},
template: '<MkAchievements v-bind="props" />',
};
},
args: {
user: userDetailed(),
},
parameters: {
layout: 'fullscreen',
msw: {
handlers: [
...commonHandlers,
rest.post('/api/users/achievements', (req, res, ctx) => {
return res(ctx.json([]));
}),
],
},
},
} satisfies StoryObj<typeof MkAchievements>;
export const All = {
...Empty,
parameters: {
msw: {
handlers: [
...commonHandlers,
rest.post('/api/users/achievements', (req, res, ctx) => {
return res(ctx.json(ACHIEVEMENT_TYPES.map((name) => ({ name, unlockedAt: 0 }))));
}),
],
},
},
} satisfies StoryObj<typeof MkAchievements>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { StoryObj } from '@storybook/vue3';
import MkAnalogClock from './MkAnalogClock.vue';
import isChromatic from 'chromatic';
export const Default = {
render(args) {
return {
Expand All @@ -22,6 +23,14 @@ export const Default = {
template: '<MkAnalogClock v-bind="props" />',
};
},
args: {
now: isChromatic() ? () => new Date('2023-01-01T10:10:30') : undefined,
},
decorators: [
() => ({
template: '<div style="container-type:inline-size;height:100%"><div style="height:100cqmin;margin:auto;width:100cqmin"><story/></div></div>',
}),
],
parameters: {
layout: 'fullscreen',
},
Expand Down
Loading

0 comments on commit 9bb6c53

Please sign in to comment.