Files
pezkuwi-apps/packages/page-accounts/test/pages/accountsPage.tsx
T
Satoshi Qazi Muhammed 3767c819e3 Accounts, Contacts and Sidebar specs: follow the current table layout, run them
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.
2026-10-10 16:28:39 +04:00

117 lines
3.6 KiB
TypeScript

// Copyright 2017-2026 @pezkuwi/app-accounts authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Sidebar } from '@pezkuwi/test-support/pagesElements';
import type { AccountOverrides } from '@pezkuwi/test-support/types';
import { fireEvent, screen, within } from '@testing-library/react';
import React from 'react';
import { anAccount } from '@pezkuwi/test-support/creation/account';
import { Page } from '@pezkuwi/test-support/pages/Page';
import { assertText, clickButton } from '@pezkuwi/test-support/utils';
import { settings } from '@pezkuwi/ui-settings';
import AccountOverview from '../../src/Accounts/index.js';
import { AccountRow } from '../pageElements/AccountRow.js';
const NOOP_CHANGE = () => undefined;
// set the account creation for localStorage to on
settings.set({ ...settings.get(), storage: 'on' });
export class AccountsPage extends Page {
constructor () {
super(
<AccountOverview onStatusChange={NOOP_CHANGE} />
);
}
/** The rows of every account group table, in the order shown */
async getAccountRows (): Promise<AccountRow[]> {
const rows: AccountRow[] = [];
for (const table of await this.getTables()) {
for (const row of await table.getRows()) {
rows.push(new AccountRow(row.primaryRow, row.balanceRow, row.detailsRow));
}
}
return rows;
}
async reverseSortingOrder (): Promise<void> {
const sortingComponent = await this.getSortByComponent();
const reverseOrderButton = await within(sortingComponent).findByRole('button');
fireEvent.click(reverseOrderButton);
}
async sortBy (category: string): Promise<void> {
const currentCategory = await this.getCurrentSortCategory();
fireEvent.click(currentCategory);
const selectedCategory = await this.getSortCategory(category);
fireEvent.click(selectedCategory);
}
async getCurrentSortCategory (): Promise<HTMLElement> {
const sortByComponent = await this.getSortByComponent();
return within(sortByComponent).findByRole('alert');
}
async enterCreateAccountModal (): Promise<void> {
this.render([]);
await clickButton('Account');
await assertText('Add an account via seed 1/3');
}
renderAccountsWithDefaultAddresses (...overrides: AccountOverrides[]): void {
const accounts = overrides.map((accountProperties, index) =>
[this.defaultAddresses[index], accountProperties] as [string, AccountOverrides]);
this.render(accounts);
}
renderAccountsForAddresses (...addresses: string[]): void {
const accounts = addresses.map((address) => [address, anAccount()] as [string, AccountOverrides]);
this.render(accounts);
}
renderDefaultAccounts (accountsNumber: number): void {
const accounts = Array.from({ length: accountsNumber },
(_, index) => [this.defaultAddresses[index], anAccount()] as [string, AccountOverrides]);
this.render(accounts);
}
async openSidebarForRow (accountRowIndex: number): Promise<Sidebar> {
const accountRows = await this.getAccountRows();
return accountRows[accountRowIndex].openSidebar();
}
private async getSortCategory (categoryName: string): Promise<HTMLElement> {
const sortByComponent = await this.getSortByComponent();
const availableCategories = await within(sortByComponent).findAllByRole('option');
const selectedCategory = availableCategories.find((category) => category.textContent === categoryName);
if (!selectedCategory) {
throw new Error('No category found');
}
return selectedCategory;
}
private async getSortByComponent (): Promise<HTMLElement> {
this.assertRendered();
return await screen.findByTestId('sort-by-section');
}
}