feat: complete in-game message parity
This commit is contained in:
@@ -0,0 +1,384 @@
|
||||
import { expect, test, type Page, type Route } from '@playwright/test';
|
||||
|
||||
import { canonicalFrontendFixture as fixture } from './fixtures/canonical';
|
||||
|
||||
const gamePort = process.env.FRONTEND_PARITY_GAME_PORT ?? '15102';
|
||||
const response = (data: unknown) => ({ result: { data } });
|
||||
const errorResponse = (path: string, message: string) => ({
|
||||
error: {
|
||||
message,
|
||||
code: -32000,
|
||||
data: { code: 'BAD_REQUEST', httpStatus: 400, path },
|
||||
},
|
||||
});
|
||||
|
||||
const operationNames = (route: Route): string[] => {
|
||||
const pathname = new URL(route.request().url()).pathname;
|
||||
return decodeURIComponent(pathname.slice(pathname.lastIndexOf('/trpc/') + 6)).split(',');
|
||||
};
|
||||
|
||||
const general = {
|
||||
id: 1,
|
||||
name: '테스트장수',
|
||||
npcState: 0,
|
||||
nationId: 1,
|
||||
cityId: 1,
|
||||
troopId: 0,
|
||||
picture: 'default.jpg',
|
||||
imageServer: 0,
|
||||
officerLevel: 1,
|
||||
stats: { leadership: 80, strength: 70, intelligence: 90 },
|
||||
gold: 1000,
|
||||
rice: 1000,
|
||||
crew: 500,
|
||||
train: 100,
|
||||
atmos: 100,
|
||||
injury: 0,
|
||||
experience: 1200,
|
||||
dedication: 900,
|
||||
items: { horse: null, weapon: null, book: null, item: null },
|
||||
};
|
||||
|
||||
const generalContext = {
|
||||
general,
|
||||
city: {
|
||||
id: 1,
|
||||
name: '낙양',
|
||||
level: 7,
|
||||
nationId: 1,
|
||||
population: 50000,
|
||||
agriculture: 5000,
|
||||
commerce: 5000,
|
||||
security: 5000,
|
||||
defence: 5000,
|
||||
wall: 5000,
|
||||
supplyState: 1,
|
||||
frontState: 2,
|
||||
},
|
||||
nation: {
|
||||
id: 1,
|
||||
name: '테스트국',
|
||||
color: '#d32f2f',
|
||||
level: 5,
|
||||
gold: 10000,
|
||||
rice: 10000,
|
||||
tech: 1200,
|
||||
typeCode: 'che_군벌',
|
||||
capitalCityId: 1,
|
||||
},
|
||||
settings: {},
|
||||
penalties: {},
|
||||
};
|
||||
|
||||
const target = (generalId: number, generalName: string, nationId: number, nationName: string, color: string) => ({
|
||||
generalId,
|
||||
generalName,
|
||||
nationId,
|
||||
nationName,
|
||||
color,
|
||||
icon: '/image/icons/default.jpg',
|
||||
});
|
||||
|
||||
const ownTarget = target(1, '테스트장수', 1, '테스트국', '#d32f2f');
|
||||
const foreignTarget = target(8, '상대장수', 2, '상대국', '#2457a6');
|
||||
const messageTime = new Date().toISOString().replace('T', ' ').slice(0, 19);
|
||||
|
||||
const buildMessages = (permission: number) => ({
|
||||
result: true,
|
||||
public: [
|
||||
{
|
||||
id: 101,
|
||||
msgType: 'public',
|
||||
src: ownTarget,
|
||||
dest: null,
|
||||
text: '전체 메시지 본문',
|
||||
option: {},
|
||||
time: messageTime,
|
||||
},
|
||||
],
|
||||
national: [
|
||||
{
|
||||
id: 102,
|
||||
msgType: 'national',
|
||||
src: ownTarget,
|
||||
dest: target(0, '', 1, '테스트국', '#d32f2f'),
|
||||
text: '국가 메시지 본문',
|
||||
option: {},
|
||||
time: messageTime,
|
||||
},
|
||||
],
|
||||
private: [
|
||||
{
|
||||
id: 103,
|
||||
msgType: 'private',
|
||||
src: foreignTarget,
|
||||
dest: ownTarget,
|
||||
text: '개인 메시지 본문',
|
||||
option: {},
|
||||
time: messageTime,
|
||||
},
|
||||
],
|
||||
diplomacy: [
|
||||
{
|
||||
id: 104,
|
||||
msgType: 'diplomacy',
|
||||
src: foreignTarget,
|
||||
dest: target(0, '', 1, '테스트국', '#d32f2f'),
|
||||
text: permission >= 3 ? '외교 메시지 본문' : '(외교 메시지입니다)',
|
||||
option:
|
||||
permission >= 3
|
||||
? { action: 'noAggression', deletable: false }
|
||||
: { action: 'noAggression', deletable: false, invalid: true },
|
||||
time: messageTime,
|
||||
},
|
||||
],
|
||||
sequence: 104,
|
||||
nationId: 1,
|
||||
generalName: general.name,
|
||||
permission,
|
||||
canRespondDiplomacy: permission >= 4 && general.officerLevel > 4,
|
||||
latestRead: { private: 0, diplomacy: 0 },
|
||||
});
|
||||
|
||||
const contacts = {
|
||||
nation: [
|
||||
{
|
||||
nationId: 0,
|
||||
mailbox: 9000,
|
||||
name: '재야',
|
||||
color: '#000000',
|
||||
general: [],
|
||||
},
|
||||
{
|
||||
nationId: 1,
|
||||
mailbox: 9001,
|
||||
name: '테스트국',
|
||||
color: '#d32f2f',
|
||||
general: [
|
||||
[1, '테스트장수', 4],
|
||||
[2, '아군군주', 1],
|
||||
],
|
||||
},
|
||||
{
|
||||
nationId: 2,
|
||||
mailbox: 9002,
|
||||
name: '상대국',
|
||||
color: '#2457a6',
|
||||
general: [
|
||||
[8, '상대외교관', 4],
|
||||
[9, '상대일반', 0],
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const installFixture = async (
|
||||
page: Page,
|
||||
options: { permission: number; sendError?: string }
|
||||
): Promise<Array<{ operation: string; body: unknown }>> => {
|
||||
const mutations: Array<{ operation: string; body: unknown }> = [];
|
||||
await page.addInitScript(
|
||||
({ gameToken, profile }) => {
|
||||
window.localStorage.setItem('sammo-game-token', gameToken);
|
||||
window.localStorage.setItem('sammo-game-profile', profile);
|
||||
},
|
||||
{
|
||||
gameToken: fixture.game.session.gameToken,
|
||||
profile: fixture.game.session.profile,
|
||||
}
|
||||
);
|
||||
await page.route('**/image/**', (route) => route.fulfill({ status: 204, body: '' }));
|
||||
await page.route('**/che/api/events**', (route) => route.abort());
|
||||
await page.route('**/che/api/trpc/**', async (route) => {
|
||||
const body = route.request().postDataJSON();
|
||||
const results = operationNames(route).map((operation) => {
|
||||
if (operation === 'lobby.info') {
|
||||
return response({ ...fixture.game.lobby, myGeneral: general });
|
||||
}
|
||||
if (operation === 'general.me') return response(generalContext);
|
||||
if (operation === 'world.getMapLayout') return response(fixture.game.mapLayout);
|
||||
if (operation === 'world.getMap') {
|
||||
return response({ ...fixture.game.map, myCity: 1, myNation: 1 });
|
||||
}
|
||||
if (operation === 'turns.getCommandTable') return response({ general: [], nation: [] });
|
||||
if (operation === 'turns.reserved.getGeneral' || operation === 'turns.reserved.getNation') {
|
||||
return response([]);
|
||||
}
|
||||
if (operation === 'messages.getRecent') return response(buildMessages(options.permission));
|
||||
if (operation === 'messages.getContacts') return response(contacts);
|
||||
if (operation === 'board.getAccess') return response({ canMeeting: true, canSecret: true });
|
||||
if (operation === 'tournament.getState') return response({ stage: 0 });
|
||||
if (
|
||||
operation === 'messages.send' ||
|
||||
operation === 'messages.readLatest' ||
|
||||
operation === 'messages.delete' ||
|
||||
operation === 'messages.respond'
|
||||
) {
|
||||
mutations.push({ operation, body });
|
||||
if (operation === 'messages.send' && options.sendError) {
|
||||
return errorResponse(operation, options.sendError);
|
||||
}
|
||||
return response(operation === 'messages.respond' ? { result: true, reason: 'success' } : { ok: true });
|
||||
}
|
||||
return errorResponse(operation, `Unhandled message fixture operation: ${operation}`);
|
||||
});
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(results),
|
||||
});
|
||||
});
|
||||
return mutations;
|
||||
};
|
||||
|
||||
const openMessages = async (page: Page, viewport: { width: number; height: number }) => {
|
||||
await page.setViewportSize(viewport);
|
||||
await page.goto(`http://127.0.0.1:${gamePort}/che/`);
|
||||
await expect(page.getByRole('heading', { name: '전장 현황' })).toBeVisible();
|
||||
if (viewport.width <= 1024) {
|
||||
await page.getByRole('button', { name: '메시지', exact: true }).click();
|
||||
}
|
||||
await expect(page.locator('.MessagePanel')).toBeVisible();
|
||||
};
|
||||
|
||||
for (const viewport of [
|
||||
{ width: 1000, height: 900 },
|
||||
{ width: 500, height: 900 },
|
||||
]) {
|
||||
test(`matches the reference message computed DOM at ${viewport.width}px Chromium viewport`, async ({ page }) => {
|
||||
await installFixture(page, { permission: 4 });
|
||||
await openMessages(page, viewport);
|
||||
const geometry = await page.locator('.MessagePanel').evaluate((panel) => {
|
||||
const required = (selector: string) => panel.querySelector<HTMLElement>(selector)!;
|
||||
const rect = (element: Element) => {
|
||||
const box = element.getBoundingClientRect();
|
||||
return { x: box.x, y: box.y, width: box.width, height: box.height };
|
||||
};
|
||||
const panelStyle = getComputedStyle(panel);
|
||||
const header = required('.BoardHeader');
|
||||
const plate = required('.msg-plate');
|
||||
const icon = required('.general-icon');
|
||||
return {
|
||||
panel: rect(panel),
|
||||
inputForm: rect(required('.MessageInputForm')),
|
||||
select: rect(required('.message-select')),
|
||||
input: rect(required('.message-text')),
|
||||
submit: rect(required('.message-send')),
|
||||
publicSection: rect(required('.PublicTalk')),
|
||||
nationalSection: rect(required('.NationalTalk')),
|
||||
firstHeader: rect(header),
|
||||
firstPlate: rect(plate),
|
||||
firstIcon: rect(icon),
|
||||
computed: {
|
||||
panelDisplay: panelStyle.display,
|
||||
panelColumns: panelStyle.gridTemplateColumns,
|
||||
panelFontSize: panelStyle.fontSize,
|
||||
headerColor: getComputedStyle(header).color,
|
||||
headerOutlineWidth: getComputedStyle(header).outlineWidth,
|
||||
plateBackgroundColor: getComputedStyle(plate).backgroundColor,
|
||||
plateFontSize: getComputedStyle(plate).fontSize,
|
||||
plateMinHeight: getComputedStyle(plate).minHeight,
|
||||
iconObjectFit: getComputedStyle(icon).objectFit,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
expect(geometry.panel.x).toBeCloseTo(0, 0);
|
||||
expect(geometry.panel.width).toBeCloseTo(viewport.width, 0);
|
||||
expect(geometry.inputForm.width).toBeCloseTo(viewport.width, 0);
|
||||
expect(geometry.select.height).toBeCloseTo(35.5, 0);
|
||||
expect(geometry.submit.height).toBeCloseTo(35.5, 0);
|
||||
expect(geometry.firstHeader.height).toBeCloseTo(25, 0);
|
||||
expect(geometry.firstPlate.height).toBeGreaterThanOrEqual(64);
|
||||
expect(geometry.firstIcon).toMatchObject({ width: 64, height: 64 });
|
||||
expect(geometry.computed).toMatchObject({
|
||||
panelFontSize: '14px',
|
||||
headerColor: 'rgb(255, 255, 255)',
|
||||
headerOutlineWidth: '1px',
|
||||
plateBackgroundColor: 'rgb(20, 28, 101)',
|
||||
plateFontSize: '12.5px',
|
||||
plateMinHeight: '64px',
|
||||
iconObjectFit: 'fill',
|
||||
});
|
||||
|
||||
if (viewport.width === 1000) {
|
||||
expect(geometry.computed.panelDisplay).toBe('grid');
|
||||
expect(geometry.computed.panelColumns).toBe('500px 500px');
|
||||
expect(geometry.select.width).toBeCloseTo(166.66, 0);
|
||||
expect(geometry.input.width).toBeCloseTo(666.66, 0);
|
||||
expect(geometry.submit.width).toBeCloseTo(166.66, 0);
|
||||
expect(geometry.publicSection.width).toBeCloseTo(500, 0);
|
||||
expect(geometry.nationalSection.x).toBeCloseTo(500, 0);
|
||||
} else {
|
||||
expect(geometry.computed.panelDisplay).toBe('block');
|
||||
expect(geometry.select.width).toBeCloseTo(250, 0);
|
||||
expect(geometry.input.width).toBeCloseTo(500, 0);
|
||||
expect(geometry.input.height).toBeCloseTo(33.5, 0);
|
||||
expect(geometry.submit.width).toBeCloseTo(250, 0);
|
||||
}
|
||||
|
||||
const submit = page.locator('.message-send');
|
||||
await submit.hover();
|
||||
expect(
|
||||
await submit.evaluate((element) => ({
|
||||
cursor: getComputedStyle(element).cursor,
|
||||
backgroundColor: getComputedStyle(element).backgroundColor,
|
||||
}))
|
||||
).toEqual({ cursor: 'pointer', backgroundColor: 'rgb(55, 90, 127)' });
|
||||
await submit.focus();
|
||||
expect(
|
||||
await submit.evaluate((element) => ({
|
||||
outlineWidth: getComputedStyle(element).outlineWidth,
|
||||
boxShadow: getComputedStyle(element).boxShadow,
|
||||
}))
|
||||
).toEqual({ outlineWidth: '0px', boxShadow: 'none' });
|
||||
});
|
||||
}
|
||||
|
||||
test('exposes ambassador targets, reply, read, delete, and successful send interactions', async ({ page }) => {
|
||||
const mutations = await installFixture(page, { permission: 4 });
|
||||
await openMessages(page, { width: 500, height: 900 });
|
||||
|
||||
const select = page.getByLabel('메시지 수신 대상');
|
||||
await expect(select.locator('option[value="9002"]')).toHaveCount(1);
|
||||
await expect(select.locator('option[value="8"]')).toBeDisabled();
|
||||
await expect(select.locator('option[value="9"]')).toBeEnabled();
|
||||
|
||||
await page.locator('.PrivateTalk .msg-target').filter({ hasText: '상대장수' }).click();
|
||||
await expect(select).toHaveValue('8');
|
||||
|
||||
await page.locator('.PrivateTalk').getByRole('button', { name: '모두 읽음' }).click();
|
||||
await expect.poll(() => mutations.filter((entry) => entry.operation === 'messages.readLatest').length).toBe(1);
|
||||
|
||||
const deleteButton = page.locator('.PublicTalk .delete-message');
|
||||
page.once('dialog', (dialog) => dialog.accept());
|
||||
await deleteButton.click();
|
||||
await expect.poll(() => mutations.filter((entry) => entry.operation === 'messages.delete').length).toBe(1);
|
||||
|
||||
await select.selectOption('9999');
|
||||
await page.getByLabel('메시지 입력').fill('전송 성공');
|
||||
await page.getByRole('button', { name: '서신전달&갱신' }).click();
|
||||
await expect(page.getByLabel('메시지 입력')).toHaveValue('');
|
||||
await expect.poll(() => mutations.filter((entry) => entry.operation === 'messages.send').length).toBe(1);
|
||||
});
|
||||
|
||||
test('redacts diplomacy for a low-permission general and preserves the failed-send error flow', async ({ page }) => {
|
||||
const mutations = await installFixture(page, {
|
||||
permission: 2,
|
||||
sendError: '공개 메세지를 보낼 수 없습니다.',
|
||||
});
|
||||
await openMessages(page, { width: 500, height: 900 });
|
||||
|
||||
const select = page.getByLabel('메시지 수신 대상');
|
||||
await expect(select.locator('option[value="9002"]')).toHaveCount(0);
|
||||
await expect(page.locator('.DiplomacyTalk')).toContainText('삭제된 메시지입니다');
|
||||
await expect(page.locator('.DiplomacyTalk')).not.toContainText('외교 메시지 본문');
|
||||
await expect(page.locator('.DiplomacyTalk .message-response button').first()).toBeDisabled();
|
||||
|
||||
await select.selectOption('9999');
|
||||
await page.getByLabel('메시지 입력').fill('차단될 메시지');
|
||||
await page.getByRole('button', { name: '서신전달&갱신' }).click();
|
||||
await expect(page.getByLabel('메시지 입력')).toHaveValue('');
|
||||
await expect(page.locator('.error')).toHaveText('공개 메세지를 보낼 수 없습니다.');
|
||||
await expect.poll(() => mutations.filter((entry) => entry.operation === 'messages.send').length).toBe(1);
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import { resolve } from 'node:path';
|
||||
import { canonicalFrontendFixture as fixture } from './fixtures/canonical';
|
||||
|
||||
const artifactRoot = process.env.FRONTEND_PARITY_ARTIFACT_DIR;
|
||||
const gamePort = process.env.FRONTEND_PARITY_GAME_PORT ?? '15102';
|
||||
const response = (data: unknown) => ({ result: { data } });
|
||||
|
||||
const operationNames = (route: Route): string[] => {
|
||||
@@ -90,6 +91,7 @@ const messageBundle = (visible: boolean, canRespondDiplomacy = true) => ({
|
||||
sequence: visible ? diplomacyMessage.id : -1,
|
||||
nationId: 1,
|
||||
generalName: general.name,
|
||||
permission: canRespondDiplomacy ? 4 : 2,
|
||||
canRespondDiplomacy,
|
||||
latestRead: { diplomacy: 0, private: 0 },
|
||||
});
|
||||
@@ -131,6 +133,9 @@ const installFixture = async (
|
||||
if (operation === 'messages.getRecent') {
|
||||
return response(messageBundle(visible, options.canRespondDiplomacy));
|
||||
}
|
||||
if (operation === 'messages.getContacts') return response({ nation: [] });
|
||||
if (operation === 'board.getAccess') return response({ canMeeting: true, canSecret: true });
|
||||
if (operation === 'tournament.getState') return response({ stage: 0 });
|
||||
if (operation === 'messages.respond') {
|
||||
mutations.push({ operation, body: requestBody });
|
||||
if (options.acceptResponse) {
|
||||
@@ -151,9 +156,9 @@ const installFixture = async (
|
||||
};
|
||||
|
||||
const openDiplomacyTab = async (page: Page) => {
|
||||
await page.goto('http://127.0.0.1:15102/che/');
|
||||
await page.goto(`http://127.0.0.1:${gamePort}/che/`);
|
||||
await expect(page.getByRole('heading', { name: '전장 현황' })).toBeVisible();
|
||||
await page.getByRole('button', { name: '외교', exact: true }).last().click();
|
||||
await expect(page.locator('.DiplomacyTalk')).toBeVisible();
|
||||
await expect(page.getByText(diplomacyMessage.text)).toBeVisible();
|
||||
};
|
||||
|
||||
@@ -186,20 +191,20 @@ test.describe('instant diplomacy response UI', () => {
|
||||
});
|
||||
|
||||
expect(geometry.buttons).toHaveLength(2);
|
||||
expect(geometry.buttons[1]!.x - (geometry.buttons[0]!.x + geometry.buttons[0]!.width)).toBeCloseTo(4, 0);
|
||||
expect(geometry.buttons[1]!.x - (geometry.buttons[0]!.x + geometry.buttons[0]!.width)).toBeCloseTo(0, 0);
|
||||
expect(geometry.buttons[0]).toMatchObject({
|
||||
color: 'rgb(143, 209, 143)',
|
||||
fontSize: '11.2px',
|
||||
color: 'rgb(255, 255, 255)',
|
||||
fontSize: '12.5px',
|
||||
borderWidth: '1px',
|
||||
cursor: 'pointer',
|
||||
});
|
||||
expect(geometry.buttons[1]).toMatchObject({
|
||||
color: 'rgb(224, 154, 154)',
|
||||
fontSize: '11.2px',
|
||||
color: 'rgb(255, 255, 255)',
|
||||
fontSize: '12.5px',
|
||||
borderWidth: '1px',
|
||||
cursor: 'pointer',
|
||||
});
|
||||
expect(geometry.buttons.every((button) => button.height >= 22 && button.height <= 26)).toBe(true);
|
||||
expect(geometry.buttons.every((button) => button.height >= 20 && button.height <= 22)).toBe(true);
|
||||
|
||||
await decline.hover();
|
||||
expect(await decline.evaluate((element) => getComputedStyle(element).cursor)).toBe('pointer');
|
||||
@@ -234,18 +239,17 @@ test.describe('instant diplomacy response UI', () => {
|
||||
test('keeps the message and exposes a rejected response on mobile Chromium', async ({ page }) => {
|
||||
const mutations = await installFixture(page, { acceptResponse: false });
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await page.goto('http://127.0.0.1:15102/che/');
|
||||
await page.goto(`http://127.0.0.1:${gamePort}/che/`);
|
||||
await expect(page.getByRole('heading', { name: '전장 현황' })).toBeVisible();
|
||||
await page.getByRole('button', { name: '메시지', exact: true }).click();
|
||||
await page.getByRole('button', { name: '외교', exact: true }).click();
|
||||
|
||||
const responseRow = page.locator('.message-response');
|
||||
await expect(responseRow).toBeVisible();
|
||||
const itemWidth = await page
|
||||
.locator('.message-item')
|
||||
.locator('.DiplomacyTalk .msg-plate')
|
||||
.evaluate((element) => element.getBoundingClientRect().width);
|
||||
expect(itemWidth).toBeGreaterThan(320);
|
||||
expect(itemWidth).toBeLessThanOrEqual(342);
|
||||
expect(itemWidth).toBeGreaterThanOrEqual(389);
|
||||
expect(itemWidth).toBeLessThanOrEqual(390);
|
||||
|
||||
page.once('dialog', async (dialog) => {
|
||||
expect(dialog.message()).toBe('거절하시겠습니까?');
|
||||
@@ -272,10 +276,9 @@ test.describe('instant diplomacy response UI', () => {
|
||||
canRespondDiplomacy: false,
|
||||
});
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await page.goto('http://127.0.0.1:15102/che/');
|
||||
await page.goto(`http://127.0.0.1:${gamePort}/che/`);
|
||||
await expect(page.getByRole('heading', { name: '전장 현황' })).toBeVisible();
|
||||
await page.getByRole('button', { name: '메시지', exact: true }).click();
|
||||
await page.getByRole('button', { name: '외교', exact: true }).click();
|
||||
|
||||
const accept = page.locator('.message-response').getByRole('button', { name: '수락' });
|
||||
await expect(accept).toBeDisabled();
|
||||
@@ -284,7 +287,7 @@ test.describe('instant diplomacy response UI', () => {
|
||||
const style = getComputedStyle(element);
|
||||
return { cursor: style.cursor, opacity: style.opacity };
|
||||
})
|
||||
).toEqual({ cursor: 'not-allowed', opacity: '0.5' });
|
||||
).toEqual({ cursor: 'not-allowed', opacity: '0.65' });
|
||||
await accept.click({ force: true });
|
||||
expect(mutations).toHaveLength(0);
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ export default defineConfig({
|
||||
'visual-parity.spec.ts',
|
||||
'public-gaps.spec.ts',
|
||||
'instant-diplomacy-message.spec.ts',
|
||||
'ingame-message-parity.spec.ts',
|
||||
'tournament-betting.spec.ts',
|
||||
],
|
||||
fullyParallel: false,
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { mkdir, readFile } from 'node:fs/promises';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
|
||||
import { chromium } from '@playwright/test';
|
||||
|
||||
const baseUrl = process.env.REF_MESSAGE_URL ?? 'http://127.0.0.1:3400/sam/';
|
||||
const username = process.env.REF_MESSAGE_USER ?? 'refuser1';
|
||||
const passwordFile = process.env.REF_MESSAGE_PASSWORD_FILE;
|
||||
const artifactRoot = process.env.REF_MESSAGE_ARTIFACT_DIR;
|
||||
|
||||
if (!passwordFile) {
|
||||
throw new Error('REF_MESSAGE_PASSWORD_FILE is required.');
|
||||
}
|
||||
|
||||
const password = (await readFile(passwordFile, 'utf8')).trim();
|
||||
|
||||
const login = async (context, page) => {
|
||||
await page.goto(baseUrl, { waitUntil: 'networkidle', timeout: 60_000 });
|
||||
const globalSalt = await page.locator('#global_salt').inputValue();
|
||||
const passwordHash = createHash('sha512')
|
||||
.update(globalSalt + password + globalSalt)
|
||||
.digest('hex');
|
||||
const response = await context.request.post(new URL('api.php?path=Login/LoginByID', baseUrl).toString(), {
|
||||
data: { username, password: passwordHash },
|
||||
});
|
||||
const result = await response.json();
|
||||
if (!response.ok() || result.result !== true) {
|
||||
throw new Error('Reference login failed.');
|
||||
}
|
||||
};
|
||||
|
||||
const ensureGeneral = async (page) => {
|
||||
await page.goto(new URL('hwe/index.php', baseUrl).toString(), {
|
||||
waitUntil: 'networkidle',
|
||||
timeout: 60_000,
|
||||
});
|
||||
if (await page.locator('.MessagePanel').isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
await page.goto(new URL('hwe/v_join.php', baseUrl).toString(), {
|
||||
waitUntil: 'networkidle',
|
||||
timeout: 60_000,
|
||||
});
|
||||
const create = page.getByRole('button', { name: '장수 생성', exact: true });
|
||||
await create.waitFor({ state: 'visible', timeout: 30_000 });
|
||||
page.once('dialog', (dialog) => dialog.accept());
|
||||
await create.click();
|
||||
await page.locator('.MessagePanel').waitFor({ state: 'visible', timeout: 60_000 });
|
||||
};
|
||||
|
||||
const measure = async (browser, name, viewport) => {
|
||||
const context = await browser.newContext({
|
||||
viewport,
|
||||
deviceScaleFactor: 1,
|
||||
colorScheme: 'dark',
|
||||
locale: 'ko-KR',
|
||||
timezoneId: 'UTC',
|
||||
ignoreHTTPSErrors: true,
|
||||
});
|
||||
try {
|
||||
const page = await context.newPage();
|
||||
await login(context, page);
|
||||
await ensureGeneral(page);
|
||||
await page.locator('.MessagePanel').waitFor({ state: 'visible', timeout: 30_000 });
|
||||
await page.locator('.BoardHeader').first().waitFor({ state: 'visible' });
|
||||
const marker = `computed-dom-${name}-${Date.now()}`;
|
||||
await page.locator('.MessageInputForm select').selectOption('9999');
|
||||
await page.locator('.MessageInputForm input').fill(marker);
|
||||
await page.getByRole('button', { name: '서신전달&갱신' }).click();
|
||||
await page.getByText(marker, { exact: true }).waitFor({ state: 'visible', timeout: 30_000 });
|
||||
|
||||
if (artifactRoot) {
|
||||
const path = resolve(artifactRoot, `message-ref-${name}.png`);
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await page.locator('.MessagePanel').screenshot({
|
||||
path,
|
||||
animations: 'disabled',
|
||||
});
|
||||
}
|
||||
|
||||
const result = await page.evaluate(() => {
|
||||
const rect = (element) => {
|
||||
const box = element.getBoundingClientRect();
|
||||
return {
|
||||
x: box.x,
|
||||
y: box.y,
|
||||
width: box.width,
|
||||
height: box.height,
|
||||
};
|
||||
};
|
||||
const required = (selector) => {
|
||||
const element = document.querySelector(selector);
|
||||
if (!element) throw new Error(`Missing reference selector: ${selector}`);
|
||||
return element;
|
||||
};
|
||||
const optionalRect = (selector) => {
|
||||
const element = document.querySelector(selector);
|
||||
return element ? rect(element) : null;
|
||||
};
|
||||
const style = (selector) => getComputedStyle(required(selector));
|
||||
const input = required('.MessageInputForm input');
|
||||
const select = required('.MessageInputForm select');
|
||||
const submit = required('#msg_submit-col button');
|
||||
const firstPlate = document.querySelector('.msg_plate');
|
||||
const firstIcon = document.querySelector('.msg_plate .generalIcon');
|
||||
const panelStyle = style('.MessagePanel');
|
||||
const headerStyle = style('.BoardHeader');
|
||||
const plateStyle = firstPlate ? getComputedStyle(firstPlate) : null;
|
||||
const iconStyle = firstIcon ? getComputedStyle(firstIcon) : null;
|
||||
return {
|
||||
panel: rect(required('.MessagePanel')),
|
||||
inputForm: rect(required('.MessageInputForm')),
|
||||
select: rect(select),
|
||||
input: rect(input),
|
||||
submit: rect(submit),
|
||||
publicSection: rect(required('.PublicTalk')),
|
||||
nationalSection: rect(required('.NationalTalk')),
|
||||
privateSection: rect(required('.PrivateTalk')),
|
||||
diplomacySection: rect(required('.DiplomacyTalk')),
|
||||
firstHeader: rect(required('.BoardHeader')),
|
||||
firstPlate: optionalRect('.msg_plate'),
|
||||
firstIcon: optionalRect('.msg_plate .generalIcon'),
|
||||
computed: {
|
||||
panelDisplay: panelStyle.display,
|
||||
panelColumns: panelStyle.gridTemplateColumns,
|
||||
panelFontSize: panelStyle.fontSize,
|
||||
headerColor: headerStyle.color,
|
||||
headerOutlineWidth: headerStyle.outlineWidth,
|
||||
headerBackgroundImage: headerStyle.backgroundImage,
|
||||
plateBackgroundColor: plateStyle?.backgroundColor ?? null,
|
||||
plateFontSize: plateStyle?.fontSize ?? null,
|
||||
plateMinHeight: plateStyle?.minHeight ?? null,
|
||||
iconObjectFit: iconStyle?.objectFit ?? null,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const submit = page.locator('#msg_submit-col button');
|
||||
await submit.hover();
|
||||
const hover = await submit.evaluate((element) => {
|
||||
const style = getComputedStyle(element);
|
||||
return {
|
||||
cursor: style.cursor,
|
||||
backgroundColor: style.backgroundColor,
|
||||
};
|
||||
});
|
||||
await submit.focus();
|
||||
const focus = await submit.evaluate((element) => {
|
||||
const style = getComputedStyle(element);
|
||||
return {
|
||||
outline: style.outline,
|
||||
boxShadow: style.boxShadow,
|
||||
};
|
||||
});
|
||||
const markerPlate = page.locator('.msg_plate').filter({ hasText: marker });
|
||||
const deleteButton = markerPlate.locator('.btn-delete-msg');
|
||||
if (await deleteButton.isVisible()) {
|
||||
page.once('dialog', (dialog) => dialog.accept());
|
||||
await deleteButton.click();
|
||||
}
|
||||
return { ...result, interaction: { hover, focus } };
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
};
|
||||
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
try {
|
||||
const measurements = {
|
||||
desktop: await measure(browser, 'desktop', { width: 1000, height: 900 }),
|
||||
mobile: await measure(browser, 'mobile', { width: 500, height: 900 }),
|
||||
};
|
||||
process.stdout.write(`${JSON.stringify(measurements, null, 2)}\n`);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
Reference in New Issue
Block a user