test(storybook): add test for `MkChannelFollowButton`

This commit is contained in:
zyoshoka 2024-05-19 18:18:56 +09:00
parent 153df627c3
commit d5c6ec2540
No known key found for this signature in database
GPG Key ID: 0C2CB8FBA309A5B8
1 changed files with 22 additions and 0 deletions

View File

@ -8,9 +8,18 @@
import { StoryObj } from '@storybook/vue3';
import { HttpResponse, http } from 'msw';
import { action } from '@storybook/addon-actions';
import { expect, userEvent, waitFor, within } from '@storybook/test';
import { channel } from '../../.storybook/fakes.js';
import { commonHandlers } from '../../.storybook/mocks.js';
import MkChannelFollowButton from './MkChannelFollowButton.vue';
import { semaphore, tick } from '@/scripts/test-utils.js';
import { i18n } from '@/i18n.js';
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const s = semaphore();
export const Default = {
render(args) {
return {
@ -36,6 +45,19 @@ export const Default = {
channel: channel(),
full: true,
},
async play({ canvasElement }) {
await s.acquire();
await sleep(100);
const canvas = within(canvasElement);
const buttonElement = canvas.getByRole<HTMLButtonElement>('button');
await expect(buttonElement).toHaveTextContent(i18n.ts.follow);
await userEvent.click(buttonElement);
await sleep(100);
await expect(buttonElement).toHaveTextContent(i18n.ts.unfollow);
await sleep(100);
await userEvent.click(buttonElement);
s.release();
},
parameters: {
layout: 'centered',
msw: {