Skip to content

Commit

Permalink
Add flow test
Browse files Browse the repository at this point in the history
  • Loading branch information
Onitoxan committed Jan 15, 2025
1 parent 5feb1e2 commit 333951f
Show file tree
Hide file tree
Showing 13 changed files with 1,358 additions and 464 deletions.
36 changes: 36 additions & 0 deletions apps/hpc-ftsadmin-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,47 @@ Cypress.Commands.add('login', (username: string) => {
localStorage.setItem(STORAGE_KEY, JSON.stringify(dataWithUser));
});

type DatePickerDataTest = 'field' | 'today';
type ChildParent = 'child' | 'parent';
type Direction = 'source' | 'destination';
/**
* When removing `data-test` properties from code,
* please also remove it from here
*/
export type DataTest =
| 'add-flow-nav-button'
| 'add-flow-source-organization-field'
| 'add-flow-source-location-field'
| 'add-flow-source-usage-year-field'
| 'add-flow-destination-project-field'
| 'add-flow-destination-plan-field'
| 'add-flow-destination-global-cluster-field'
| 'add-flow-destination-usage-year-field'
| 'add-flow-destination-location-field'
| 'add-flow-destination-organization-field'
| 'add-flow-original-currency-funding-amount-field'
| 'add-flow-original-currency-field'
| 'add-flow-exchange-rate-field'
| 'add-flow-original-currency-button'
| 'add-flow-amount-USD-field'
| 'add-flow-description-field'
| 'add-flow-readonly-source-organization-field'
| 'add-flow-readonly-source-location-field'
| 'add-flow-readonly-source-usage-year-field'
| `add-flow-first-reported-${DatePickerDataTest}`
| `add-flow-decision-date-${DatePickerDataTest}`
| 'add-flow-flow-status-field'
| `add-flow-flow-date-${DatePickerDataTest}`
| `add-flow-reported-by-organization-${number}-options-${Direction}-${number}`
| `add-flow-reported-channel-field-${number}`
| `add-flow-date-reported-${DatePickerDataTest}-${number}`
| 'add-flow-create-button'
| 'add-flow-copy-button'
| 'add-flow-title'
| 'add-flow-add-parent-flow-button'
| `add-flow-add-${ChildParent}-flow-field`
| 'add-flow-add-parent-flow-submit-button'
| `add-flow-${ChildParent}-flow-table`
| 'flows-nav-button'
| 'flows-table'
| 'flows-table-checkbox'
Expand Down
58 changes: 33 additions & 25 deletions apps/hpc-ftsadmin-e2e/src/tests/add-flow.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as dayjs from 'dayjs';
import * as ADD_FLOW from '../fixtures/add-flow.json';
import { selectOption } from '../support/select-component-utils';

Expand All @@ -8,10 +9,10 @@ describe('hpc-ftsadmin add-flow', () => {
cy.visit('/');
cy.location('pathname').should('eq', '/flows');
cy.typedGet('add-flow-nav-button').click();
cy.location('pathname').should('eq', '/flow/add');
cy.location('pathname').should('eq', '/flows/add');
});

it('bulkRejectPendingFlows workflow', () => {
it('Add flow', () => {
cy.typedGet('add-flow-source-organization-field').type(
ADD_FLOW['test1']['add-flow-source-organization-field']
);
Expand All @@ -34,7 +35,7 @@ describe('hpc-ftsadmin add-flow', () => {
selectOption(ADD_FLOW['test1']['add-flow-destination-project-field']);

cy.typedGet('add-flow-destination-plan-field').should(
'contain',
'contain.html',
'Afghanistan 2002 (ITAP for the Afghan People)'
);
cy.typedGet('add-flow-destination-global-cluster-field').should(
Expand All @@ -43,7 +44,7 @@ describe('hpc-ftsadmin add-flow', () => {
);
cy.typedGet('add-flow-destination-usage-year-field').should(
'contain',
'2022'
'2002'
);
cy.typedGet('add-flow-destination-location-field').should(
'contain',
Expand All @@ -58,13 +59,11 @@ describe('hpc-ftsadmin add-flow', () => {
* Original Currency related testing
*/

cy.typedGet('add-flow-original-currency-dropdown').click();

cy.typedGet('add-flow-original-currency-funding-amount-field').type(
ADD_FLOW['test1']['add-flow-original-currency-funding-amount-field']
);
cy.typedGet('add-flow-original-currency-field').click();
selectOption('LAK');
selectOption('EUR');

cy.typedGet('add-flow-exchange-rate-field').type(
ADD_FLOW['test1']['add-flow-exchange-rate-field']
Expand Down Expand Up @@ -99,6 +98,7 @@ describe('hpc-ftsadmin add-flow', () => {
'contain.text',
'Calculate the exchange rate'
);

/*
* --------------------------------------------------------
*/
Expand All @@ -107,22 +107,23 @@ describe('hpc-ftsadmin add-flow', () => {
ADD_FLOW['test1']['add-flow-description-field']
);

const date = new Date().toLocaleDateString('en-GB');
cy.typedGet('add-flow-first-reported-field').type(date);
cy.typedGet('add-flow-decision-date-field').type(date);
const date = dayjs().format('DD/MM/YYYY');
cy.typedGet('add-flow-first-reported-today').click();
cy.typedGet('add-flow-decision-date-today').click();

cy.typedGet('add-flow-flow-status-field').click();
selectOption('Commitment');

cy.typedGet('add-flow-flow-date-field').type(date);
cy.typedGet('add-flow-flow-date-today').click();

// Properly write
cy.typedGet('add-flow-reported-by-organization-options').click();
cy.typedGet(
'add-flow-reported-by-organization-0-options-destination-0'
).click();

cy.typedGet('add-flow-reported-channel-field').click();
cy.typedGet('add-flow-reported-channel-field-0').click();
selectOption('Fax');

cy.typedGet('add-flow-date-reported-field').should('contain', date);
cy.typedGet('add-flow-date-reported-field-0').should('contain.html', date);

cy.typedGet('add-flow-create-button').click();

Expand All @@ -132,20 +133,27 @@ describe('hpc-ftsadmin add-flow', () => {

cy.typedGet('add-flow-add-parent-flow-button').click();

// TODO: Get previous flow ID
cy.typedGet('add-flow-add-parent-flow-field').type('PREVIOUS FLOW ID');
selectOption('PREVIOUS FLOW ID');
// flow 316064 is part of mocked data
cy.typedGet('add-flow-add-parent-flow-field').type('316064');
selectOption('316064');

cy.typedGet('add-flow-add-parent-flow-submit-button').click();

cy.typedGet('add-flow-parent-flow-table').should('exist');
});

/**
* TODO: Add more checking to the test once edit flow is in the app
*/
it('Enter pending-flow', () => {
cy.typedGet('flows-table-row-305776v1').click();
cy.location('pathname').should('eq', '/flows/305776');
// Verify source data gets updated when
// a parent flow is selected
cy.typedGet('add-flow-readonly-source-organization-field').should(
'contain',
'United States of America, Government of [USA]'
);
cy.typedGet('add-flow-readonly-source-usage-year-field').should(
'contain',
'2023'
);
cy.typedGet('add-flow-readonly-source-location-field').should(
'contain',
'United States'
);
});
});
1 change: 1 addition & 0 deletions apps/hpc-ftsadmin/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const App = () => {
path: paths.addFlow(),
icon: MdAdd,
selected: false,
dataTest: 'add-flow-nav-button',
},
]}
className={CLASSES.CONTAINER.FLUID}
Expand Down
Loading

0 comments on commit 333951f

Please sign in to comment.