Skip to content

Commit

Permalink
Add add-flow initial test
Browse files Browse the repository at this point in the history
  • Loading branch information
Onitoxan committed Nov 14, 2024
1 parent 0c118a9 commit fc993e1
Show file tree
Hide file tree
Showing 14 changed files with 540 additions and 20 deletions.
14 changes: 14 additions & 0 deletions apps/hpc-ftsadmin-e2e/src/fixtures/add-flow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"test1": {
"add-flow-source-organization-field": "Germany, Government of",
"add-flow-source-usage-year-field": "2022",
"add-flow-destination-project-field": "apts627",
"add-flow-amount-USD-field": "8994018977",
"add-flow-original-currency-funding-amount-field": "200000000000000",
"add-flow-exchange-rate-field": "22237",
"add-flow-description-field": "GV, WASH EDU",
"add-flow-flow-status-field": "Commitment",
"add-flow-earmarking-field": "Unearmarked",
"add-flow-report-channel-field": "Other"
}
}
63 changes: 63 additions & 0 deletions apps/hpc-ftsadmin-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare global {
interface Chainable<Subject> {
login(username: string): void;
getDummyData(): DummyData;
typedGet(dataTest: DataTest): Cypress.Chainable<JQuery<HTMLElement>>;
}
}
}
Expand Down Expand Up @@ -60,3 +61,65 @@ Cypress.Commands.add('login', (username: string) => {
const dataWithUser = { ...parsedData, currentUser: userIds[0] };
localStorage.setItem(STORAGE_KEY, JSON.stringify(dataWithUser));
});

/*
* When removing data-test properties from code,
* please also remove it from here
*/
export type DataTest =
| 'flows-nav-button'
| 'flows-table'
| 'flows-table-checkbox'
| 'flows-table-id'
| 'flows-table-status'
| 'flows-table-updated'
| 'flows-table-external-reference'
| 'flows-table-amount-usd'
| 'flows-table-source-organization'
| 'flows-table-destination-organization'
| 'flows-table-plans'
| 'flows-table-locations'
| 'flows-table-years'
| 'flows-table-details'
| 'flows-table-newMoney'
| 'flows-table-decisionDate'
| 'flows-table-exchangeRate'
| 'flows-table-flowDate'
| 'flows-table-sourceSystemId'
| 'flows-table-reporterRefCode'
| 'flows-table-exchangeRate'
| 'flows-table-pagination'
| `flows-table-row-${number}v${number}` // flow.id v flow.versionID
| `flows-table-header-${string}` // TableHeadersProps<FlowHeaderID>.label as value
| 'pending-flows-nav-button'
| 'pending-flows-bulk-reject-button'
| 'keywords-nav-button'
| 'keywords-table-id'
| 'keywords-table-name'
| 'keywords-table-relatedFlows'
| 'keywords-table-public'
| `keywords-table-row-${number}` // keyword.id
| `keywords-table-header-${string}` // TableHeadersProps<KeywordHeaderID>.label as value
| 'organizations-nav-button'
| 'organizations-table-id'
| 'organizations-table-name'
| 'organizations-table-abbreviation'
| 'organizations-table-type'
| 'organizations-table-subType'
| 'organizations-table-location'
| 'organizations-table-created-by'
| 'organizations-table-updated-by'
| `keywords-table-row-${number}` // organization.id
| `organizations-table-header-${string}` // TableHeadersProps<OrganizationHeaderID>.label as value
| 'organizations-table-pagination';

/*
* Command that makes the same as cy.get()
* but we use it for known elements.
*
* Ex: <div data-test="test"> test </div>
* Our type for dataTest will define "test" as a possible value
*/
Cypress.Commands.add('typedGet', (dataTest: DataTest) => {
return cy.get(`[data-test="${dataTest}"]`);
});
3 changes: 3 additions & 0 deletions apps/hpc-ftsadmin-e2e/src/support/select-component-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const selectOption = (option: string) => {
cy.contains('li', option).click();
};
151 changes: 151 additions & 0 deletions apps/hpc-ftsadmin-e2e/src/tests/add-flow.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import * as ADD_FLOW from '../fixtures/add-flow.json';
import { selectOption } from '../support/select-component-utils';

