summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/MkChannelFollowButton.stories.impl.ts
diff options
context:
space:
mode:
authormisskey-release-bot[bot] <157398866+misskey-release-bot[bot]@users.noreply.github.com>2024-07-31 11:20:31 +0000
committerGitHub <noreply@github.com>2024-07-31 11:20:31 +0000
commite98f66db51aabef925ea1a8faee6c37f67071107 (patch)
tree168fcc9219f7511bbf9bc198568406bd49fc31bb /packages/frontend/src/components/MkChannelFollowButton.stories.impl.ts
parentfix: remove unreleased section (#14246) (diff)
parentRelease: 2024.7.0 (diff)
downloadsharkey-e98f66db51aabef925ea1a8faee6c37f67071107.tar.gz
sharkey-e98f66db51aabef925ea1a8faee6c37f67071107.tar.bz2
sharkey-e98f66db51aabef925ea1a8faee6c37f67071107.zip
Merge pull request #14233 from misskey-dev/develop
Release: 2024.7.0
Diffstat (limited to 'packages/frontend/src/components/MkChannelFollowButton.stories.impl.ts')
-rw-r--r--packages/frontend/src/components/MkChannelFollowButton.stories.impl.ts71
1 files changed, 71 insertions, 0 deletions
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 0000000000..b9770670dc
--- /dev/null
+++ b/packages/frontend/src/components/MkChannelFollowButton.stories.impl.ts
@@ -0,0 +1,71 @@
+/*
+ * 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 { expect, userEvent, within } from '@storybook/test';
+import { channel } from '../../.storybook/fakes.js';
+import { commonHandlers } from '../../.storybook/mocks.js';
+import MkChannelFollowButton from './MkChannelFollowButton.vue';
+import { i18n } from '@/i18n.js';
+
+function sleep(ms: number) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+}
+
+export const Default = {
+ render(args) {
+ return {
+ components: {
+ MkChannelFollowButton,
+ },
+ setup() {
+ return {
+ args,
+ };
+ },
+ computed: {
+ props() {
+ return {
+ ...this.args,
+ };
+ },
+ },
+ template: '<MkChannelFollowButton v-bind="props" />',
+ };
+ },
+ args: {
+ channel: channel(),
+ full: true,
+ },
+ async play({ canvasElement }) {
+ const canvas = within(canvasElement);
+ const buttonElement = canvas.getByRole<HTMLButtonElement>('button');
+ await expect(buttonElement).toHaveTextContent(i18n.ts.follow);
+ await userEvent.click(buttonElement);
+ await sleep(1000);
+ await expect(buttonElement).toHaveTextContent(i18n.ts.unfollow);
+ await userEvent.click(buttonElement);
+ },
+ 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<typeof MkChannelFollowButton>;