| 1 | // Run: tsx src/__tests__/image-viewer-window-controls.test.ts |
| 2 | |
| 3 | import assert from "node:assert/strict"; |
| 4 | import { readFileSync } from "node:fs"; |
| 5 | |
| 6 | const styles = readFileSync(new URL("../styles.css", import.meta.url), "utf8").replace(/\/\*[\s\S]*?\*\//g, ""); |
| 7 | |
| 8 | function finalDeclaration(selector: string, property: string): string | undefined { |
| 9 | let value: string | undefined; |
| 10 | const rule = /([^{}]+)\{([^{}]*)\}/g; |
| 11 | let ruleMatch: RegExpExecArray | null; |
| 12 | |
| 13 | while ((ruleMatch = rule.exec(styles)) !== null) { |
| 14 | const selectors = ruleMatch[1].split(",").map((part) => part.trim()); |
| 15 | if (!selectors.includes(selector)) continue; |
| 16 | |
| 17 | const declaration = new RegExp(`(?:^|;)\\s*${property}\\s*:\\s*([^;]+)`, "g"); |
| 18 | let declarationMatch: RegExpExecArray | null; |
| 19 | while ((declarationMatch = declaration.exec(ruleMatch[2])) !== null) { |
| 20 | value = declarationMatch[1].trim(); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | return value; |
| 25 | } |
| 26 | |
| 27 | const windowsPreviewSelector = ".app--windows-frameless:has(.image-viewer-backdrop) > .windows-window-controls"; |
| 28 | const windowsAutomationSelector = ".app--windows-frameless.app--automation > .windows-window-controls"; |
| 29 | |
| 30 | assert.equal(finalDeclaration(".image-viewer__close", "right"), "16px"); |
| 31 | assert.equal(finalDeclaration(".app--windows-frameless .image-viewer__close", "right"), undefined); |
| 32 | assert.equal(finalDeclaration(windowsPreviewSelector, "opacity"), "0"); |
| 33 | assert.equal(finalDeclaration(windowsPreviewSelector, "visibility"), "hidden"); |
| 34 | assert.equal(finalDeclaration(windowsPreviewSelector, "pointer-events"), "none"); |
| 35 | |
| 36 | // Management pages reserve caption space; unlike image previews, they retain |
| 37 | // native window controls, including while the automation editor is open. |
| 38 | assert.equal(finalDeclaration(windowsAutomationSelector, "opacity"), undefined); |
| 39 | assert.equal(finalDeclaration(windowsAutomationSelector, "visibility"), undefined); |
| 40 | assert.equal(finalDeclaration(windowsAutomationSelector, "pointer-events"), undefined); |
| 41 | |
| 42 | console.log("image viewer and automation window controls: 8 passed"); |
| 43 |