Skip to content

Commit

Permalink
migrate some methods to new lookup strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
antonborisoff committed Mar 26, 2024
1 parent 49ab66b commit 31d67b8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/app/components/contract/contract.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="flex-container-row full-height flex-container-content-center flex-container-items-center">
<mat-card
data-id="createEditFormContainer"
style="width: 30%"
appBusy="createEditForm">
<mat-card-content>
Expand Down
1 change: 1 addition & 0 deletions src/app/components/contracts/contracts.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div
data-id="dataContainer"
class="mat-elevation-z8 content-margin margin-top"
appBusy="contracts">
<mat-toolbar class="flex-container-row">
Expand Down
16 changes: 8 additions & 8 deletions src/app/components/contracts/tests/contracts.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('ContractsComponent', () => {
harnesses
} = await initComponent(CONTRACTS)

expect(await harnesses.router.component.matTableNRows('contractList')).toBe(getVisibleContracts(CONTRACTS).length)
await harnesses.router.component.expectMatTableNRows('contractList', getVisibleContracts(CONTRACTS).length)
for (const contract of getVisibleContracts(CONTRACTS)) {
await harnesses.router.component.inMatTableRow('contractList', {
number: contract.number
Expand All @@ -112,7 +112,7 @@ describe('ContractsComponent', () => {
harnesses
} = await initComponent([])

expect(await harnesses.router.component.matTableNRows('contractList')).toBe(0)
await harnesses.router.component.expectMatTableNRows('contractList', 0)
await harnesses.router.component.expectElementVisible('noContractsMessage', true)
})

Expand All @@ -139,7 +139,7 @@ describe('ContractsComponent', () => {
number: contractToDelete.number
}).clickElement('deleteContract')
await harnesses.router.component.messageBoxClick(MessageActions.CONFIRM)
expect(await harnesses.router.component.matTableNRows('contractList')).toBe(expectedContracts.length)
await harnesses.router.component.expectMatTableNRows('contractList', expectedContracts.length)
for (const expectedContract of expectedContracts) {
await harnesses.router.component.inMatTableRow('contractList', {
number: expectedContract.number
Expand All @@ -162,7 +162,7 @@ describe('ContractsComponent', () => {
number: contractToDelete.number
}).clickElement('deleteContract')
await harnesses.router.component.messageBoxClick(MessageActions.CANCEL)
expect(await harnesses.router.component.matTableNRows('contractList')).toBe(expectedContracts.length)
await harnesses.router.component.expectMatTableNRows('contractList', expectedContracts.length)
for (const expectedContract of expectedContracts) {
await harnesses.router.component.inMatTableRow('contractList', {
number: expectedContract.number
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('ContractsComponent', () => {
const contractToFind = CONTRACTS[5]

await harnesses.router.component.enterValue('contractSearchInput', contractToFind.number)
expect(await harnesses.router.component.matTableNRows('contractList')).toBe(1)
await harnesses.router.component.expectMatTableNRows('contractList', 1)
await harnesses.router.component.inMatTableRow('contractList', {
number: contractToFind.number
}).expectElementText('contractNumber', contractToFind.number)
Expand All @@ -225,12 +225,12 @@ describe('ContractsComponent', () => {
}).expectElementText('contractConditions', contractToFind.conditions)

await harnesses.router.component.enterValue('contractSearchInput', '')
expect(await harnesses.router.component.matTableNRows('contractList')).toBe(getVisibleContracts(CONTRACTS).length)
await harnesses.router.component.expectMatTableNRows('contractList', getVisibleContracts(CONTRACTS).length)

await harnesses.router.component.enterValue('contractSearchInput', 'some nono-existent contract number')
expect(await harnesses.router.component.matTableNRows('contractList')).toBe(0)
await harnesses.router.component.expectMatTableNRows('contractList', 0)

await harnesses.router.component.enterValue('contractSearchInput', '')
expect(await harnesses.router.component.matTableNRows('contractList')).toBe(getVisibleContracts(CONTRACTS).length)
await harnesses.router.component.expectMatTableNRows('contractList', getVisibleContracts(CONTRACTS).length)
})
})
17 changes: 11 additions & 6 deletions src/app/tests/foundation/base.component.harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class BaseHarness extends ComponentHarness {

protected getRootLoader(): HarnessLoader {
if (!this.rootLoader) {
console.error('root loader was not initialized')
throw new Error('root loader was not initialized')
}
return this.rootLoader
Expand Down Expand Up @@ -388,12 +389,16 @@ export class BaseHarness extends ComponentHarness {
return children.length
}

public async matTableNRows(id: string): Promise<number> {
const matTable = await this.locatorFor(MatTableHarness.with({
selector: this.getIdSelector(id)
}))()
const rows = await matTable.getRows()
return rows.length
public async expectMatTableNRows(id: string, nRows: number): Promise<void> {
await this.waitFor({
lookup: async () => {
const matTable = await this.locatorFor(MatTableHarness.with({
selector: this.getIdSelector(id)
}))()
return (await matTable.getRows()).length === nRows
},
errorMessage: `No mat table ${id} with ${nRows} rows found`
})
}

// +
Expand Down

0 comments on commit 31d67b8

Please sign in to comment.