Skip to content

Commit

Permalink
add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
bprize15 committed Nov 3, 2024
1 parent 7df2e6d commit 883995c
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/main/webapp/app/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
import { Col, Container, Row } from 'reactstrap';
import * as styles from './styles.module.scss';
import classNames from 'classnames';
import { getTabDataTestId } from 'app/shared/util/test-id-utils';

export type Tab = {
id?: string;
Expand All @@ -15,9 +16,10 @@ export interface ITabsProps {
isCollapsed?: boolean;
className?: string;
contentClassName?: string;
dataTestIdPrefix?: string;
}

const Tabs = ({ tabs, isCollapsed = false, defaultOpenTabIndex = 0, className, contentClassName }: ITabsProps) => {
const Tabs = ({ tabs, isCollapsed = false, defaultOpenTabIndex = 0, className, contentClassName, dataTestIdPrefix }: ITabsProps) => {
const [openTabIndex, setOpenTabIndex] = useState(defaultOpenTabIndex);

useEffect(() => {
Expand All @@ -37,6 +39,7 @@ const Tabs = ({ tabs, isCollapsed = false, defaultOpenTabIndex = 0, className, c
key={index}
style={{ marginRight: index !== tabs.length - 1 ? 16 : 0 }}
className={`${styles.tab} ${index === openTabIndex ? styles.selected : ''} col-sm-auto`}
data-testid={getTabDataTestId(index, dataTestIdPrefix)}
>
<h6>{tab.title}</h6>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/app/config/constants/html-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const REVIEW_PAGE_ID = 'review-page';
export const RCT_MODAL_BUTTON_ID = 'relevant-cancer-types-button';
export const RCT_MODAL_ID = 'relevant-cancer-type-modal';

// add mutation modal
export const DEFAULT_ADD_MUTATION_MODAL_ID = 'default-add-mutation-modal';
export const ADD_MUTATION_MODAL_INPUT_ID = 'add-mutation-modal-input';

Expand Down
22 changes: 21 additions & 1 deletion src/main/webapp/app/shared/modal/AddMutationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Select from 'react-select/dist/declarations/src/Select';
import InfoIcon from '../icons/InfoIcon';
import { Linkout } from '../links/Linkout';
import { SopPageLink } from '../links/SopPageLink';
import { AddMutationModalFieldTestIdType, getAddMuationModalFieldDataTestId } from '../util/test-id-utils';

type AlterationData = {
type: AlterationTypeEnum;
Expand Down Expand Up @@ -711,13 +712,15 @@ function AddMutationModal({
isLoading={_.isNil(excludingIndex) ? isFetchingAlteration : isFetchingExcludingAlteration}
placeholder="Input alteration"
onChange={newValue => handleAlterationChange(newValue, alterationIndex, excludingIndex)}
dataTestId={getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.ALTERATION, alterationIndex, excludingIndex)}
/>
{content}
<AddMutationModalField
label="Comment"
value={alterationData.comment}
placeholder="Input comment"
onChange={newValue => handleFieldChange(newValue, 'comment', alterationIndex, excludingIndex)}
dataTestId={getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.COMMENT, alterationIndex, excludingIndex)}
/>
{excludingSection}
</>
Expand All @@ -732,6 +735,7 @@ function AddMutationModal({
value={alterationData.name}
placeholder="Input name"
onChange={newValue => handleFieldChange(newValue, 'name', alterationIndex, excludingIndex)}
dataTestId={getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, alterationIndex, excludingIndex)}
/>
<AddMutationModalField
label="Protein Change"
Expand Down Expand Up @@ -782,6 +786,7 @@ function AddMutationModal({
value={alterationData.name}
placeholder="Input name"
onChange={newValue => handleFieldChange(newValue, 'name', alterationIndex, excludingIndex)}
dataTestId={getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, alterationIndex, excludingIndex)}
/>
<AddMutationModalField
label="Protein Change"
Expand All @@ -801,6 +806,7 @@ function AddMutationModal({
value={alterationData.name}
placeholder="Input name"
onChange={newValue => handleFieldChange(newValue, 'name', alterationIndex, excludingIndex)}
dataTestId={getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, alterationIndex, excludingIndex)}
/>
<AddMutationModalField
label="Protein Change"
Expand All @@ -820,6 +826,7 @@ function AddMutationModal({
value={alterationData.name}
placeholder="Input name"
onChange={newValue => handleFieldChange(newValue, 'name', alterationIndex, excludingIndex)}
dataTestId={getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, alterationIndex, excludingIndex)}
/>
</div>
);
Expand All @@ -833,6 +840,7 @@ function AddMutationModal({
value={alterationData.name}
placeholder="Input name"
onChange={newValue => handleFieldChange(newValue, 'name', alterationIndex, excludingIndex)}
dataTestId={getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, alterationIndex, excludingIndex)}
/>
<AddMutationModalField
label="Genes"
Expand All @@ -853,6 +861,7 @@ function AddMutationModal({
value={alterationData.name}
placeholder="Input name"
onChange={newValue => handleFieldChange(newValue, 'name', alterationIndex, excludingIndex)}
dataTestId={getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, alterationIndex, excludingIndex)}
/>
</div>
);
Expand Down Expand Up @@ -922,6 +931,7 @@ function AddMutationModal({
content: getTabContent(ex, alterationIndex, index),
}))}
isCollapsed={excludingCollapsed}
dataTestIdPrefix="excluding"
/>
</div>
</Col>
Expand Down Expand Up @@ -1117,9 +1127,18 @@ interface IAddMutationModalFieldProps {
onChange: (newValue: string) => void;
isLoading?: boolean;
disabled?: boolean;
dataTestId?: string;
}

function AddMutationModalField({ label, value: value, placeholder, onChange, isLoading, disabled }: IAddMutationModalFieldProps) {
function AddMutationModalField({
label,
value: value,
placeholder,
onChange,
isLoading,
disabled,
dataTestId,
}: IAddMutationModalFieldProps) {
return (
<div className="d-flex align-items-center mb-3">
<Col className="px-0 col-3 me-3 align-items-center">
Expand All @@ -1130,6 +1149,7 @@ function AddMutationModalField({ label, value: value, placeholder, onChange, isL
</Col>
<Col className="px-0">
<Input
data-testid={dataTestId}
disabled={disabled}
value={value}
onChange={event => {
Expand Down
21 changes: 21 additions & 0 deletions src/main/webapp/app/shared/util/test-id-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,24 @@ export enum CollapsibleDataTestIdType {
export function getCollapsibleDataTestId(dataTestid: CollapsibleDataTestIdType, identifier: string | undefined) {
return `${identifier}-${dataTestid}`;
}

export enum AddMutationModalFieldTestIdType {
ALTERATION = 'alteration',
NAME = 'name',
COMMENT = 'comment',
}

export function getAddMuationModalFieldDataTestId(
dataTestId: AddMutationModalFieldTestIdType,
alterationIndex: number,
excludingIndex: number | undefined,
) {
return `${dataTestId}-${alterationIndex}-${excludingIndex};`;
}

export function getTabDataTestId(index: number, prefix?: string) {
if (prefix) {
return `${prefix}-tab-${index}`;
}
return `${prefix}-tab-${index}`;
}
44 changes: 44 additions & 0 deletions src/test/javascript/data/api-annotate-alterations-v600g.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"entity": {
"id": null,
"type": "PROTEIN_CHANGE",
"name": "V600G",
"alteration": "V600G",
"proteinChange": "V600G",
"start": 600,
"end": 600,
"refResidues": "V",
"variantResidues": "G",
"flags": [],
"genes": [{ "id": 41135, "entrezGeneId": 673, "hugoSymbol": "BRAF", "hgncId": "1097" }],
"transcripts": [],
"consequence": {
"id": 16,
"term": "MISSENSE_VARIANT",
"name": "Missense Variant",
"isGenerallyTruncating": false,
"description": "A sequence variant, that changes one or more bases, resulting in a different amino acid sequence but where the length is preserved"
},
"associations": []
},
"message": "",
"type": "OK",
"queryId": "V600G",
"annotation": {
"hotspot": {
"associatedHotspots": [
{ "type": "HOTSPOT_V1", "alteration": "V600" },
{ "type": "THREE_D", "alteration": "V600" },
{ "type": "HOTSPOT_V1", "alteration": "V600" },
{ "type": "THREE_D", "alteration": "V600" }
],
"hotspot": true
},
"exons": [{ "range": { "start": 581, "end": 620 }, "exon": 15 }]
},
"warning": false,
"ok": true,
"error": false
}
]
5 changes: 4 additions & 1 deletion src/test/javascript/setup-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ const DATA_DIR = 'src/test/javascript/data/';

const getAlterationMockResponse = (requestBody: string, readFile = true) => {
const body = JSON.parse(requestBody);
const alterationName = body[0]?.alteration?.alteration?.toLowerCase();
const alterationName: string = body[0]?.alteration?.alteration?.toLowerCase();
let filePath = `${DATA_DIR}api-annotate-alterations-`;
switch (alterationName) {
case 'v600e':
filePath += alterationName;
break;
case 'v600g':
filePath += alterationName;
break;
default:
break;
}
Expand Down
8 changes: 5 additions & 3 deletions src/test/javascript/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { ADD_MUTATION_MODAL_INPUT_ID, DEFAULT_ADD_MUTATION_MODAL_ID } from '../../../main/webapp/app/config/constants/html-id';

export const createMutationOnCurationPage = async (mutationName: string) => {
export const addMutationInAddMutationModal = async (mutationName: string) => {
const mutationNameInput = await $(`input#${ADD_MUTATION_MODAL_INPUT_ID}`);
await mutationNameInput.setValue(mutationName);
await browser.keys('Enter');

const addMutationModal = await $(`div[id="${DEFAULT_ADD_MUTATION_MODAL_ID}"]`);
await addMutationModal.waitForDisplayed();
};

export const createMutationOnCurationPage = async (mutationName: string) => {
await addMutationInAddMutationModal(mutationName);

const modalConfirmBtn = await $('button=Confirm');
await modalConfirmBtn.click();

return { mutationNameInput, addMutationModal, modalConfirmBtn };
};
72 changes: 70 additions & 2 deletions src/test/javascript/spec/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ import {
import { BASE_URL, DATABASE_EMULATOR_URL, MOCK_DATA_JSON_FILE_PATH, PUB_MED_ARTICLE_TITLE, PUB_MED_PMID } from '../constants';
import * as fs from 'fs';
import * as admin from 'firebase-admin';
import { createMutationOnCurationPage } from '../shared/utils';
import { CollapsibleDataTestIdType, getCollapsibleDataTestId } from '../../../main/webapp/app/shared/util/test-id-utils';
import { addMutationInAddMutationModal, createMutationOnCurationPage } from '../shared/utils';
import {
AddMutationModalFieldTestIdType,
CollapsibleDataTestIdType,
getAddMuationModalFieldDataTestId,
getCollapsibleDataTestId,
getTabDataTestId,
} from '../../../main/webapp/app/shared/util/test-id-utils';

describe('End to end tests', () => {
let adminApp: admin.app.App;
Expand Down Expand Up @@ -138,4 +144,66 @@ describe('End to end tests', () => {
const reviewButton = await $(`button[data-testid="${GENE_HEADER_REVIEW_BUTTON_ID}"]`);
expect(await reviewButton.isExisting()).toBe(false);
});

it('should add mutation with name, comment, and excluding', async () => {
await browser.url(`${BASE_URL}/curation/EMPTYGENE/somatic`);

const addMutationButton = await $('button=Add Mutation');
await addMutationButton.waitForDisplayed();
await addMutationButton.click();

await addMutationInAddMutationModal('V600E/G [name] {excluding V600E} (comment)');

let alterationField = await $(
`input[data-testid='${getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.ALTERATION, 0, undefined)}']`,
);
expect(await alterationField.getValue()).toBe('V600E [name] {excluding V600E} (comment)');

let nameField = await $(
`input[data-testid='${getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, 0, undefined)}']`,
);
expect(await nameField.getValue()).toBe('name');

let commentField = await $(
`input[data-testid='${getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.COMMENT, 0, undefined)}']`,
);
expect(await commentField.getValue()).toBe('comment');

let excludingAlterationField = await $(
`input[data-testid='${getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, 0, 0)}']`,
);
expect(await excludingAlterationField.getValue()).toBe('V600E');

const secondTab = await $(`div[data-testid='${getTabDataTestId(1)}']`);
await secondTab.click();

alterationField = await $(
`input[data-testid='${getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.ALTERATION, 1, undefined)}']`,
);
expect(await alterationField.getValue()).toBe('V600G [name] {excluding V600E} (comment)');

nameField = await $(`input[data-testid='${getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, 1, undefined)}']`);
expect(await nameField.getValue()).toBe('name');

commentField = await $(
`input[data-testid='${getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.COMMENT, 1, undefined)}']`,
);
expect(await commentField.getValue()).toBe('comment');

excludingAlterationField = await $(
`input[data-testid='${getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, 1, 0)}']`,
);
expect(await excludingAlterationField.getValue()).toBe('V600E');

alterationField.setValue('V600E');
await commentField.waitUntil(async () => !(await commentField.getValue()));

nameField = await $(`input[data-testid='${getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.NAME, 1, undefined)}']`);
expect(await nameField.getValue()).toBe('V600E');

const nonExistantExcludingAlterationField = await $(
`input[data-testid='${getAddMuationModalFieldDataTestId(AddMutationModalFieldTestIdType.ALTERATION, 1, 0)}']`,
);
expect(await nonExistantExcludingAlterationField.isExisting()).toBeFalsy();
});
});

0 comments on commit 883995c

Please sign in to comment.