Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ソング関連のe2eテストを追加 #1849

Merged
merged 10 commits into from
Feb 22, 2024
2 changes: 2 additions & 0 deletions src/components/Sing/ScoreSequencer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<div
ref="sequencerBody"
class="sequencer-body"
aria-label="シーケンサ"
weweweok marked this conversation as resolved.
Show resolved Hide resolved
@mousedown="onMouseDown"
@mousemove="onMouseMove"
@mouseup="onMouseUp"
Expand Down Expand Up @@ -147,6 +148,7 @@
/>
<div
class="sequencer-playhead"
data-testid="sequencer-playhead"
weweweok marked this conversation as resolved.
Show resolved Hide resolved
:style="{
transform: `translateX(${playheadX - scrollX}px)`,
}"
Expand Down
6 changes: 5 additions & 1 deletion src/components/Sing/SequencerNote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
<div class="note-right-edge" @mousedown="onRightEdgeMouseDown"></div>
<context-menu ref="contextMenu" :menudata="contextMenuData" />
</div>
<div class="note-lyric" @mousedown="onLyricMouseDown">
<div
class="note-lyric"
data-testid="note-lyric"
@mousedown="onLyricMouseDown"
>
{{ lyric }}
</div>
<input
Expand Down
81 changes: 81 additions & 0 deletions tests/e2e/browser/song/ソング.spec.ts
weweweok marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { test, expect, Page, Locator } from "@playwright/test";

import { gotoHome, navigateToMain } from "../../navigators";

test.beforeEach(gotoHome);

async function navigateToSong(page: Page) {
await navigateToMain(page);
expect(page.getByText("ソング")).toBeVisible();
await page.getByText("ソング").click();
}

async function getCurrentPlayhead(page: Page) {
const boundingBox = await page
.getByTestId("sequencer-playhead")
.boundingBox();
if (boundingBox == null) throw new Error("再生バーが見つかりません");
return boundingBox;
}

test("再生ボタンを押して再生できる", async ({ page }) => {
await navigateToSong(page);
// TODO: ページ内のオーディオを検出するテストを追加する

const sequencer = page.getByLabel("シーケンサ");
weweweok marked this conversation as resolved.
Show resolved Hide resolved

await sequencer.click({ position: { x: 107, y: 171 } }); // ノートを追加
const beforePosition = await getCurrentPlayhead(page); // 再生ヘッドの初期位置
await page.getByText("play_arrow").click(); // 再生ボタンを押す
await page.waitForTimeout(3000);
await page.getByText("stop").click(); // 停止ボタンを押す
const afterPosition = await getCurrentPlayhead(page); // 再生ヘッドの再生後の位置
expect(afterPosition.x).not.toEqual(beforePosition.x);
expect(afterPosition.y).toEqual(beforePosition.y);
});

test("ノートを追加・削除できる", async ({ page }) => {
await navigateToSong(page);

const sequencer = page.getByLabel("シーケンサ");

const getCurrentNoteCount = async () =>
await sequencer.locator(".note").count();

// ノートの追加
expect(await getCurrentNoteCount()).toBe(0);
await sequencer.click({ position: { x: 107, y: 171 } });
expect(await getCurrentNoteCount()).toBe(1);
await sequencer.click({ position: { x: 200, y: 171 } });
expect(await getCurrentNoteCount()).toBe(2);

// ノートの削除
expect(await getCurrentNoteCount()).toBe(2);
await sequencer.click({ position: { x: 107, y: 171 } });
await page.keyboard.press("Delete");
expect(await getCurrentNoteCount()).toBe(1);
await sequencer.click({ position: { x: 200, y: 171 } });
await page.keyboard.press("Delete");
expect(await getCurrentNoteCount()).toBe(0);
});

test("ダブルクリックで歌詞を編集できる", async ({ page }) => {
await navigateToSong(page);

const sequencer = page.getByLabel("シーケンサ");

const getCurrentNoteLyric = async (note: Locator) =>
await note.getByTestId("note-lyric").textContent();

await sequencer.click({ position: { x: 107, y: 171 } });

const note = sequencer.locator(".note");
const beforeLyric = await getCurrentNoteLyric(note);

await sequencer.click({ position: { x: 107, y: 171 }, clickCount: 2 }); // ダブルクリック

await note.getByRole("textbox").fill("あ");
await page.keyboard.press("Enter");
const afterLyric = await getCurrentNoteLyric(note);
expect(afterLyric).not.toEqual(beforeLyric);
});
Loading