-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/additionalWindowsTests
- Loading branch information
Showing
9 changed files
with
285 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
integration_test/tests/src/page-objects/pages/SettlementsPage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { ReactSelector } from 'testcafe-react-selectors'; | ||
import { Temporal } from '@js-temporal/polyfill'; | ||
import { t } from 'testcafe'; | ||
|
||
// TODO: get this data from the application? Instead of using this data, use the actual text | ||
// displayed to the user, as the user would? | ||
export enum SettlementStatus { | ||
PendingSettlement = 'PENDING_SETTLEMENT', | ||
PsTransfersRecorded = 'PS_TRANSFERS_RECORDED', | ||
PsTransfersReserved = 'PS_TRANSFERS_RESERVED', | ||
PsTransfersCommitted = 'PS_TRANSFERS_COMMITTED', | ||
Settling = 'SETTLING', | ||
Settled = 'SETTLED', | ||
Aborted = 'ABORTED', | ||
} | ||
|
||
export type SettlementRow = { | ||
id: Selector, | ||
state: Selector, | ||
} | ||
|
||
const datePickerSelectDate = async ( | ||
t: TestController, | ||
datePicker: Selector, | ||
newDate: Temporal.PlainDate, | ||
) => { | ||
// TODO: the following code hangs for some reason. We should probably not make assumptions | ||
// about the default month displayed, instead we should call getReact() on the Month component | ||
// and use its props .months property to determine how many times we need to press the | ||
// back/forward button. As a user would do. | ||
// const { month } = await datePicker.findReact('Month').getReact().props; | ||
// | ||
// Assuming the current date is preselected as the default, calculate the number of times we | ||
// need to click the back button | ||
const today = Temporal.Now.plainDateISO(); | ||
const numberOfPresses = newDate.month - today.month + 12 * (newDate.year - today.year); | ||
const button = datePicker.find( | ||
numberOfPresses > 0 | ||
? '.daypicker-navbutton--next' | ||
: '.daypicker-navbutton--prev' | ||
); | ||
for (let i = 0; i < Math.abs(numberOfPresses); i += 1) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await t.click(button); | ||
} | ||
const dayKey = `${newDate.year}${newDate.month - 1}${newDate.day}`; | ||
await t.click(datePicker.findReact('Day').withKey(dayKey)); | ||
}; | ||
|
||
type Filters = | ||
| { fromDate: Temporal.PlainDate; toDate?: Temporal.PlainDate; state?: SettlementStatus } | ||
| { toDate: Temporal.PlainDate; fromDate?: Temporal.PlainDate; state?: SettlementStatus } | ||
| { state: SettlementStatus, toDate?: Temporal.PlainDate; fromDate?: Temporal.PlainDate }; | ||
|
||
export type WindowRow = { | ||
id: Selector, | ||
dfsp: Selector, | ||
debit: Selector, | ||
credit: Selector, | ||
viewNetPositionsButton: Selector, | ||
}; | ||
|
||
const modalRoot = ReactSelector('Modal').withProps({ title: 'Settlement Details' }); | ||
export const SettlementDetailModal = { | ||
async getWindowsRows(): Promise<WindowRow[]> { | ||
await t.expect(ReactSelector('Modal').exists).ok(); | ||
await t.expect(modalRoot.exists).ok(); | ||
const rows = modalRoot.findReact('DataList Rows').findReact('RowItem'); | ||
// This `expect` forces TestCafe to take a snapshot of the DOM. If we don't make this call, | ||
// rows.count always returns zero, and this function fails. | ||
await t.expect(rows.exists).ok(); | ||
const length = await rows.count; | ||
return Array | ||
.from({ length }) | ||
.map((_, i) => ({ | ||
dfsp: rows.nth(i).findReact('ItemCell').nth(0), | ||
id: rows.nth(i).findReact('ItemCell').nth(1), | ||
debit: rows.nth(i).findReact('ItemCell').nth(2), | ||
credit: rows.nth(i).findReact('ItemCell').nth(3), | ||
viewNetPositionsButton: rows.nth(i).findReact('ItemCell').nth(4).findReact('Button'), | ||
})); | ||
}, | ||
} | ||
|
||
export const SettlementsPage = { | ||
date: ReactSelector('Select').withProps({ placeholder: 'Date' }), | ||
|
||
fromDate: ReactSelector('DatePicker').withProps({ placeholder: 'From' }), | ||
fromDatePicker: ReactSelector('DatePicker').withProps({ placeholder: 'From' }).findReact('DayPicker'), | ||
|
||
toDate: ReactSelector('DatePicker').withProps({ placeholder: 'To' }), | ||
toDatePicker: ReactSelector('DatePicker').withProps({ placeholder: 'To' }).findReact('DayPicker'), | ||
|
||
state: ReactSelector('Select').withProps({ placeholder: 'State' }), | ||
clearFiltersButton: ReactSelector('Button').withProps({ label: 'Clear Filters' }), | ||
|
||
async getResultRows(): Promise<SettlementRow[]> { | ||
const rows = ReactSelector('DataList Rows').findReact('RowItem'); | ||
// This `expect` forces TestCafe to take a snapshot of the DOM. If we don't make this call, | ||
// rows.count always returns zero, and this function fails. | ||
await t.expect(rows.exists).ok(); | ||
const length = await rows.count; | ||
return Array | ||
.from({ length }) | ||
.map((_, i) => ({ | ||
id: rows.nth(i).findReact('ItemCell').nth(0), | ||
state: rows.nth(i).findReact('ItemCell').nth(1), | ||
})); | ||
}, | ||
|
||
async selectFiltersCustomDateRange(t: TestController, filters: Filters) { | ||
// TODO: how does the actual UI present dates? What happens if we run the tests in a different TZ? | ||
await t.click(this.clearFiltersButton); | ||
await t.click(this.date); | ||
// TODO: get 'Custom Range' from the application? | ||
await t.click(ReactSelector('Select Option').withProps({ label: 'Custom Range' })); | ||
|
||
if (filters.toDate) { | ||
await t.click(this.toDate); | ||
datePickerSelectDate(t, this.toDatePicker, filters.toDate); | ||
} | ||
|
||
if (filters.fromDate) { | ||
await t.click(this.fromDate); | ||
datePickerSelectDate(t, this.fromDatePicker, filters.fromDate); | ||
} | ||
|
||
if (filters.state) { | ||
await t.click(this.state); | ||
await t.click(this.state.findReact('Option').withProps({ value: filters.state })); | ||
} | ||
}, | ||
}; |
Oops, something went wrong.