mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-10-20 18:56:30 +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.
109 lines
3.6 KiB
TypeScript
109 lines
3.6 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/test-supports authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
/* global expect */
|
|
|
|
import type { Balance } from '@pezkuwi/types/interfaces';
|
|
|
|
import { fireEvent, screen, within } from '@testing-library/react';
|
|
|
|
import { format } from '../utils/balance.js';
|
|
import { assertTextContent } from '../utils/domAssertions.js';
|
|
import { Sidebar } from './Sidebar.js';
|
|
|
|
// utility wrapper over an account item in accounts table, serves basic assertions about an account row
|
|
export class Row {
|
|
public primaryRow: HTMLElement;
|
|
public balanceRow: HTMLElement;
|
|
public detailsRow: HTMLElement;
|
|
|
|
constructor (primaryRow: HTMLElement, balanceRow: HTMLElement, detailsRow: HTMLElement) {
|
|
this.primaryRow = primaryRow;
|
|
this.balanceRow = balanceRow;
|
|
this.detailsRow = detailsRow;
|
|
}
|
|
|
|
async assertBalancesTotal (expectedTotalBalance: Balance): Promise<void> {
|
|
const actualBalanceText = await this.getBalanceSummary();
|
|
const expectedBalanceText = format(expectedTotalBalance);
|
|
|
|
assertTextContent(actualBalanceText, expectedBalanceText);
|
|
}
|
|
|
|
async getBalanceSummary (): Promise<HTMLElement> {
|
|
return within(this.balanceRow).findByTestId('balance-summary');
|
|
}
|
|
|
|
async assertAccountName (expectedName: string): Promise<void> {
|
|
const accountName = await this.getAccountName();
|
|
|
|
assertTextContent(accountName, expectedName);
|
|
}
|
|
|
|
async assertBalancesDetails (expectedBalanceComponents: { name: string, amount: Balance }[]): Promise<void> {
|
|
for (const { amount, name } of expectedBalanceComponents) {
|
|
await this.assertBalanceComponent({ amount, name });
|
|
}
|
|
}
|
|
|
|
async assertBadge (expectedBadgeName: string): Promise<void> {
|
|
await within(this.primaryRow).findByTestId(expectedBadgeName);
|
|
}
|
|
|
|
assertNoBadge (badgeName: string): void {
|
|
expect(within(this.primaryRow).queryByTestId(badgeName)).toBeFalsy();
|
|
}
|
|
|
|
async assertTags (expectedTagsContent: string): Promise<void> {
|
|
const actualTags = await within(this.detailsRow).findByTestId('tags');
|
|
|
|
assertTextContent(actualTags, expectedTagsContent);
|
|
}
|
|
|
|
async assertShortAddress (expectedShortAddress: string): Promise<void> {
|
|
const actualShortAddress = await within(this.primaryRow).findByTestId('short-address');
|
|
|
|
assertTextContent(actualShortAddress, expectedShortAddress);
|
|
}
|
|
|
|
expand (): void {
|
|
// the toggle is the row's expand column (Table.Column.Expand)
|
|
const toggle = this.primaryRow.querySelector('td.ui--Table-Column-Expand');
|
|
|
|
if (!toggle) {
|
|
throw new Error('Expected an expand toggle in the row');
|
|
}
|
|
|
|
fireEvent.click(toggle);
|
|
}
|
|
|
|
async getBadge (expectedBadgeName: string): Promise<HTMLElement> {
|
|
return within(this.primaryRow).findByTestId(`${expectedBadgeName}-badge`);
|
|
}
|
|
|
|
async openSidebar (): Promise<Sidebar> {
|
|
const accountName = await this.getAccountName();
|
|
|
|
fireEvent.click(accountName);
|
|
|
|
return new Sidebar(await screen.findByTestId('account-sidebar'));
|
|
}
|
|
|
|
private async assertBalanceComponent (expectedBalanceComponent: { name: string; amount: Balance }): Promise<void> {
|
|
const balanceElement = await this.getBalanceElementByLabelName(expectedBalanceComponent.name);
|
|
const balanceText = format(expectedBalanceComponent.amount);
|
|
|
|
assertTextContent(balanceElement, balanceText);
|
|
}
|
|
|
|
private async getBalanceElementByLabelName (labelName: string): Promise<ChildNode | null> {
|
|
const labelElement = await within(this.detailsRow).findByText(labelName);
|
|
|
|
return labelElement.nextSibling;
|
|
}
|
|
|
|
private getAccountName (): Promise<HTMLElement> {
|
|
return within(this.primaryRow).findByTestId('account-name');
|
|
}
|
|
}
|