Skip to content

Commit

Permalink
Merge branch 'master' into feature/additionalWindowsTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sridevi Miriyala committed Aug 26, 2021
2 parents 3370431 + 1f3da9b commit 3c853eb
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 48 deletions.
4 changes: 2 additions & 2 deletions integration_test/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
resources:
- github.com/partiallyordered/mojaloop-kustomize/base/nginx-ingress-controller?ref=ee2ffcc2588dcefda74ed6b4f2e47a7388f67f4e
- github.com/partiallyordered/mojaloop-kustomize/base/mojaloop/central?ref=49fb1e37d817a757ff7d172c29b84f31bfb20cc3
- github.com/partiallyordered/mojaloop-kustomize/base/mojaloop/central?ref=9334e91098cc318f79720504cc8beffb537639e2
- manifests/portal-frontend
- github.com/partiallyordered/voodoo-doll/kubernetes?ref=dacd3ab92b4b39e8a0df9bc69e946b087ac06b90
- github.com/partiallyordered/voodoo-doll/kubernetes?ref=bb9fd03ad90be34771b46088128c167bfb9ab70a
- github.com/mojaloop/wso2is-populate/integration_test/manifests/wso2is?ref=v2.0.4
- github.com/mojaloop/wso2is-populate/integration_test/manifests/wso2is-populate?ref=v2.0.4

Expand Down
40 changes: 27 additions & 13 deletions integration_test/tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration_test/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"axios": "^0.21.1",
"dotenv": "^9.0.2",
"env-var": "^7.0.1",
"mojaloop-voodoo-client": "0.4.1",
"mojaloop-voodoo-client": "0.5.0",
"promise.any": "^2.0.2",
"request": "2.88.2",
"testcafe": "1.15.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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?
Expand All @@ -11,6 +12,12 @@ export enum SettlementWindowStatus {
Aborted = 'ABORTED',
}

export type SettlementWindowRow = {
id: Selector,
closeButton: Selector,
checkbox: Selector,
}

const datePickerSelectDate = async (
t: TestController,
datePicker: Selector,
Expand Down Expand Up @@ -44,6 +51,11 @@ type Filters =
| { toDate: Temporal.PlainDate; fromDate?: Temporal.PlainDate; state?: SettlementWindowStatus }
| { state: SettlementWindowStatus, toDate?: Temporal.PlainDate; fromDate?: Temporal.PlainDate };

export const SettlementWindowsSettlementModal = {
viewSubmittedSettlementsButton: ReactSelector('SettlementWindowModal').findReact('Button').withText('View Submitted Settlements'),
continueViewingWindowsButton: ReactSelector('SettlementWindowModal').findReact('Button').withText('Continue Viewing Windows'),
};

export const SettlementWindowsPage = {
date: ReactSelector('Select').withProps({ placeholder: 'Date' }),

Expand All @@ -56,7 +68,22 @@ export const SettlementWindowsPage = {
state: ReactSelector('Select').withProps({ placeholder: 'State' }),
clearFiltersButton: ReactSelector('Button').withProps({ label: 'Clear Filters' }),

resultRows: ReactSelector('DataList Rows').findReact('RowItem'),
settleWindowsButton: ReactSelector('Button').withText('Settle Selected Windows'),

async getResultRows(): Promise<SettlementWindowRow[]> {
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) => ({
closeButton: rows.nth(i).findReact('Button'),
id: rows.nth(i).findReact('ItemCell').nth(1),
checkbox: rows.nth(i).findReact('ItemCell').withKey('_checkbox_column'),
}));
},

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?
Expand Down
133 changes: 133 additions & 0 deletions integration_test/tests/src/page-objects/pages/SettlementsPage.ts
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 }));
}
},
};
Loading

0 comments on commit 3c853eb

Please sign in to comment.