|
| 1 | +import { expectDefined } from "@openclaw/normalization-core"; |
| 2 | +import { afterEach, describe, expect, it } from "vitest"; |
| 3 | +import "../../styles/base.css"; |
| 4 | +import "../../styles/settings.css"; |
| 5 | +import "../../styles/cron.css"; |
| 6 | + |
| 7 | +const hasBrowserLayout = !navigator.userAgent.toLowerCase().includes("jsdom"); |
| 8 | +const alignmentTolerancePx = 1.25; |
| 9 | + |
| 10 | +afterEach(() => { |
| 11 | + document.body.replaceChildren(); |
| 12 | +}); |
| 13 | + |
| 14 | +function centerY(bounds: DOMRect) { |
| 15 | + return bounds.top + bounds.height / 2; |
| 16 | +} |
| 17 | + |
| 18 | +async function nextFrame() { |
| 19 | + await new Promise<void>((resolve) => { |
| 20 | + requestAnimationFrame(() => resolve()); |
| 21 | + }); |
| 22 | +} |
| 23 | + |
| 24 | +describe.skipIf(!hasBrowserLayout)("cron editor browser layout", () => { |
| 25 | + it("vertically centers the configured trigger status with the Advanced heading", async () => { |
| 26 | + const details = document.createElement("details"); |
| 27 | + details.className = "cron-advanced"; |
| 28 | + details.open = true; |
| 29 | + details.innerHTML = ` |
| 30 | + <summary class="settings-section__heading cron-advanced__summary">Advanced</summary> |
| 31 | + `; |
| 32 | + document.body.append(details); |
| 33 | + |
| 34 | + const summary = expectDefined( |
| 35 | + details.querySelector<HTMLElement>(".cron-advanced__summary"), |
| 36 | + "Advanced summary", |
| 37 | + ); |
| 38 | + const heading = document.createRange(); |
| 39 | + heading.selectNode(expectDefined(summary.firstChild, "Advanced heading text")); |
| 40 | + |
| 41 | + summary.insertAdjacentHTML( |
| 42 | + "beforeend", |
| 43 | + ` |
| 44 | + <span class="cron-trigger-summary"> |
| 45 | + <svg viewBox="0 0 24 24" aria-hidden="true"> |
| 46 | + <path d="M6 3v12"></path> |
| 47 | + <path d="M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"></path> |
| 48 | + </svg> |
| 49 | + Trigger configured |
| 50 | + </span> |
| 51 | + `, |
| 52 | + ); |
| 53 | + await nextFrame(); |
| 54 | + |
| 55 | + const status = expectDefined( |
| 56 | + details.querySelector<HTMLElement>(".cron-trigger-summary"), |
| 57 | + "configured trigger status", |
| 58 | + ); |
| 59 | + const headingCenter = centerY(heading.getBoundingClientRect()); |
| 60 | + const statusCenter = centerY(status.getBoundingClientRect()); |
| 61 | + |
| 62 | + expect(Math.abs(statusCenter - headingCenter)).toBeLessThanOrEqual(alignmentTolerancePx); |
| 63 | + }); |
| 64 | +}); |
0 commit comments