Skip to content

Commit 1c3045c

Browse files
authored
chore: refactor some assertions to common code
1 parent fe2f38c commit 1c3045c

File tree

4 files changed

+202
-124
lines changed

4 files changed

+202
-124
lines changed

src/features/blocks/pages/block-page.test.tsx

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import { HttpError } from '@/tests/errors'
88
import { blockResultMother } from '@/tests/object-mother/block-result'
99
import { createStore } from 'jotai'
1010
import { blocksAtom } from '../data'
11-
import { getByDescriptionTerm } from '@/tests/custom-queries/get-description'
1211
import { nextRoundLabel, previousRoundLabel, roundLabel, timestampLabel, transactionsLabel } from '../components/block'
1312
import { transactionsAtom } from '@/features/transactions/data'
1413
import { transactionResultMother } from '@/tests/object-mother/transaction-result'
1514
import { assetResultMother } from '@/tests/object-mother/asset-result'
1615
import { assetsAtom } from '@/features/assets/data'
1716
import { ellipseId } from '@/utils/ellipse-id'
1817
import { ellipseAddress } from '@/utils/ellipse-address'
18+
import { tableAssertion } from '@/tests/assertions/table-assertion'
19+
import { descriptionListAssertion } from '@/tests/assertions/description-list-assertion'
1920

2021
describe('block-page', () => {
2122
describe('when rending a block using an invalid round number', () => {
@@ -71,12 +72,18 @@ describe('block-page', () => {
7172
return executeComponentTest(
7273
() => render(<BlockPage />, undefined, myStore),
7374
async (component) => {
74-
await waitFor(() => expect(getByDescriptionTerm(component.container, roundLabel).textContent).toBe(block.round.toString()))
75-
expect(getByDescriptionTerm(component.container, timestampLabel).textContent).toBe('Thu, 29 February 2024 06:52:01')
76-
expect(getByDescriptionTerm(component.container, transactionsLabel).textContent).toBe('0')
77-
expect(getByDescriptionTerm(component.container, previousRoundLabel).textContent).toBe((block.round - 1).toString())
78-
expect(getByDescriptionTerm(component.container, nextRoundLabel).textContent).toBe((block.round + 1).toString())
79-
75+
await waitFor(() =>
76+
descriptionListAssertion({
77+
container: component.container,
78+
items: [
79+
{ term: roundLabel, description: block.round.toString() },
80+
{ term: timestampLabel, description: 'Thu, 29 February 2024 06:52:01' },
81+
{ term: transactionsLabel, description: '0' },
82+
{ term: previousRoundLabel, description: (block.round - 1).toString() },
83+
{ term: nextRoundLabel, description: (block.round + 1).toString() },
84+
],
85+
})
86+
)
8087
const transactionsRow = getAllByRole(component.container, 'row')[1]
8188
expect(transactionsRow.textContent).toBe('No results.')
8289
}
@@ -101,31 +108,47 @@ describe('block-page', () => {
101108
return executeComponentTest(
102109
() => render(<BlockPage />, undefined, myStore),
103110
async (component) => {
104-
await waitFor(() => expect(getByDescriptionTerm(component.container, roundLabel).textContent).toBe(block.round.toString()))
105-
expect(getByDescriptionTerm(component.container, timestampLabel).textContent).toBe('Thu, 29 February 2024 06:52:01')
106-
expect(getByDescriptionTerm(component.container, transactionsLabel).textContent).toBe('2Payment=1Asset Transfer=1')
107-
expect(getByDescriptionTerm(component.container, previousRoundLabel).textContent).toBe((block.round - 1).toString())
108-
expect(getByDescriptionTerm(component.container, nextRoundLabel).textContent).toBe((block.round + 1).toString())
111+
await waitFor(() =>
112+
descriptionListAssertion({
113+
container: component.container,
114+
items: [
115+
{ term: roundLabel, description: block.round.toString() },
116+
{ term: timestampLabel, description: 'Thu, 29 February 2024 06:52:01' },
117+
{ term: transactionsLabel, description: '2Payment=1Asset Transfer=1' },
118+
{ term: previousRoundLabel, description: (block.round - 1).toString() },
119+
{ term: nextRoundLabel, description: (block.round + 1).toString() },
120+
],
121+
})
122+
)
109123

110124
const rows = getAllByRole(component.container, 'row')
111125
expect(rows.length).toBe(3)
112-
const transactionsRow1 = rows[1]
113-
const row1Cells = getAllByRole(transactionsRow1, 'cell')
114-
expect(row1Cells[0].textContent).toBe(ellipseId(transaction1.id))
115-
expect(row1Cells[1].textContent).toBe(ellipseId(transaction1.group))
116-
expect(row1Cells[2].textContent).toBe(ellipseAddress(transaction1.sender))
117-
expect(row1Cells[3].textContent).toBe(ellipseAddress(transaction1['payment-transaction']!.receiver))
118-
expect(row1Cells[4].textContent).toBe('Payment')
119-
expect(row1Cells[5].textContent).toBe((transaction1['payment-transaction']!.amount / 1e6).toString())
120126

121-
const transactionsRow2 = rows[2]
122-
const row2Cells = getAllByRole(transactionsRow2, 'cell')
123-
expect(row2Cells[0].textContent).toBe(ellipseId(transaction2.id))
124-
expect(row2Cells[1].textContent).toBe(ellipseId(transaction2.group))
125-
expect(row2Cells[2].textContent).toBe(ellipseAddress(transaction2.sender))
126-
expect(row2Cells[3].textContent).toBe(ellipseAddress(transaction2['asset-transfer-transaction']!.receiver))
127-
expect(row2Cells[4].textContent).toBe('Asset Transfer')
128-
expect(row2Cells[5].textContent).toBe(`${(transaction2['asset-transfer-transaction']!.amount as number) / 1e6} USDt`)
127+
tableAssertion({
128+
container: component.container,
129+
rows: [
130+
{
131+
cells: [
132+
ellipseId(transaction1.id),
133+
ellipseId(transaction1.group),
134+
ellipseAddress(transaction1.sender),
135+
ellipseAddress(transaction1['payment-transaction']!.receiver),
136+
'Payment',
137+
(transaction1['payment-transaction']!.amount / 1e6).toString(),
138+
],
139+
},
140+
{
141+
cells: [
142+
ellipseId(transaction2.id),
143+
ellipseId(transaction2.group),
144+
ellipseAddress(transaction2.sender),
145+
ellipseAddress(transaction2['asset-transfer-transaction']!.receiver),
146+
'Asset Transfer',
147+
`${(transaction2['asset-transfer-transaction']!.amount as number) / 1e6} USDt`,
148+
],
149+
},
150+
],
151+
})
129152
}
130153
)
131154
})

0 commit comments

Comments
 (0)