mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-10-27 04:59:49 +00:00
The three suites were skipped since the table rework. What changed under them: - An account or contact spans three rows (main, total balance, details), marked from isFirst; the helpers paired rows by two and filtered on a row class the rows no longer carry. A collapsed details row is hidden, so rows are read including hidden ones. - Accounts render one table per account group; the page object reads the rows of every group table in order, and the sorting fixture keeps its three accounts in one group, since sorting applies within a group. - The expand toggle is the row's expand column, not a row-toggle element. - useAccountInfo reads ownership from the keyring context, which the test page did not provide, so saving a name did nothing; the page now renders the real KeyringCtxRoot. The mock api gains consts.system.ss58Prefix. - Badge popups (react-tooltip v6) render only while hovered; the specs hover the badge first. The multisig badge needs the isMultisig flag. - Addresses are shown in full and shortened by css; the fixtures with shortened addresses are gone. - The total balance, transferable and locked cards are always shown, as placeholders without accounts; the specs check that instead of their absence. - Checks that needed matchers the runner lacks (not.toHaveLength, toHaveProperty, toThrow with a contained message) are written against the DOM directly.
66 lines
2.8 KiB
TypeScript
66 lines
2.8 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/test-supports authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// DOM checks with the meaning of the matching @testing-library/jest-dom
|
|
// matchers, which the node:test based runner does not provide
|
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
function describeElement (node: Node): string {
|
|
const html = (node as Partial<Element>).outerHTML ?? node.nodeName;
|
|
|
|
return html.length > 200
|
|
? `${html.slice(0, 200)}...`
|
|
: html;
|
|
}
|
|
|
|
/** As toHaveClass: the element carries the class */
|
|
export function assertHasClass (node: Node | null, className: string): void {
|
|
assert.ok(node, `Expected an element with class "${className}", found none`);
|
|
|
|
const classList = (node as Partial<Element>).classList;
|
|
|
|
assert.ok(classList, `Expected an element with class "${className}", found ${describeElement(node)}`);
|
|
assert.ok(classList.contains(className), `Expected class "${className}" on ${describeElement(node)}`);
|
|
}
|
|
|
|
/** As not.toHaveClass: the element is there, without the class */
|
|
export function assertNotHasClass (node: Node | null, className: string): void {
|
|
assert.ok(node, `Expected an element without class "${className}", found none`);
|
|
|
|
const classList = (node as Partial<Element>).classList;
|
|
|
|
assert.ok(classList, `Expected an element without class "${className}", found ${describeElement(node)}`);
|
|
assert.ok(!classList.contains(className), `Expected no class "${className}" on ${describeElement(node)}`);
|
|
}
|
|
|
|
/** As toHaveTextContent: the whitespace-normalized text contains the string, or matches the pattern */
|
|
export function assertTextContent (element: Node | null, expected: string | RegExp): void {
|
|
assert.ok(element, `Expected an element with text ${String(expected)}, found none`);
|
|
|
|
const text = (element.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
|
|
if (typeof expected === 'string') {
|
|
assert.ok(text.includes(expected), `Expected text containing "${expected}", found "${text}"`);
|
|
} else {
|
|
assert.match(text, expected);
|
|
}
|
|
}
|
|
|
|
/** As toBeVisible: in the document, and neither it nor an ancestor is hidden */
|
|
export function assertVisible (element: Element | null): void {
|
|
assert.ok(element, 'Expected a visible element, found none');
|
|
assert.ok(element.isConnected, `Expected ${describeElement(element)} to be in the document`);
|
|
|
|
for (let current: Element | null = element; current; current = current.parentElement) {
|
|
const style = current.ownerDocument.defaultView?.getComputedStyle(current);
|
|
const isHidden = current.hasAttribute('hidden') ||
|
|
style?.display === 'none' ||
|
|
style?.visibility === 'hidden' ||
|
|
style?.visibility === 'collapse' ||
|
|
style?.opacity === '0';
|
|
|
|
assert.ok(!isHidden, `Expected ${describeElement(element)} to be visible, hidden by ${describeElement(current)}`);
|
|
}
|
|
}
|