Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions web/src/styles/new-note.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
}
.new-note-hint {
font-size: 14px;
color: var(--t4);
margin: 6px 0 12px;
}
.new-note-tiles {
Expand Down Expand Up @@ -312,7 +311,6 @@
}
.new-note-hint {
font-size: 14px;
color: var(--t4);
margin: 6px 0 0;
}
.new-note-foot {
Expand Down Expand Up @@ -410,7 +408,7 @@
.new-note[data-starter="Meeting"] .tiptap p:has(> br:only-child)::before {
position: absolute;
pointer-events: none;
color: var(--t4);
color: var(--t3);
}

.quick-note-content textarea::placeholder {
Expand Down
150 changes: 150 additions & 0 deletions web/tests/integration/new-note-contrast-browser.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { chromium, expect } from "@playwright/test";

const browser = await chromium.launch({
channel: process.env.NOTES_BROWSER_CHANNEL ?? "msedge",
headless: true,
});
const base = process.env.NOTES_PREVIEW_URL ?? "http://127.0.0.1:5187";

try {
const page = await browser.newPage({
viewport: { width: 1440, height: 1000 },
serviceWorkers: "block",
});
await page.addInitScript(() =>
localStorage.setItem("orbyn-notes.local-only", "1"),
);
await page.goto(base);
await page
.getByRole("button", { name: "New note", exact: true })
.first()
.waitFor();
const close = page.getByRole("button", { name: "Close setup" });
if (await close.isVisible()) await close.click();
await page
.getByRole("button", { name: "New note", exact: true })
.first()
.click();
const hint = page.locator(".new-note-hint");
await expect(hint).toBeVisible();
await page.evaluate(() => document.fonts.ready);
expect(
await page.evaluate(() => document.fonts.check('400 14px "Geist"')),
).toBe(true);
for (const width of [1440, 390]) {
await page.setViewportSize({ width, height: 1000 });
for (const theme of ["light", "dark", "dim"]) {
await page.evaluate((value) => {
document.documentElement.dataset.theme = value;
}, theme);
const measured = await hint.evaluate((element) => {
const parse = (value) => {
const numbers = value.match(/[\d.]+/g).map(Number);
return [numbers[0], numbers[1], numbers[2], numbers[3] ?? 1];
};
const composite = (front, back) =>
front
.slice(0, 3)
.map((c, i) => c * front[3] + back[i] * (1 - front[3]));
let background = [255, 255, 255];
const layers = [];
for (let node = element; node; node = node.parentElement)
layers.push(parse(getComputedStyle(node).backgroundColor));
for (const layer of layers.reverse())
background = composite(layer, background);
const style = getComputedStyle(element);
const foreground = parse(style.color);
const mixed = composite(foreground, background);
const luminance = (rgb) =>
rgb
.map((c) => c / 255)
.map((c) =>
c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4,
)
.reduce((sum, c, i) => sum + c * [0.2126, 0.7152, 0.0722][i], 0);
const a = luminance(mixed),
b = luminance(background);
const rect = element.getBoundingClientRect();
return {
color: style.color,
font: style.font,
background,
composited: mixed,
contrast: (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05),
rect: {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
},
viewport: innerWidth,
scrollWidth: document.documentElement.scrollWidth,
};
});
console.log(JSON.stringify({ theme, width, ...measured }));
expect(measured.contrast).toBeGreaterThanOrEqual(4.5);
expect(measured.rect.x).toBeGreaterThanOrEqual(0);
expect(measured.rect.x + measured.rect.width).toBeLessThanOrEqual(
width + 1,
);
expect(measured.scrollWidth).toBeLessThanOrEqual(width + 1);
if (process.env.NOTES_EVIDENCE_DIR) {
await page.screenshot({
path: `${process.env.NOTES_EVIDENCE_DIR}/hint-${theme}-${width}.png`,
});
}
}
}
await page.setViewportSize({ width: 1440, height: 1000 });
await page.getByRole("button", { name: /Meeting/ }).click();
const prompts = page.locator('.new-note[data-starter="Meeting"] .tiptap p');
await expect(prompts).toHaveCount(3);
for (const theme of ["light", "dark", "dim"]) {
await page.evaluate((value) => {
document.documentElement.dataset.theme = value;
}, theme);
const values = await prompts.evaluateAll((elements) =>
elements.map((element) => {
const css = getComputedStyle(element, "::before");
const parse = (value) => value.match(/[\d.]+/g).map(Number);
const foreground = parse(css.color);
const background = parse(
getComputedStyle(element.closest(".new-note")).backgroundColor,
);
const mixed = background
.slice(0, 3)
.map(
(c, i) => foreground[i] * foreground[3] + c * (1 - foreground[3]),
);
const luminance = (rgb) =>
rgb
.map((c) => c / 255)
.map((c) =>
c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4,
)
.reduce((sum, c, i) => sum + c * [0.2126, 0.7152, 0.0722][i], 0);
const a = luminance(mixed),
b = luminance(background.slice(0, 3));
return {
text: css.content,
font: css.fontSize,
color: css.color,
background: background.slice(0, 3),
composited: mixed,
contrast: (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05),
};
}),
);
console.log(JSON.stringify({ theme, meeting: values }));
expect(values.map((value) => value.text)).toEqual([
'"Names"',
'"What was said"',
'"An action. Planner task links are Planned"',
]);
for (const value of values) {
expect(value.contrast).toBeGreaterThanOrEqual(4.5);
}
}
} finally {
await browser.close();
}