Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ A new release of a package the kit's peers pull in can turn these steps red with
It then compares the installed kit's declarations and API documentation with its source, and checks the types of each package's `scripts/`.
Those comparisons, and the kit's own build, which carries the documentation onto the declarations the Angular compiler writes, read the kit's source through TypeScript's compiler API in the same process, from `src/noldova.ui.components.angular/scripts/api/`.

`npm test` runs every test past the others' failures: the nativeElement assertions check, the OnPush strategies check, the poll and test limits check, the part glyphs check, on Linux x64 only the Kit bundles, the Kit copies, the Kit manifest and Angular's newest, the kit's Node.js tests, `src/noldova.ui.components.angular/tests/node/*.test.ts`, with `node --test`, of the symbols entry and the stylesheets that load the symbol font, which no browser loads, and the kit's Angular specs, which must each report a result, with no test identity, the spec file and the titles of its suites and test, repeated, then, on Linux only, builds the docs site and tests it, as `npm run docs:build` and `npm run docs:test` do, as the static site it serves is the same on every platform.
`npm test` runs every test past the others' failures: the nativeElement assertions check, the browser APIs check, the OnPush strategies check, the poll and test limits check, the part glyphs check, on Linux x64 only the Kit bundles, the Kit copies, the Kit manifest and Angular's newest, the kit's Node.js tests, `src/noldova.ui.components.angular/tests/node/*.test.ts`, with `node --test`, of the symbols entry and the stylesheets that load the symbol font, which no browser loads, and the kit's Angular specs, which must each report a result, with no test identity, the spec file and the titles of its suites and test, repeated, then, on Linux only, builds the docs site and tests it, as `npm run docs:build` and `npm run docs:test` do, as the static site it serves is the same on every platform.
With `NOLDOVA_SEPARATE_TEST=docs`, as the CI targets' tests set it, `npm test` leaves the docs site out, and the CI run's "Separate test" job checks it once, with `npm run build` and `npm run test:docs`.
The kit's Angular specs run in two runs of Angular's test builder, each in a browser of its own: first every test but those in a `describe(LayoutTraceFixture.suite, ...)`, then, from the spec files that hold one, only those. A layout trace records every tab of its browser, so in the first browser, under the whole suite, one could take over 10 seconds to end and keep another spec's trace from starting ([#198](https://github.com/noldova-com/ui-components/issues/198)); in the second only the tracing tests run. Both runs use the Angular `part` configuration, and the script adds up their coverage as `npm run test:merge` does below, gating it on a whole run. The suite's title is in `src/noldova.ui.components.angular/tests/fixtures/layout-trace-suite.ts`, which the fixture and the script both read. After both runs, the script fails unless each test in either run's report passed or failed in exactly one of them, and the second run ran at least one test, so a traced test that both filters skip, or that both run, fails the run.
`npm test -- --shard=<part>/<parts>`, with 2 to 8 parts, runs only every `<parts>`-th spec file of the kit's sorted list, from the `<part>`-th, with the Angular `part` configuration, which keeps the coverage report in `_build/angular-coverage` without gating it, and runs the checks and the Node.js tests before the specs only in part 1.
`npm run test:merge -- <folder> <parts>`, with Node.js alone, first checks itself on small reports in a temporary folder, then adds up the coverage of the parts, each in a subfolder of `<folder>`, by where each function, statement and branch sits in its file, from only the parts that loaded the file, since a part that never loaded it maps it from its source and can map it otherwise, and fails as `npm test` does below the requirement in [Coverage](#coverage), naming what no part reached; it also fails when fewer subfolders than `<parts>` came, or when one holds no report or one that isn't JSON.
`npm test -- <filter>...` runs only the spec files and Node.js tests whose path from the repository root holds a filter, without the coverage gates, the nativeElement assertions check, the OnPush strategies check, the poll and test limits check, the part glyphs check, the Kit bundles, the Kit copies, the Kit manifest, Angular's newest and the docs site, and fails when nothing matches.
`npm test -- <filter>...` runs only the spec files and Node.js tests whose path from the repository root holds a filter, without the coverage gates, the nativeElement assertions check, the browser APIs check, the OnPush strategies check, the poll and test limits check, the part glyphs check, the Kit bundles, the Kit copies, the Kit manifest, Angular's newest and the docs site, and fails when nothing matches.
`npm run test:timing`, after `npm test`, is the timing check that [Time per file](#time-per-file) describes; CI doesn't run it, since its pass condition is a time, and it belongs on a test machine.
The root's `npm run build:components` and `npm test` run each workspace's own `build` and `test`, and `npm run build:docs` each workspace's own `docs:build`, passing on what follows `--`; each package's scripts run from its own folder, with paths relative to it, and write to the root's `_build/` and `_packages/`.
The kit's entry points are `src/noldova.ui.components.angular/scripts/build.ts` and `src/noldova.ui.components.angular/scripts/test.ts`, and the docs site's are in `src/noldova.ui.components.angular.docs/scripts/`.
Expand Down Expand Up @@ -136,6 +136,11 @@ The typed generic, `querySelector<HTMLElement>(…)`, stays allowed.
A spec reads such an element through the same fixture instead: `DomFixture.one(root, selector)` and `DomFixture.oneOf(root, selector, HTMLInputElement)` return the first match checked with `instanceof` and throw when nothing matches or the match is of another class, `DomFixture.maybe` returns `null` where nothing matches for a spec that expects the element absent, `DomFixture.all` and `allOf` check every match, and `DomFixture.present` checks that an element a spec found in a list is there.
It reads one line at a time: it refuses an assertion that a line break splits from its expression, a line that starts with `as HTMLElement`, `] as HTMLElement[]` or `as [HTMLElement, HTMLElement]`, or a code line that ends in `as`, but a read that a line break splits after its `=` passes, as does an untyped `nativeElement` passed to a typed parameter.

### Browser APIs

The kit supports the browsers `src/noldova.ui.components.angular/README.md` names, Safari 16.5 among them, so a part calls no browser API one of them lacks: whether an element is drawn comes from `ElementVisibility.isDrawn`, in `src/noldova.ui.components.angular/src/app/models/element-visibility.ts`, which reads the element's boxes, and its computed `visibility` when asked, where `Element.checkVisibility()` exists only from Safari 17.4.
The browser APIs check, `src/noldova.ui.components.angular/scripts/checks/browser-api-check.ts`, reads every TypeScript file under `src/noldova.ui.components.angular/src` and `src/noldova.ui.components.angular.docs/src` and fails on each line that calls `checkVisibility(`, naming the file and line and what to call instead; specs and fixtures, which run in Chromium only, may still call it.

### Part glyphs

The part glyphs check, `src/noldova.ui.components.angular/scripts/checks/part-glyphs-check.ts`, reads the glyphs each part the kit's entries export can draw, as the build writes them to the package's `glyphs.json`, with TypeScript's type checker over every source file under `src/noldova.ui.components.angular/src` but the specs.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @license
* Copyright (c) Noldova.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

import { readdir, readFile } from "node:fs/promises";
import path from "node:path";
import type { Writable } from "node:stream";

import type { ICheck } from "./interfaces/i-check.ts";

export class BrowserApiCheck implements ICheck {
private static readonly FOLDERS: readonly string[] = ["src/noldova.ui.components.angular/src", "src/noldova.ui.components.angular.docs/src"];
private static readonly SOURCE: RegExp = /\.ts$/;
private static readonly DECLARATIONS: RegExp = /\.d\.ts$/;
private static readonly CALLS: readonly (readonly [RegExp, string])[] = [
[/\.checkVisibility\s*\(/, "Element.checkVisibility(), which Safari before 17.4 lacks; call ElementVisibility.isDrawn instead"]
Comment thread
rostislavrotaru marked this conversation as resolved.
Resolved
];
private static readonly ENCODING: BufferEncoding = "utf8";

private readonly root: string;

public readonly title: string = "browser APIs";

public constructor(root: string) {
this.root = root;
}

public async runAsync(output: Writable): Promise<boolean> {
const findings: string[] = [];
let count = 0;
for (const folder of BrowserApiCheck.FOLDERS) {
const files = (await readdir(path.join(this.root, folder), { recursive: true }))
.filter(t => BrowserApiCheck.SOURCE.test(t) && !BrowserApiCheck.DECLARATIONS.test(t)).sort();
count += files.length;
for (const file of files) {
const lines = (await readFile(path.join(this.root, folder, file), BrowserApiCheck.ENCODING)).split("\n");
lines.forEach((line, index) => {
for (const [call, advice] of BrowserApiCheck.CALLS)
if (call.test(line))
findings.push(`${path.posix.join(folder, file.split(path.sep).join(path.posix.sep))}:${index + 1} calls ${advice}.`);
});
}
}
for (const finding of findings)
output.write(`${finding}\n`);
output.write(`Read ${count} files under ${BrowserApiCheck.FOLDERS.join(" and ")} for a browser API a supported browser lacks.\n`);
return findings.length === 0;
}
}
2 changes: 2 additions & 0 deletions src/noldova.ui.components.angular/scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AngularCoverageReport } from "./angular/angular-coverage-report.ts";
import { AngularTestReport } from "./angular/angular-test-report.ts";
import { CoverageMerge } from "./angular/coverage-merge.ts";
import { AngularNewestCheck } from "./checks/angular-newest-check.ts";
import { BrowserApiCheck } from "./checks/browser-api-check.ts";
import { FailureScreenshotCheck } from "./checks/failure-screenshot-check.ts";
import { IconNamesCheck } from "./checks/icon-names-check.ts";
import type { ICheck } from "./checks/interfaces/i-check.ts";
Expand Down Expand Up @@ -106,6 +107,7 @@ export class Test extends Script {
const isFiltered = filters.length > 0;
if (!isFiltered && (Object.isNull(shard) || shard.part === 1)) {
await this.runCheckAsync(new NativeElementAssertionCheck(Test.ROOT));
await this.runCheckAsync(new BrowserApiCheck(Test.ROOT));
await this.runCheckAsync(new OnPushCheck(Test.ROOT, new ProcessRunner()));
await this.runCheckAsync(new PollBoundCheck(Test.ROOT));
await this.runCheckAsync(new IconNamesCheck(Test.ROOT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { PopoverOpening } from "../../enums/popover-opening.js";
import type { ITimeSource } from "../../interfaces/i-time-source.js";
import { ClockTokens } from "../../models/clock-tokens.js";
import { ComposingKey } from "../../models/composing-key.js";
import { ElementVisibility } from "../../models/element-visibility.js";
import { OverlayAnchoring } from "../../models/overlay-anchoring.js";
import { OverlaySide } from "../../models/overlay-side.js";
import { PointerGraceArea } from "../../models/pointer-grace-area.js";
Expand Down Expand Up @@ -246,6 +247,6 @@ export class PopoverTriggerDirective {
return false;
const toward = event.shiftKey ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;
return ![...pane.querySelectorAll<HTMLElement>(Resources.focusableSelector)]
.some(t => t.tabIndex >= 0 && !t.matches(":disabled") && t.checkVisibility({ visibilityProperty: true }) && (focused.compareDocumentPosition(t) & toward) !== 0);
.some(t => t.tabIndex >= 0 && !t.matches(":disabled") && ElementVisibility.isDrawn(t, true) && (focused.compareDocumentPosition(t) & toward) !== 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "@noldova/context.core";

import { SiteWordmarkSize } from "../../enums/site-wordmark-size.js";
import type { IResizeObservers } from "../../interfaces/i-resize-observers.js";
import { ElementVisibility } from "../../models/element-visibility.js";
import { ResizeTokens } from "../../models/resize-tokens.js";
import type { SiteLink } from "../../models/site-link.js";
import type { SiteSocialLink } from "../../models/site-social-link.js";
Expand Down Expand Up @@ -134,7 +135,7 @@ export class SiteHeaderComponent {
this.searchOpen.set(false);
if (isOpening)
afterNextRender(() => {
const stops = [...this.menuPanel().nativeElement.querySelectorAll<HTMLElement>(SiteHeaderResources.menuStops)].filter(t => t.tabIndex >= 0 && t.checkVisibility());
const stops = [...this.menuPanel().nativeElement.querySelectorAll<HTMLElement>(SiteHeaderResources.menuStops)].filter(t => t.tabIndex >= 0 && ElementVisibility.isDrawn(t));
for (const stop of stops.slice(0, 1))
stop.focus();
}, { injector: this.injector });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { IResizeObservers } from "../../interfaces/i-resize-observers.js";
import type { ITimeSource } from "../../interfaces/i-time-source.js";
import type { IVirtualListObserver } from "../../interfaces/i-virtual-list-observer.js";
import { ClockTokens } from "../../models/clock-tokens.js";
import { ElementVisibility } from "../../models/element-visibility.js";
import { ResizeTokens } from "../../models/resize-tokens.js";
import { VirtualListAnchor } from "../../models/virtual-list-anchor.js";
import { VirtualListChoice } from "../../models/virtual-list-choice.js";
Expand Down Expand Up @@ -534,7 +535,7 @@ export class VirtualListComponent<T> {
private focusBeside(isAfter: boolean): void {
const feed = this.viewport().nativeElement;
const tabbable = [...this.document.querySelectorAll<HTMLElement>(Resources.focusableSelector)]
.filter(t => t.tabIndex >= 0 && !feed.contains(t) && !t.matches(":disabled") && t.checkVisibility({ visibilityProperty: true }));
.filter(t => t.tabIndex >= 0 && !feed.contains(t) && !t.matches(":disabled") && ElementVisibility.isDrawn(t, true));
const target = isAfter
? tabbable.find(t => (feed.compareDocumentPosition(t) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0)
: tabbable.findLast(t => (feed.compareDocumentPosition(t) & Node.DOCUMENT_POSITION_PRECEDING) !== 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @license
* Copyright (c) Noldova.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

export class ElementVisibility {
public static isDrawn(element: Element, isVisibilityAsked: boolean = false): boolean {
return element.getClientRects().length > 0 && (!isVisibilityAsked || getComputedStyle(element).visibility === "visible");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { IResizeObservers } from "../interfaces/i-resize-observers.js";
import type { ITimeSource } from "../interfaces/i-time-source.js";
import { ClockTokens } from "../models/clock-tokens.js";
import { ContentMovedEvent } from "../models/content-moved-event.js";
import { ElementVisibility } from "../models/element-visibility.js";
import type { OverlayAnchoring } from "../models/overlay-anchoring.js";
import type { OverlayPlacement } from "../models/overlay-placement.js";
import { PlacedBoxes } from "../models/placed-boxes.js";
Expand Down Expand Up @@ -144,7 +145,7 @@ export class AnchoredOverlay {
});
resize.observe(this.element);
const hidden = this.observers.create(() => {
if (!origin.checkVisibility())
if (!ElementVisibility.isDrawn(origin))
this.originLostValue.next();
});
hidden.observe(origin);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @license
* Copyright (c) Noldova.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/

import { ElementVisibility } from "../../../src/app/models/element-visibility";

describe("ElementVisibility", () => {
let host: HTMLElement;

beforeEach(() => {
host = document.createElement("div");
host.innerHTML = "<p class=\"shown\">Shown</p><p class=\"none\" style=\"display: none\">None</p>"
+ "<div style=\"display: none\"><p class=\"inside\">Inside</p></div><p class=\"hidden\" style=\"visibility: hidden\">Hidden</p>"
+ "<p class=\"collapsed\" style=\"visibility: collapse\">Collapsed</p>";
document.body.append(host);
});

afterEach(() => host.remove());

const read = (selector: string, isVisibilityAsked: boolean): boolean => {
const element = host.querySelector(selector);
if (element === null)
throw new Error(`${selector} isn't in the host.`);
return ElementVisibility.isDrawn(element, isVisibilityAsked);
};

it("answers as checkVisibility does, with and without the visibility property", () => {
const selectors = [".shown", ".none", ".inside", ".hidden", ".collapsed"];

expect(selectors.map(t => [read(t, false), read(t, true)])).toEqual(selectors.map(t => {
const element = host.querySelector(t);
return [element?.checkVisibility(), element?.checkVisibility({ visibilityProperty: true })];
}));
expect(selectors.map(t => [read(t, false), read(t, true)])).toEqual([[true, true], [false, false], [false, false], [true, false], [true, false]]);
});

it("calls no checkVisibility, which Safari before 17.4 lacks", () => {
const check = vi.spyOn(Element.prototype, "checkVisibility").mockImplementation(() => {
throw new TypeError("checkVisibility is not a function");
});
try {
expect([read(".shown", true), read(".hidden", true), read(".none", false)]).toEqual([true, false, false]);
expect(check).not.toHaveBeenCalled();
} finally {
check.mockRestore();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ describe("AnchoredOverlay", () => {
// The overlay's observer of its anchor asks whether the anchor still renders each time it sees it resize.
const seen = new ChangeSignalFixture();
let checks = 0;
const isVisible = origin.checkVisibility.bind(origin);
vi.spyOn(origin, "checkVisibility").mockImplementation(options => {
const rects = origin.getClientRects.bind(origin);
vi.spyOn(origin, "getClientRects").mockImplementation(() => {
checks++;
seen.fire();
return isVisible(options);
return rects();
});
overlay.openComponent(new ComponentPortal(ContentComponent), origin, below());
origin.style.width = "200px";
Expand Down
Loading