describe('hpc-ftsadmin add-flow', () => {
beforeEach(() => {
cy.visit('/');
cy.login('Admin User');
cy.visit('/');
cy.location('pathname').should('eq', '/flows');
cy.typedGet('add-flow-nav-button').click();
cy.location('pathname').should('eq', '/flow/add');
});

it('bulkRejectPendingFlows workflow', () => {
cy.typedGet('add-flow-source-organization-field').type(
ADD_FLOW['test1']['add-flow-source-organization-field']
);
selectOption(ADD_FLOW['test1']['add-flow-source-organization-field']);

cy.typedGet('add-flow-source-organization-field').should(
'contain',
ADD_FLOW['test1']['add-flow-source-organization-field']
);
cy.typedGet('add-flow-source-location-field').should('contain', 'Germany');

cy.typedGet('add-flow-source-usage-year-field').type(
ADD_FLOW['test1']['add-flow-source-usage-year-field']
);
selectOption(ADD_FLOW['test1']['add-flow-source-usage-year-field']);

cy.typedGet('add-flow-destination-project-field').type(
ADD_FLOW['test1']['add-flow-destination-project-field']
);
selectOption(ADD_FLOW['test1']['add-flow-destination-project-field']);

cy.typedGet('add-flow-destination-plan-field').should(
'contain',
'Afghanistan 2002 (ITAP for the Afghan People)'
);
cy.typedGet('add-flow-destination-global-cluster-field').should(
'contain',
'Multi-sector'
);
cy.typedGet('add-flow-destination-usage-year-field').should(
'contain',
'2022'
);
cy.typedGet('add-flow-destination-location-field').should(
'contain',
'Afghanistan'
);
cy.typedGet('add-flow-destination-organization-field').should(
'contain',
"United Nations Children's Fund"
);

/*
* 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');

cy.typedGet('add-flow-exchange-rate-field').type(
ADD_FLOW['test1']['add-flow-exchange-rate-field']
);

cy.typedGet('add-flow-original-currency-button').should(
'contain.text',
'Calculate the funding amount in USD'
);
cy.typedGet('add-flow-original-currency-funding-amount-field').clear();

cy.typedGet('add-flow-amount-USD-field').type(
ADD_FLOW['test1']['add-flow-amount-USD-field']
);

cy.typedGet('add-flow-original-currency-button').should(
'contain.text',
'Calculate funding amount in its original currency'
);

cy.typedGet('add-flow-exchange-rate-field').clear();
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-button').should(
'contain.text',
'Calculate the exchange rate'
);

cy.typedGet('add-flow-original-currency-button').should(
'contain.text',
'Calculate the exchange rate'
);
/*
* --------------------------------------------------------
*/

cy.typedGet('add-flow-description-field').type(
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);

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

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

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

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

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

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

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

cy.typedGet('add-flow-title').should('contain', 'Copy');

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');

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');
});
});
File renamed without changes.
30 changes: 30 additions & 0 deletions apps/hpc-ftsadmin-e2e/src/tests/pending-flow.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe('hpc-ftsadmin pending-flow', () => {
beforeEach(() => {
cy.visit('/');
cy.login('Admin User');
cy.visit('/');
cy.location('pathname').should('eq', '/flows');
cy.typedGet('pending-flows-nav-button').click();
cy.location('pathname').should('eq', '/pending-flows');
});

it('bulkRejectPendingFlows workflow', () => {
cy.typedGet('flows-table')
.find('input[type="checkbox"]')
.each(($checkbox) => {
cy.wrap($checkbox).click();
});

cy.typedGet('pending-flows-bulk-reject-button').click();
cy.contains('No results found');
cy.typedGet('flows-table').should('not.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');
});
});
7 changes: 6 additions & 1 deletion apps/hpc-ftsadmin-e2e/tsconfig.e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
"allowJs": true,
"composite": true
},
"include": ["**/*.ts", "**/*.js", "../../libs/hpc-dummy/src/index.ts"]
"include": [
"**/*.ts",
"**/*.js",
"../../libs/hpc-dummy/src/index.ts",
"./src/fixtures/*.json"
]
}
4 changes: 4 additions & 0 deletions apps/hpc-ftsadmin/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,22 @@ export const App = () => {
{
label: t.t(lang, (s) => s.navigation.flows),
path: paths.flows(),
dataTest: 'flows-nav-button',
},
{
label: t.t(lang, (s) => s.navigation.pendingFlows),
path: paths.pendingFlows(),
dataTest: 'pending-flows-nav-button',
},
{
label: t.t(lang, (s) => s.navigation.organizations),
path: paths.organizations(),
dataTest: 'organizations-nav-button',
},
{
label: t.t(lang, (s) => s.navigation.keywords),
path: paths.keywords(),
dataTest: 'keywords-nav-button',
},
]}
className={CLASSES.CONTAINER.FLUID}
Expand Down
6 changes: 4 additions & 2 deletions apps/hpc-ftsadmin/src/app/components/tables/flows-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export default function FlowsTable(props: FlowsTableProps) {
? tw`bg-unocha-primary bg-opacity-10`
: undefined,
}}
data-test={`flows-table-row-${row.id}v${row.versionID}`}
>
{props.pending && (
<TableCell
Expand Down Expand Up @@ -636,7 +637,7 @@ export default function FlowsTable(props: FlowsTableProps) {
<TableCell
size="small"
key={`${header.identifierID}_${header.label}`}
data-test={`header-${header.label}`}
data-test={`flows-table-header-${header.label}`}
{...(header.sortable &&
query.orderBy === header.identifierID && {
'aria-sort':
Expand Down Expand Up @@ -677,7 +678,7 @@ export default function FlowsTable(props: FlowsTableProps) {
})}
</TableRow>
</TableHead>
<TableBody>
<TableBody data-test="flows-table">
<TableRowsComponent lang={lang} data={data} />
</TableBody>
<TableFooter />
Expand Down Expand Up @@ -750,6 +751,7 @@ export default function FlowsTable(props: FlowsTableProps) {
(s) => s.components.flowsTable.rejectPendingFlows.button
)}
displayLoading={loading}
dataTest="pending-flows-bulk-reject-button"
onClick={() => submitForm()}
/>
}
Expand Down
Loading

0 comments on commit fc993e1

Please sign in to comment.