mirror of
https://github.com/bitbaum/biaslens.git
synced 2026-12-04 17:57:49 +01:00
* Group navigation by task with SiteKit 0.7 * Record navigation acceptance and remaining work
291 lines
12 KiB
JavaScript
291 lines
12 KiB
JavaScript
import assert from 'node:assert/strict';
|
||
import { chromium } from 'playwright';
|
||
|
||
const base = process.env.BROWSER_SMOKE_URL ?? 'http://127.0.0.1:3000';
|
||
const browser = await chromium.launch({
|
||
executablePath: process.env.BROWSER_EXECUTABLE ?? '/usr/bin/chromium',
|
||
args: ['--no-sandbox'],
|
||
});
|
||
try {
|
||
const page = await browser.newPage();
|
||
const errors = [];
|
||
page.on('pageerror', (error) => errors.push(error.message));
|
||
for (const width of [320, 390, 834, 1440]) {
|
||
await page.setViewportSize({ width, height: 900 });
|
||
await page.goto(base + '/analyze', { waitUntil: 'networkidle' });
|
||
await page.getByRole('heading', { name: 'Examine text.' }).waitFor();
|
||
if (width > 380) await page.getByRole('link', { name: 'Sign in', exact: true }).waitFor();
|
||
assert.equal(
|
||
await page.evaluate(() => document.documentElement.scrollWidth > innerWidth),
|
||
false,
|
||
'viewport overflow at ' + width,
|
||
);
|
||
const titleStyle = await page.locator('h1').evaluate((el) => ({
|
||
font: getComputedStyle(el).fontFamily,
|
||
size: parseFloat(getComputedStyle(el).fontSize),
|
||
weight: parseInt(getComputedStyle(el).fontWeight),
|
||
}));
|
||
assert.match(titleStyle.font, /Inter/);
|
||
assert.ok(
|
||
titleStyle.size >= 30 && titleStyle.size <= 44,
|
||
'application title scale at ' + width,
|
||
);
|
||
assert.ok(titleStyle.weight >= 600, 'application title weight');
|
||
const headerHeight = (await page.locator('.sk-masthead').boundingBox()).height;
|
||
assert.ok(headerHeight >= 64 && headerHeight <= 70, 'compact shared header at ' + width);
|
||
assert.equal(await page.locator('.sk-footer-group').count(), 3);
|
||
{
|
||
const menu = page.locator('[data-sitekit-menu]');
|
||
const summary = menu.locator('summary');
|
||
await summary.focus();
|
||
await page.keyboard.press('Enter');
|
||
assert.equal(await menu.evaluate((el) => el.open), true);
|
||
const links = menu.locator('.sk-nav-group a');
|
||
assert.equal(await links.count(), 8);
|
||
const panel = await menu.locator('nav').boundingBox();
|
||
assert.ok(panel.x >= 0 && panel.x + panel.width <= width, 'grouped menu fits ' + width);
|
||
if (width <= 380) {
|
||
const signIn = menu.getByRole('link', { name: 'Sign in', exact: true });
|
||
assert.ok((await signIn.boundingBox()).height >= 44);
|
||
}
|
||
for (const link of await links.all()) assert.ok((await link.boundingBox()).height >= 44);
|
||
await links.first().focus();
|
||
await page.keyboard.press('Escape');
|
||
assert.equal(await menu.evaluate((el) => el.open), false);
|
||
assert.equal(await summary.evaluate((el) => el === document.activeElement), true);
|
||
await summary.click();
|
||
await page.mouse.click(4, 850);
|
||
assert.equal(await menu.evaluate((el) => el.open), false);
|
||
await summary.click();
|
||
await menu.locator('a[href="/desk"]').click();
|
||
await page.waitForURL('**/desk');
|
||
assert.equal(await menu.evaluate((el) => el.open), false);
|
||
await summary.click();
|
||
assert.equal(await menu.locator('a[href="/desk"]').getAttribute('aria-current'), 'page');
|
||
await page.screenshot({
|
||
path:
|
||
(process.env.BROWSER_SMOKE_DIR ?? 'browser-smoke-artifacts') +
|
||
'/grouped-menu-' +
|
||
width +
|
||
'.png',
|
||
});
|
||
}
|
||
}
|
||
for (const path of [
|
||
'/workspace',
|
||
'/roadmap',
|
||
'/changelog',
|
||
'/blog',
|
||
'/sign-in',
|
||
'/not-a-real-page',
|
||
]) {
|
||
await page.goto(base + path);
|
||
assert.equal(await page.locator('.sk-masthead').count(), 1);
|
||
assert.equal(await page.locator('.sk-footer').count(), 1);
|
||
assert.equal(await page.locator('#main-content').count(), 1);
|
||
}
|
||
await page.goto(base + '/');
|
||
await page.getByRole('button', { name: 'Finance', exact: true }).click();
|
||
await page
|
||
.getByText('Is a record profit the same as a stronger business?', { exact: true })
|
||
.waitFor();
|
||
assert.equal(
|
||
await page.getByRole('button', { name: 'Finance', exact: true }).getAttribute('aria-pressed'),
|
||
'true',
|
||
);
|
||
await page.evaluate(() =>
|
||
localStorage.setItem(
|
||
'biaslens:inquiry:v1',
|
||
JSON.stringify({
|
||
version: 1,
|
||
question: 'What explains this financial result?',
|
||
scope: '',
|
||
notes: '',
|
||
challenge: '',
|
||
sources: [],
|
||
}),
|
||
),
|
||
);
|
||
await page.goto(base + '/workspace', { waitUntil: 'networkidle' });
|
||
await page
|
||
.getByRole('heading', { name: 'What explains this financial result?', exact: true })
|
||
.waitFor();
|
||
await page.getByRole('link', { name: 'Continue investigating →', exact: true }).click();
|
||
await page.waitForURL('**/explore');
|
||
// The notebook shows a saved question as text, editable with one tap.
|
||
await page
|
||
.getByRole('button', { name: 'Edit question', exact: true })
|
||
.getByText('What explains this financial result?')
|
||
.waitFor();
|
||
|
||
// Speaking or typing one sentence fills the notebook; a link is a source.
|
||
await page.evaluate(() => localStorage.removeItem('biaslens:inquiry:v1'));
|
||
await page.route('**/api/ai/form-assist', (route) =>
|
||
route.fulfill({
|
||
json: {
|
||
ok: true,
|
||
values: {
|
||
question: 'Why did electricity prices rise in 2022?',
|
||
scope: 'Switzerland, 2021–2023, household tariffs',
|
||
notes:
|
||
'- Gas prices fed through to power prices\n- Grid fees rose\n- Tariffs lag the market',
|
||
challenge: 'Tariff data by canton would settle how much was the market.',
|
||
},
|
||
changed: ['question', 'scope', 'notes', 'challenge'],
|
||
message: 'Filled in.',
|
||
},
|
||
}),
|
||
);
|
||
await page.route('**/api/source-preview**', (route) =>
|
||
route.fulfill({ json: { ok: true, title: 'Electricity tariffs 2023', publication: 'ElCom' } }),
|
||
);
|
||
await page.goto(base + '/explore', { waitUntil: 'networkidle' });
|
||
const box = page.getByRole('textbox', { name: 'Your research question' });
|
||
await box.fill('why did my power bill go up');
|
||
await box.press('Enter');
|
||
await page.getByText('Gas prices fed through to power prices', { exact: true }).waitFor();
|
||
await page.getByRole('button', { name: 'Remove: Grid fees rose', exact: true }).click();
|
||
assert.equal(await page.getByText('Grid fees rose', { exact: true }).count(), 0);
|
||
await page
|
||
.getByRole('textbox', { name: 'Paste a link to a source' })
|
||
.fill('https://www.elcom.admin.ch/tarife');
|
||
await page.getByRole('button', { name: 'Add', exact: true }).click();
|
||
await page.getByRole('link', { name: 'Electricity tariffs 2023 — ElCom' }).waitFor();
|
||
await page.getByRole('button', { name: 'Challenges', exact: true }).click();
|
||
const saved = await page.evaluate(() => JSON.parse(localStorage.getItem('biaslens:inquiry:v1')));
|
||
assert.equal(saved.sources[0].stance, 'contradicts');
|
||
assert.equal(saved.notes, '- Gas prices fed through to power prices\n- Tariffs lag the market');
|
||
await page.unroute('**/api/ai/form-assist');
|
||
await page.unroute('**/api/source-preview**');
|
||
await page.goto(base + '/sign-in', { waitUntil: 'networkidle' });
|
||
assert.equal(
|
||
await page.locator('.sk-masthead').getByRole('link', { name: 'Sign in', exact: true }).count(),
|
||
0,
|
||
'auth screens do not repeat the sign-in navigation action',
|
||
);
|
||
await page.getByLabel('Email', { exact: true }).waitFor();
|
||
await page.getByLabel('Password', { exact: true }).waitFor();
|
||
assert.equal((await page.locator('.account-card .acct-auth-button').count()) > 0, true);
|
||
const authColors = await page
|
||
.locator('.account-card .acct-auth-button')
|
||
.first()
|
||
.evaluate((el) => ({
|
||
action: getComputedStyle(el).backgroundColor,
|
||
ink: getComputedStyle(document.body).color,
|
||
}));
|
||
assert.equal(
|
||
authColors.action,
|
||
authColors.ink,
|
||
'auth action uses the product ink role, not a package default accent',
|
||
);
|
||
await page
|
||
.getByText('Your current notebook is saved in this browser', { exact: false })
|
||
.waitFor();
|
||
await page.goto(base + '/');
|
||
await page.evaluate(() => document.fonts.ready);
|
||
assert.equal(await page.evaluate(() => document.fonts.check('16px Inter')), true);
|
||
assert.match(await page.locator('h1').evaluate((el) => getComputedStyle(el).fontFamily), /Inter/);
|
||
assert.deepEqual(errors, []);
|
||
const signedIn = await browser.newContext({ viewport: { width: 390, height: 844 } });
|
||
await signedIn.route('**/api/auth/get-session**', (route) =>
|
||
route.fulfill({
|
||
json: {
|
||
user: {
|
||
id: 'browser-fixture',
|
||
name: 'Test Researcher',
|
||
email: 'researcher@example.test',
|
||
emailVerified: true,
|
||
createdAt: new Date().toISOString(),
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
session: {
|
||
id: 'browser-session',
|
||
token: 'test-only',
|
||
userId: 'browser-fixture',
|
||
expiresAt: new Date(Date.now() + 3600000).toISOString(),
|
||
createdAt: new Date().toISOString(),
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
},
|
||
}),
|
||
);
|
||
const accountPage = await signedIn.newPage();
|
||
for (const width of [320, 390, 834, 1440]) {
|
||
await accountPage.setViewportSize({ width, height: 900 });
|
||
await accountPage.goto(base + '/workspace', { waitUntil: 'networkidle' });
|
||
if (width <= 380) await accountPage.locator('[data-sitekit-menu] summary').click();
|
||
const accountTrigger = accountPage
|
||
.locator(width <= 380 ? '.sk-grouped-actions' : '.sk-account-actions')
|
||
.getByRole('button', { name: 'Account: Test Researcher', exact: true, includeHidden: true });
|
||
await accountTrigger.click();
|
||
assert.equal(
|
||
await accountPage
|
||
.getByRole('menuitem', { name: 'Profile & security', exact: true })
|
||
.getAttribute('href'),
|
||
'/account',
|
||
);
|
||
assert.equal(
|
||
await accountPage
|
||
.getByRole('menuitem', { name: 'Your notebook', exact: true })
|
||
.getAttribute('href'),
|
||
'/explore',
|
||
);
|
||
await accountPage
|
||
.getByRole('menuitem', { name: 'Profile & security', exact: true })
|
||
.click({ trial: true });
|
||
await accountPage
|
||
.getByRole('menuitem', { name: 'Your notebook', exact: true })
|
||
.click({ trial: true });
|
||
assert.equal(
|
||
await accountPage.evaluate(() => document.documentElement.scrollWidth <= innerWidth),
|
||
true,
|
||
);
|
||
assert.deepEqual(
|
||
await accountPage
|
||
.getByRole('menuitem')
|
||
.evaluateAll((items) => [
|
||
...new Set(items.map((item) => getComputedStyle(item).flexDirection)),
|
||
]),
|
||
['row'],
|
||
'account links and buttons retain one row anatomy',
|
||
);
|
||
const accountBounds = await accountPage.getByRole('menu').boundingBox();
|
||
assert.ok(
|
||
accountBounds.x >= 0 && accountBounds.x + accountBounds.width <= width,
|
||
'account popup fits viewport at ' + width,
|
||
);
|
||
if (width <= 380) {
|
||
const menuBounds = await accountPage.locator('.sk-grouped-panel').boundingBox();
|
||
assert.ok(
|
||
accountBounds.x >= menuBounds.x &&
|
||
accountBounds.x + accountBounds.width <= menuBounds.x + menuBounds.width,
|
||
'account popup is not clipped by navigation at ' + width,
|
||
);
|
||
}
|
||
await accountPage.screenshot({
|
||
path:
|
||
(process.env.BROWSER_SMOKE_DIR ?? 'browser-smoke-artifacts') +
|
||
'/account-menu-' +
|
||
width +
|
||
'.png',
|
||
});
|
||
await accountPage.keyboard.press('Escape');
|
||
assert.equal(await accountTrigger.getAttribute('aria-expanded'), 'false');
|
||
}
|
||
await signedIn.close();
|
||
const noJs = await browser.newContext({
|
||
javaScriptEnabled: false,
|
||
viewport: { width: 390, height: 844 },
|
||
});
|
||
const plain = await noJs.newPage();
|
||
await plain.goto(base + '/analyze');
|
||
await plain.locator('[data-sitekit-menu] summary').click();
|
||
assert.equal(await plain.locator('[data-sitekit-menu] a').first().isVisible(), true);
|
||
await noJs.close();
|
||
console.log(
|
||
'Shared shell: responsive navigation, Escape/outside/route dismissal, active state, account entry, one root shell, native no-JS menu and shared fonts passed.',
|
||
);
|
||
} finally {
|
||
await browser.close();
|
||
}
|