|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: syuilo and misskey-project |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-only |
| 4 | + */ |
| 5 | + |
| 6 | +/* eslint-disable @typescript-eslint/explicit-function-return-type */ |
| 7 | +/* eslint-disable import/no-default-export */ |
| 8 | +import { StoryObj } from '@storybook/vue3'; |
| 9 | +import { HttpResponse, http } from 'msw'; |
| 10 | +import { action } from '@storybook/addon-actions'; |
| 11 | +import { expect, userEvent, within } from '@storybook/test'; |
| 12 | +import { channel } from '../../.storybook/fakes.js'; |
| 13 | +import { commonHandlers } from '../../.storybook/mocks.js'; |
| 14 | +import MkChannelFollowButton from './MkChannelFollowButton.vue'; |
| 15 | +import { semaphore } from '@/scripts/test-utils.js'; |
| 16 | +import { i18n } from '@/i18n.js'; |
| 17 | + |
| 18 | +function sleep(ms: number) { |
| 19 | + return new Promise(resolve => setTimeout(resolve, ms)); |
| 20 | +} |
| 21 | + |
| 22 | +const s = semaphore(); |
| 23 | +export const Default = { |
| 24 | + render(args) { |
| 25 | + return { |
| 26 | + components: { |
| 27 | + MkChannelFollowButton, |
| 28 | + }, |
| 29 | + setup() { |
| 30 | + return { |
| 31 | + args, |
| 32 | + }; |
| 33 | + }, |
| 34 | + computed: { |
| 35 | + props() { |
| 36 | + return { |
| 37 | + ...this.args, |
| 38 | + }; |
| 39 | + }, |
| 40 | + }, |
| 41 | + template: '<MkChannelFollowButton v-bind="props" />', |
| 42 | + }; |
| 43 | + }, |
| 44 | + args: { |
| 45 | + channel: channel(), |
| 46 | + full: true, |
| 47 | + }, |
| 48 | + async play({ canvasElement }) { |
| 49 | + await s.acquire(); |
| 50 | + await sleep(1000); |
| 51 | + const canvas = within(canvasElement); |
| 52 | + const buttonElement = canvas.getByRole<HTMLButtonElement>('button'); |
| 53 | + await expect(buttonElement).toHaveTextContent(i18n.ts.follow); |
| 54 | + await userEvent.click(buttonElement); |
| 55 | + await sleep(1000); |
| 56 | + await expect(buttonElement).toHaveTextContent(i18n.ts.unfollow); |
| 57 | + await sleep(100); |
| 58 | + await userEvent.click(buttonElement); |
| 59 | + s.release(); |
| 60 | + }, |
| 61 | + parameters: { |
| 62 | + layout: 'centered', |
| 63 | + msw: { |
| 64 | + handlers: [ |
| 65 | + ...commonHandlers, |
| 66 | + http.post('/api/channels/follow', async ({ request }) => { |
| 67 | + action('POST /api/channels/follow')(await request.json()); |
| 68 | + return HttpResponse.json({}); |
| 69 | + }), |
| 70 | + http.post('/api/channels/unfollow', async ({ request }) => { |
| 71 | + action('POST /api/channels/unfollow')(await request.json()); |
| 72 | + return HttpResponse.json({}); |
| 73 | + }), |
| 74 | + ], |
| 75 | + }, |
| 76 | + }, |
| 77 | +} satisfies StoryObj<typeof MkChannelFollowButton>; |
0 commit comments