2024-06-08 04:00:54 -05:00
|
|
|
/*
|
|
|
|
* 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';
|
2024-07-01 20:57:20 -05:00
|
|
|
import { expect, userEvent, within } from '@storybook/test';
|
2024-06-08 04:00:54 -05:00
|
|
|
import { commonHandlers } from '../../.storybook/mocks.js';
|
|
|
|
import MkClickerGame from './MkClickerGame.vue';
|
|
|
|
|
|
|
|
function sleep(ms: number) {
|
|
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Default = {
|
|
|
|
render(args) {
|
|
|
|
return {
|
|
|
|
components: {
|
|
|
|
MkClickerGame,
|
|
|
|
},
|
|
|
|
setup() {
|
|
|
|
return {
|
|
|
|
args,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
props() {
|
|
|
|
return {
|
|
|
|
...this.args,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
template: '<MkClickerGame v-bind="props" />',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
async play({ canvasElement }) {
|
|
|
|
await sleep(1000);
|
|
|
|
const canvas = within(canvasElement);
|
|
|
|
const count = canvas.getByTestId('count');
|
2024-07-01 20:57:20 -05:00
|
|
|
await expect(count).toHaveTextContent('0');
|
|
|
|
const buttonElement = canvas.getByRole<HTMLButtonElement>('button');
|
|
|
|
await userEvent.click(buttonElement);
|
|
|
|
await expect(count).toHaveTextContent('1');
|
2024-06-08 04:00:54 -05:00
|
|
|
},
|
|
|
|
parameters: {
|
|
|
|
layout: 'centered',
|
|
|
|
msw: {
|
|
|
|
handlers: [
|
|
|
|
...commonHandlers,
|
|
|
|
http.post('/api/i/registry/get', async ({ request }) => {
|
|
|
|
action('POST /api/i/registry/get')(await request.json());
|
|
|
|
return HttpResponse.json({
|
|
|
|
error: {
|
|
|
|
message: 'No such key.',
|
|
|
|
code: 'NO_SUCH_KEY',
|
|
|
|
id: 'ac3ed68a-62f0-422b-a7bc-d5e09e8f6a6a',
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
status: 400,
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
http.post('/api/i/registry/set', async ({ request }) => {
|
|
|
|
action('POST /api/i/registry/set')(await request.json());
|
|
|
|
return HttpResponse.json(undefined, { status: 204 });
|
|
|
|
}),
|
|
|
|
http.post('/api/i/claim-achievement', async ({ request }) => {
|
|
|
|
action('POST /api/i/claim-achievement')(await request.json());
|
|
|
|
return HttpResponse.json(undefined, { status: 204 });
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} satisfies StoryObj<typeof MkClickerGame>;
|