From 24ad5be5b1431ee13117619336ce4e60df3b1b54 Mon Sep 17 00:00:00 2001 From: takejohn Date: Fri, 3 Jan 2025 08:32:54 +0000 Subject: [PATCH 01/13] =?UTF-8?q?MkInput=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/test/components/MkInput.test.ts | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 packages/frontend/test/components/MkInput.test.ts diff --git a/packages/frontend/test/components/MkInput.test.ts b/packages/frontend/test/components/MkInput.test.ts new file mode 100644 index 000000000000..fed59e7ecc45 --- /dev/null +++ b/packages/frontend/test/components/MkInput.test.ts @@ -0,0 +1,63 @@ +import MkInput from '@/components/MkInput.vue'; +import { fireEvent, render, screen } from '@testing-library/vue'; +import { components } from '@/components/index.js'; +import { directives } from '@/directives/index.js'; +import { describe, expect, test, vi } from 'vitest'; +import { ComponentProps } from 'vue-component-type-helpers'; + +describe('MkInput', () => { + function renderMkInput

>(props: P) { + const mkInput = render(MkInput, { + props, + global: { directives, components }, + }); + const inputElement = mkInput.baseElement.getElementsByTagName('input')[0]; + expect(inputElement).not.toBeUndefined(); + return { props, mkInput, inputElement }; + } + + test('keydown', async () => { + const { props, inputElement } = renderMkInput({ + modelValue: null, + onKeydown: vi.fn((ev) => { + expect(ev.code).toBe('keyA'); + }), + }); + await fireEvent.keyDown(inputElement, { code: 'keyA' }); + expect(props.onKeydown).toHaveBeenCalledOnce(); + }); + + test('enter', async () => { + const { props, inputElement } = renderMkInput({ + modelValue: null, + onEnter: vi.fn((ev) => { + expect(ev.code).toBe('Enter'); + }), + }); + await fireEvent.keyDown(inputElement, { code: 'Enter' }); + expect(props.onEnter).toHaveBeenCalledOnce(); + }); + + test('update', async () => { + const { props, inputElement } = renderMkInput({ + modelValue: null, + 'onUpdate:modelValue': vi.fn((value) => { + expect(value).toBe('Hello'); + }), + }); + await fireEvent.update(inputElement, 'Hello'); + expect(props['onUpdate:modelValue']).toHaveBeenCalledOnce(); + }); + + test('update (type = "number")', async () => { + const { props, inputElement } = renderMkInput({ + modelValue: null, + type: 'number', + 'onUpdate:modelValue': vi.fn((value) => { + expect(value).toBe(42); + }), + }); + await fireEvent.update(inputElement, '42'); + expect(props['onUpdate:modelValue']).toHaveBeenCalledOnce(); + }); +}); From 48df2adeb167ace235208d913717f1170d105e03 Mon Sep 17 00:00:00 2001 From: takejohn Date: Sat, 4 Jan 2025 07:26:31 +0000 Subject: [PATCH 02/13] =?UTF-8?q?type=E3=82=92=E3=82=B8=E3=82=A7=E3=83=8D?= =?UTF-8?q?=E3=83=AA=E3=83=83=E3=82=AF=E5=9E=8B=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/components/MkInput.vue | 49 ++++++++++++++------ 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/packages/frontend/src/components/MkInput.vue b/packages/frontend/src/components/MkInput.vue index 08817fd6a8fa..446768c24e6a 100644 --- a/packages/frontend/src/components/MkInput.vue +++ b/packages/frontend/src/components/MkInput.vue @@ -43,17 +43,17 @@ SPDX-License-Identifier: AGPL-3.0-only -