From 914c59402e27295371fdb48c7e5b838fba664115 Mon Sep 17 00:00:00 2001 From: zyoshoka Date: Mon, 13 May 2024 23:22:17 +0900 Subject: [PATCH 1/2] fix: attempt to fix Chromatic test fails --- packages/frontend/src/components/MkModal.vue | 5 ++++- .../frontend/src/components/global/MkAd.stories.impl.ts | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/components/MkModal.vue b/packages/frontend/src/components/MkModal.vue index eb240da75978..9e69ab2207f5 100644 --- a/packages/frontend/src/components/MkModal.vue +++ b/packages/frontend/src/components/MkModal.vue @@ -276,8 +276,11 @@ const align = () => { const onOpened = () => { emit('opened'); + // NOTE: Chromatic テストの際に undefined になる場合がある + if (content.value == null) return; + // モーダルコンテンツにマウスボタンが押され、コンテンツ外でマウスボタンが離されたときにモーダルバックグラウンドクリックと判定させないためにマウスイベントを監視しフラグ管理する - const el = content.value!.children[0]; + const el = content.value.children[0]; el.addEventListener('mousedown', ev => { contentClicking = true; window.addEventListener('mouseup', ev => { diff --git a/packages/frontend/src/components/global/MkAd.stories.impl.ts b/packages/frontend/src/components/global/MkAd.stories.impl.ts index a1d274382fa3..930656e5826e 100644 --- a/packages/frontend/src/components/global/MkAd.stories.impl.ts +++ b/packages/frontend/src/components/global/MkAd.stories.impl.ts @@ -11,6 +11,10 @@ import { i18n } from '@/i18n.js'; let lock: Promise | undefined; +function sleep(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + const common = { render(args) { return { @@ -43,6 +47,7 @@ const common = { lock = new Promise(r => resolve = r); try { + await sleep(100); const canvas = within(canvasElement); const a = canvas.getByRole('link'); // await expect(a.href).toMatch(/^https?:\/\/.*#test$/); @@ -53,7 +58,7 @@ const common = { const i = buttons[0]; await expect(i).toBeInTheDocument(); await userEvent.click(i); - // await expect(canvasElement).toHaveTextContent(i18n.ts._ad.back); + await expect(canvasElement).toHaveTextContent(i18n.ts._ad.back); await expect(a).not.toBeInTheDocument(); await expect(i).not.toBeInTheDocument(); buttons = canvas.getAllByRole('button'); From b4c164d6e2ec4c6cb5a33dec0ff0ca834620e7c0 Mon Sep 17 00:00:00 2001 From: zyoshoka Date: Mon, 13 May 2024 23:44:05 +0900 Subject: [PATCH 2/2] chore: add comment --- packages/frontend/src/components/global/MkAd.stories.impl.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/frontend/src/components/global/MkAd.stories.impl.ts b/packages/frontend/src/components/global/MkAd.stories.impl.ts index 930656e5826e..aef26ab92d64 100644 --- a/packages/frontend/src/components/global/MkAd.stories.impl.ts +++ b/packages/frontend/src/components/global/MkAd.stories.impl.ts @@ -47,6 +47,7 @@ const common = { lock = new Promise(r => resolve = r); try { + // NOTE: sleep しないと何故か落ちる await sleep(100); const canvas = within(canvasElement); const a = canvas.getByRole('link');