// 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 { const actualBalanceText = await this.getBalanceSummary(); const expectedBalanceText = format(expectedTotalBalance); assertTextContent(actualBalanceText, expectedBalanceText); } async getBalanceSummary (): Promise { return within(this.balanceRow).findByTestId('balance-summary'); } async assertAccountName (expectedName: string): Promise { const accountName = await this.getAccountName(); assertTextContent(accountName, expectedName); } async assertBalancesDetails (expectedBalanceComponents: { name: string, amount: Balance }[]): Promise { for (const { amount, name } of expectedBalanceComponents) { await this.assertBalanceComponent({ amount, name }); } } async assertBadge (expectedBadgeName: string): Promise { await within(this.primaryRow).findByTestId(expectedBadgeName); } assertNoBadge (badgeName: string): void { expect(within(this.primaryRow).queryByTestId(badgeName)).toBeFalsy(); } async assertTags (expectedTagsContent: string): Promise { const actualTags = await within(this.detailsRow).findByTestId('tags'); assertTextContent(actualTags, expectedTagsContent); } async assertShortAddress (expectedShortAddress: string): Promise { 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 { return within(this.primaryRow).findByTestId(`${expectedBadgeName}-badge`); } async openSidebar (): Promise { 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 { const balanceElement = await this.getBalanceElementByLabelName(expectedBalanceComponent.name); const balanceText = format(expectedBalanceComponent.amount); assertTextContent(balanceElement, balanceText); } private async getBalanceElementByLabelName (labelName: string): Promise { const labelElement = await within(this.detailsRow).findByText(labelName); return labelElement.nextSibling; } private getAccountName (): Promise { return within(this.primaryRow).findByTestId('account-name'); } }