퀴즈 파일 A단계: 관리자 → 퀴즈 '파일로 만들기'(.xlsx·.csv를 브라우저가 라이브러리 없이 읽음, 열 이름으로 링크·정답·설명·힌트·순번 인식, 시트 선택, 잘못된 링크·중복 영상 표시), 편집 화면 '파일에서 가져오기'(뒤에 추가·목록 바꾸기)·'엑셀로 내보내기'·빈 양식. 파일 곡은 적힌 값 그대로(DB 연결·검토 대기 없음). 곡별 힌트를 하나씩 보여 준 뒤 초성 힌트(자동은 N초마다, 투표는 한 번에 하나)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* 관리자 → 퀴즈 editor in a real browser:
|
||||
* - a DB song added from the search shows (and, with 자동 off, keeps) the DB highlight, not the 30% guess
|
||||
* - an edit made while 저장 is on its way stays and stays unsaved
|
||||
* - 파일로 만들기 from an Excel-style (deflated) .xlsx, 엑셀로 내보내기 reads back, 파일에서 가져오기 a CP949 .csv
|
||||
* Run: bun run build && bun e2e/quiz.e2e.ts (needs /usr/bin/google-chrome)
|
||||
*/
|
||||
import { chromium, type Browser, type BrowserContext } from 'playwright-core';
|
||||
@@ -10,6 +11,8 @@ import { join } from 'node:path';
|
||||
import { loadConfig } from '../apps/server/src/config';
|
||||
import { startServer } from '../apps/server/src/server';
|
||||
import { Catalog } from '../apps/server/src/collector/catalog';
|
||||
import { readXlsx } from '../packages/shared/src/sheet';
|
||||
import { deflatedZip } from '../packages/shared/src/zip-fixture';
|
||||
|
||||
const PORT = Number(process.env.E2E_PORT ?? 4627);
|
||||
const ORIGIN = `http://localhost:${PORT}`;
|
||||
@@ -113,6 +116,70 @@ try {
|
||||
await p.getByText('저장됨').waitFor();
|
||||
expect(db.query<{ name: string }, []>('SELECT name FROM custom_quizzes').get()!.name === '이름 2', '두 번째 저장');
|
||||
});
|
||||
await step('파일로 만들기: 엑셀(.xlsx) → 순번 순서·힌트, 빠지는 줄 표시 → 만들기; 내보내기가 같은 곡으로 읽힘; CSV(CP949) 뒤에 추가', async () => {
|
||||
const cell = (ref: string, v: string) => `<c r="${ref}" t="inlineStr"><is><t>${v}</t></is></c>`;
|
||||
const head = ['번호', '유튜브 영상 링크', '게임 제목(한글)', '노래 제목', '힌트(게임장르)', '재생목록 순번'];
|
||||
const data = [
|
||||
['1', 'https://youtu.be/iIIjS6yDMQo', '감옥탈출(구토할배)', '트레일러', '방탈출(플래시)', '3'],
|
||||
['2', 'https://youtu.be/x0-xFqvJ-U8', '갓 오브 워 2', 'The End Begins', '액션', '1'],
|
||||
['3', 'https://example.com/x', '잘못된 링크', '', '', '4'],
|
||||
['4', 'https://youtu.be/x0-xFqvJ-U8', '같은 영상', '', '', '5'],
|
||||
['5', 'https://youtu.be/Yz-Af4p_Vv8', '건파이어 리본', 'Desert Theme', '확인필요', '2'],
|
||||
];
|
||||
const sheetXml = `<worksheet><sheetData>${[head, ...data].map((r, i) => `<row r="${i + 1}">${r.map((v, k) => cell(`${'ABCDEF'[k]}${i + 1}`, v)).join('')}</row>`).join('')}</sheetData></worksheet>`;
|
||||
const xlsx = deflatedZip({
|
||||
'xl/workbook.xml': '<workbook xmlns:r="r"><sheets><sheet name="게임별 정렬" sheetId="1" r:id="rId1"/><sheet name="메모" sheetId="2" r:id="rId2"/></sheets></workbook>',
|
||||
'xl/_rels/workbook.xml.rels': '<Relationships><Relationship Id="rId1" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Target="worksheets/sheet2.xml"/></Relationships>',
|
||||
'xl/worksheets/sheet1.xml': sheetXml,
|
||||
'xl/worksheets/sheet2.xml': `<worksheet><sheetData><row r="1">${cell('A1', '메모')}</row></sheetData></worksheet>`,
|
||||
});
|
||||
await p.goto(`${ORIGIN}/admin/quizzes`);
|
||||
await p.getByRole('button', { name: /파일로 만들기/ }).click();
|
||||
await p.getByLabel('퀴즈 파일').setInputFiles({ name: '게임 BGM.xlsx', mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', buffer: Buffer.from(xlsx) });
|
||||
await p.getByText('빠지는 줄 2개').waitFor();
|
||||
expect((await p.getByLabel('시트').inputValue()) === '0', '곡이 있는 시트를 먼저 고르지 않음');
|
||||
expect((await p.getByLabel('퀴즈 이름').inputValue()) === '게임 BGM', '이름이 파일 이름이 아님');
|
||||
await p.screenshot({ path: join(SHOTS, 'quiz-file-preview.png'), fullPage: true });
|
||||
await p.getByRole('button', { name: '3곡으로 만들기' }).click();
|
||||
await p.waitForURL(/\/admin\/quizzes\/\d+$/);
|
||||
await p.locator('.quiz-songs tbody tr').nth(2).waitFor();
|
||||
const quizId = Number(new URL(p.url()).pathname.split('/').pop());
|
||||
const rows = db
|
||||
.query<{ title: string; artist: string; hints: string; from_file: number; song_id: number | null }, [number]>('SELECT title, artist, hints, from_file, song_id FROM custom_quiz_items WHERE quiz_id = ? ORDER BY pos')
|
||||
.all(quizId);
|
||||
expect(
|
||||
JSON.stringify(rows) ===
|
||||
JSON.stringify([
|
||||
{ title: '갓 오브 워 2', artist: 'The End Begins', hints: '["액션"]', from_file: 1, song_id: null },
|
||||
{ title: '건파이어 리본', artist: 'Desert Theme', hints: '["확인필요"]', from_file: 1, song_id: null },
|
||||
{ title: '감옥탈출(구토할배)', artist: '트레일러', hints: '["방탈출(플래시)"]', from_file: 1, song_id: null },
|
||||
]),
|
||||
`저장된 곡: ${JSON.stringify(rows)}`,
|
||||
);
|
||||
expect(JSON.parse(db.query<{ s: string }, [number]>('SELECT settings_json s FROM custom_quizzes WHERE id = ?').get(quizId)!.s).hint === 'manual', '힌트가 투표로 켜지지 않음');
|
||||
await p.screenshot({ path: join(SHOTS, 'quiz-file-editor.png'), fullPage: true });
|
||||
// 엑셀로 내보내기 → the same songs come back
|
||||
const [dl] = await Promise.all([p.waitForEvent('download'), p.getByRole('button', { name: /엑셀로 내보내기/ }).click()]);
|
||||
expect(dl.suggestedFilename() === '게임 BGM.xlsx', `내보낸 파일 이름: ${dl.suggestedFilename()}`);
|
||||
const back = (await readXlsx(new Uint8Array(await Bun.file((await dl.path())!).arrayBuffer())))[0]!.rows;
|
||||
expect(back.length === 4 && back[1]![2] === '갓 오브 워 2' && back[1]![4] === '액션' && back[3]![1] === 'https://youtu.be/iIIjS6yDMQo', `내보낸 내용: ${JSON.stringify(back.slice(0, 2))}`);
|
||||
// 파일에서 가져오기: a Korean Excel CSV (CP949), one new song and one already in the list
|
||||
const csv = new Uint8Array([
|
||||
...new TextEncoder().encode('link,'),
|
||||
0xc1, 0xa4, 0xb4, 0xe4, // 정답
|
||||
...new TextEncoder().encode('\nhttps://youtu.be/9hzKkTpXDwM,'),
|
||||
0xb0, 0xd9, 0xbe, 0xda, 0xc7, 0xc1, 0xb5, 0xe5, // 겟앰프드
|
||||
...new TextEncoder().encode('\nhttps://youtu.be/iIIjS6yDMQo,x\n'),
|
||||
]);
|
||||
await p.getByRole('button', { name: '📄 파일' }).click();
|
||||
await p.getByLabel('퀴즈 파일').setInputFiles({ name: 'more.csv', mimeType: 'text/csv', buffer: Buffer.from(csv) });
|
||||
await p.getByText('이미 목록에 있는 영상 1곡').waitFor();
|
||||
await p.getByRole('button', { name: '1곡 목록 뒤에 추가' }).click();
|
||||
await p.locator('.quiz-songs tbody tr', { hasText: '겟앰프드' }).waitFor();
|
||||
await p.keyboard.press('Control+s');
|
||||
await p.getByText('저장됨').waitFor();
|
||||
expect(db.query<{ n: number }, [number]>('SELECT COUNT(*) n FROM custom_quiz_items WHERE quiz_id = ?').get(quizId)!.n === 4, '가져온 곡 저장');
|
||||
});
|
||||
expect(errors.length === 0, `페이지 오류: ${errors.join(' | ')}`);
|
||||
} catch (e) {
|
||||
console.log(e instanceof Error ? e.message.slice(0, 400) : e);
|
||||
|
||||
Reference in New Issue
Block a user