mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-10 07:13:09 +02:00
build(#10336): write some stories
This commit is contained in:
parent
85f50f3875
commit
671ce6a531
9 changed files with 160 additions and 14 deletions
|
@ -100,8 +100,10 @@ declare global {
|
||||||
function toStories(component: string): string {
|
function toStories(component: string): string {
|
||||||
const msw = `${component.slice(0, -'.vue'.length)}.msw`;
|
const msw = `${component.slice(0, -'.vue'.length)}.msw`;
|
||||||
const implStories = `${component.slice(0, -'.vue'.length)}.stories.impl`;
|
const implStories = `${component.slice(0, -'.vue'.length)}.stories.impl`;
|
||||||
|
const metaStories = `${component.slice(0, -'.vue'.length)}.stories.meta`;
|
||||||
const hasMsw = existsSync(`${msw}.ts`);
|
const hasMsw = existsSync(`${msw}.ts`);
|
||||||
const hasImplStories = existsSync(`${implStories}.ts`);
|
const hasImplStories = existsSync(`${implStories}.ts`);
|
||||||
|
const hasMetaStories = existsSync(`${metaStories}.ts`);
|
||||||
const base = basename(component);
|
const base = basename(component);
|
||||||
const dir = dirname(component);
|
const dir = dirname(component);
|
||||||
const literal = (
|
const literal = (
|
||||||
|
@ -212,6 +214,24 @@ function toStories(component: string): string {
|
||||||
/>
|
/>
|
||||||
) as estree.ImportDeclaration,
|
) as estree.ImportDeclaration,
|
||||||
]),
|
]),
|
||||||
|
...(hasMetaStories
|
||||||
|
? [
|
||||||
|
(
|
||||||
|
<import-declaration
|
||||||
|
source={
|
||||||
|
(<literal value={`./${basename(metaStories)}`} />) as estree.Literal
|
||||||
|
}
|
||||||
|
specifiers={[
|
||||||
|
(
|
||||||
|
<import-namespace-specifier
|
||||||
|
local={(<identifier name='storiesMeta' />) as estree.Identifier}
|
||||||
|
/>
|
||||||
|
) as estree.ImportNamespaceSpecifier,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
) as estree.ImportDeclaration,
|
||||||
|
]
|
||||||
|
: []),
|
||||||
(
|
(
|
||||||
<variable-declaration
|
<variable-declaration
|
||||||
kind={'const' as const}
|
kind={'const' as const}
|
||||||
|
@ -248,6 +268,19 @@ function toStories(component: string): string {
|
||||||
kind={'init' as const}
|
kind={'init' as const}
|
||||||
/>
|
/>
|
||||||
) as estree.Property,
|
) as estree.Property,
|
||||||
|
...(hasMetaStories
|
||||||
|
? [
|
||||||
|
(
|
||||||
|
<spread-element
|
||||||
|
argument={
|
||||||
|
(
|
||||||
|
<identifier name='storiesMeta' />
|
||||||
|
) as estree.Identifier
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) as estree.SpreadElement,
|
||||||
|
]
|
||||||
|
: [])
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
) as estree.ObjectExpression
|
) as estree.ObjectExpression
|
||||||
|
|
|
@ -47,17 +47,17 @@ const common = {
|
||||||
await expect(a).not.toBeInTheDocument();
|
await expect(a).not.toBeInTheDocument();
|
||||||
await expect(i).not.toBeInTheDocument();
|
await expect(i).not.toBeInTheDocument();
|
||||||
buttons = canvas.getAllByRole<HTMLButtonElement>('button');
|
buttons = canvas.getAllByRole<HTMLButtonElement>('button');
|
||||||
await expect(buttons).toHaveLength(args._hasReduce ? 2 : 1);
|
await expect(buttons).toHaveLength(args.__hasReduce ? 2 : 1);
|
||||||
const reduce = args._hasReduce ? buttons[0] : null;
|
const reduce = args.__hasReduce ? buttons[0] : null;
|
||||||
const back = buttons[args._hasReduce ? 1 : 0];
|
const back = buttons[args.__hasReduce ? 1 : 0];
|
||||||
if (reduce) {
|
if (reduce) {
|
||||||
await expect(reduce).toBeInTheDocument();
|
await expect(reduce).toBeInTheDocument();
|
||||||
await expect(reduce.textContent).toBe(
|
await expect(reduce).toHaveTextContent(
|
||||||
i18n.ts._ad.reduceFrequencyOfThisAd
|
i18n.ts._ad.reduceFrequencyOfThisAd
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await expect(back).toBeInTheDocument();
|
await expect(back).toBeInTheDocument();
|
||||||
await expect(back.textContent).toBe(i18n.ts._ad.back);
|
await expect(back).toHaveTextContent(i18n.ts._ad.back);
|
||||||
await userEvent.click(back);
|
await userEvent.click(back);
|
||||||
if (reduce) {
|
if (reduce) {
|
||||||
await expect(reduce).not.toBeInTheDocument();
|
await expect(reduce).not.toBeInTheDocument();
|
||||||
|
@ -75,7 +75,7 @@ const common = {
|
||||||
radio: 1,
|
radio: 1,
|
||||||
url: '#test',
|
url: '#test',
|
||||||
},
|
},
|
||||||
_hasReduce: true,
|
__hasReduce: true,
|
||||||
},
|
},
|
||||||
parameters: {
|
parameters: {
|
||||||
layout: 'centered',
|
layout: 'centered',
|
||||||
|
@ -125,6 +125,6 @@ export const ZeroRatio = {
|
||||||
...Square.args.specify,
|
...Square.args.specify,
|
||||||
ratio: 0,
|
ratio: 0,
|
||||||
},
|
},
|
||||||
_hasReduce: false,
|
__hasReduce: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable import/no-duplicates */
|
||||||
|
import { StoryObj } from '@storybook/vue3';
|
||||||
|
import MkCustomEmoji from './MkCustomEmoji.vue';
|
||||||
|
export const Default = {
|
||||||
|
render(args) {
|
||||||
|
return {
|
||||||
|
components: {
|
||||||
|
MkCustomEmoji,
|
||||||
|
},
|
||||||
|
setup() {
|
||||||
|
return {
|
||||||
|
args,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
props() {
|
||||||
|
return {
|
||||||
|
...args,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
template: '<MkCustomEmoji v-bind="props" />',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
args: {
|
||||||
|
name: 'mi',
|
||||||
|
url: 'https://github.com/misskey-dev/misskey/blob/master/packages/frontend/assets/about-icon.png?raw=true',
|
||||||
|
},
|
||||||
|
parameters: {
|
||||||
|
layout: 'centered',
|
||||||
|
},
|
||||||
|
} satisfies StoryObj<typeof MkCustomEmoji>;
|
||||||
|
export const Normal = {
|
||||||
|
...Default,
|
||||||
|
args: {
|
||||||
|
...Default.args,
|
||||||
|
normal: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export const Missing = {
|
||||||
|
...Default,
|
||||||
|
args: {
|
||||||
|
name: Default.args.name,
|
||||||
|
},
|
||||||
|
};
|
|
@ -1,11 +1,15 @@
|
||||||
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
/* eslint-disable import/no-default-export */
|
/* eslint-disable import/no-default-export */
|
||||||
import { Meta, StoryObj } from '@storybook/vue3';
|
import { Meta } from '@storybook/vue3';
|
||||||
import MkCustomEmoji from './MkCustomEmoji.vue';
|
|
||||||
const meta = {
|
const meta = {
|
||||||
title: 'components/global/MkCustomEmoji',
|
title: 'components/global/MkCustomEmoji',
|
||||||
component: MkCustomEmoji,
|
component: MkCustomEmoji,
|
||||||
} satisfies Meta<typeof MkCustomEmoji>;
|
} satisfies Meta<typeof MkCustomEmoji>;
|
||||||
|
export default meta;
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable import/no-duplicates */
|
||||||
|
import { StoryObj } from '@storybook/vue3';
|
||||||
|
import MkCustomEmoji from './MkCustomEmoji.vue';
|
||||||
export const Default = {
|
export const Default = {
|
||||||
render(args) {
|
render(args) {
|
||||||
return {
|
return {
|
||||||
|
@ -27,8 +31,24 @@ export const Default = {
|
||||||
template: '<MkCustomEmoji v-bind="props" />',
|
template: '<MkCustomEmoji v-bind="props" />',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
args: {
|
||||||
|
name: 'mi',
|
||||||
|
url: 'https://github.com/misskey-dev/misskey/blob/master/packages/frontend/assets/about-icon.png?raw=true',
|
||||||
|
},
|
||||||
parameters: {
|
parameters: {
|
||||||
layout: 'centered',
|
layout: 'centered',
|
||||||
},
|
},
|
||||||
} satisfies StoryObj<typeof MkCustomEmoji>;
|
} satisfies StoryObj<typeof MkCustomEmoji>;
|
||||||
export default meta;
|
export const Normal = {
|
||||||
|
...Default,
|
||||||
|
args: {
|
||||||
|
...Default.args,
|
||||||
|
normal: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export const Missing = {
|
||||||
|
...Default,
|
||||||
|
args: {
|
||||||
|
name: Default.args.name,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable import/no-duplicates */
|
||||||
|
import { StoryObj } from '@storybook/vue3';
|
||||||
|
import MkEmoji from './MkEmoji.vue';
|
||||||
|
export const Default = {
|
||||||
|
render(args) {
|
||||||
|
return {
|
||||||
|
components: {
|
||||||
|
MkEmoji,
|
||||||
|
},
|
||||||
|
setup() {
|
||||||
|
return {
|
||||||
|
args,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
props() {
|
||||||
|
return {
|
||||||
|
...args,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
template: '<MkEmoji v-bind="props" />',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
args: {
|
||||||
|
emoji: '❤',
|
||||||
|
},
|
||||||
|
parameters: {
|
||||||
|
layout: 'centered',
|
||||||
|
},
|
||||||
|
} satisfies StoryObj<typeof MkEmoji>;
|
|
@ -1,11 +1,15 @@
|
||||||
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
/* eslint-disable import/no-default-export */
|
/* eslint-disable import/no-default-export */
|
||||||
import { Meta, StoryObj } from '@storybook/vue3';
|
import { Meta } from '@storybook/vue3';
|
||||||
import MkEmoji from './MkEmoji.vue';
|
|
||||||
const meta = {
|
const meta = {
|
||||||
title: 'components/global/MkEmoji',
|
title: 'components/global/MkEmoji',
|
||||||
component: MkEmoji,
|
component: MkEmoji,
|
||||||
} satisfies Meta<typeof MkEmoji>;
|
} satisfies Meta<typeof MkEmoji>;
|
||||||
|
export default meta;
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable import/no-duplicates */
|
||||||
|
import { StoryObj } from '@storybook/vue3';
|
||||||
|
import MkEmoji from './MkEmoji.vue';
|
||||||
export const Default = {
|
export const Default = {
|
||||||
render(args) {
|
render(args) {
|
||||||
return {
|
return {
|
||||||
|
@ -27,8 +31,10 @@ export const Default = {
|
||||||
template: '<MkEmoji v-bind="props" />',
|
template: '<MkEmoji v-bind="props" />',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
args: {
|
||||||
|
emoji: '❤',
|
||||||
|
},
|
||||||
parameters: {
|
parameters: {
|
||||||
layout: 'centered',
|
layout: 'centered',
|
||||||
},
|
},
|
||||||
} satisfies StoryObj<typeof MkEmoji>;
|
} satisfies StoryObj<typeof MkEmoji>;
|
||||||
export default meta;
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
export const argTypes = {
|
||||||
|
retry: {
|
||||||
|
action: 'retry',
|
||||||
|
},
|
||||||
|
}
|
|
@ -2,9 +2,11 @@
|
||||||
/* eslint-disable import/no-default-export */
|
/* eslint-disable import/no-default-export */
|
||||||
import { Meta, StoryObj } from '@storybook/vue3';
|
import { Meta, StoryObj } from '@storybook/vue3';
|
||||||
import MkError from './MkError.vue';
|
import MkError from './MkError.vue';
|
||||||
|
import * as storiesMeta from './MkError.stories.meta';
|
||||||
const meta = {
|
const meta = {
|
||||||
title: 'components/global/MkError',
|
title: 'components/global/MkError',
|
||||||
component: MkError,
|
component: MkError,
|
||||||
|
...storiesMeta,
|
||||||
} satisfies Meta<typeof MkError>;
|
} satisfies Meta<typeof MkError>;
|
||||||
export const Default = {
|
export const Default = {
|
||||||
render(args) {
|
render(args) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<Transition :name="$store.state.animation ? '_transition_zoom' : ''" appear>
|
<Transition :name="animation ? '_transition_zoom' : ''" appear>
|
||||||
<div :class="$style.root">
|
<div :class="$style.root">
|
||||||
<img :class="$style.img" src="https://xn--931a.moe/assets/error.jpg" class="_ghost"/>
|
<img :class="$style.img" src="https://xn--931a.moe/assets/error.jpg" class="_ghost"/>
|
||||||
<p :class="$style.text"><i class="ti ti-alert-triangle"></i> {{ i18n.ts.somethingHappened }}</p>
|
<p :class="$style.text"><i class="ti ti-alert-triangle"></i> {{ i18n.ts.somethingHappened }}</p>
|
||||||
|
@ -11,7 +11,9 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import MkButton from '@/components/MkButton.vue';
|
import MkButton from '@/components/MkButton.vue';
|
||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
|
import { defaultStore } from '@/store';
|
||||||
|
|
||||||
|
const animation = $ref(defaultStore.reactiveState.animation);
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(ev: 'retry'): void;
|
(ev: 'retry'): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
Loading…
Reference in a new issue