Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: SKFP-1276 Add Clinical Data Cypress tests #4117

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions cypress/e2e/Telechargement/ClinicalDataPageParticipant.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// <reference types="cypress"/>
import '../../support/commands';
import { getDateTime, oneMinute } from '../../support/utils';

const { strDate } = getDateTime();

beforeEach(() => {
cy.removeFilesFromFolder(Cypress.config('downloadsFolder'));

cy.login();
cy.visitParticipantEntity('PT_01236T3G');
cy.get('[class*="EntityTitle"] button[class*="ant-dropdown-trigger"]').click({force: true});
});

describe('Page d\'un participant - Télécharger le clinical data', () => {
beforeEach(() => {
cy.clickAndIntercept('[data-menu-id*="-clinicalData"]', 'POST', '**/clinical-data', 1);
cy.waitUntilFile(oneMinute);
});

it('Valider le nom du fichier', () => {
cy.validateFileName(`kf_clinicalData_${strDate.slice(0, 4)}${strDate.slice(4, 6)}${strDate.slice(6, 8)}T*.xlsx`);
});

it('Valider le contenu du fichier [SKFP-1277]', () => {
cy.validateXlsxFileContent('DownloadClinicalData.json');
});
});

describe('Page d\'un participant - Télécharger le clinical data (family)', () => {
beforeEach(() => {
cy.clickAndIntercept('[data-menu-id*="-familyClinicalData"]', 'POST', '**/family-clinical-data', 1);
cy.waitUntilFile(oneMinute);
});

it('Valider le nom du fichier', () => {
cy.validateFileName(`kf_familyClinicalData_${strDate.slice(0, 4)}${strDate.slice(4, 6)}${strDate.slice(6, 8)}T*.xlsx`);
});

it('Valider le contenu du fichier [SKFP-1277]', () => {
cy.validateXlsxFileContent('DownloadClinicalDataFamily.json');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/// <reference types="cypress"/>
import '../../support/commands';
import { getDateTime, oneMinute } from '../../support/utils';

const { strDate } = getDateTime();

beforeEach(() => {
cy.removeFilesFromFolder(Cypress.config('downloadsFolder'));

cy.login();
cy.visitDataExploration('participants', '?sharedFilterId=c80e4b42-a3e3-4525-a425-933b44eafef9');
cy.get('div[role="tabpanel"] [class*="ant-table-row"]').eq(0).find('[type="checkbox"]').check({force: true});
cy.get('[class*="Header_ProTableHeader"] button[class*="ant-dropdown-trigger"]').eq(1).click({force: true});
});

describe('Page Data Exploration (Participants) - Télécharger le clinical data', () => {
beforeEach(() => {
cy.clickAndIntercept('[data-menu-id*="-clinicalData"]', 'POST', '**/clinical-data', 1);
cy.waitUntilFile(oneMinute);
});

it('Valider le nom du fichier', () => {
cy.validateFileName(`kf_clinicalData_${strDate.slice(0, 4)}${strDate.slice(4, 6)}${strDate.slice(6, 8)}T*.xlsx`);
});

it('Valider le contenu du fichier [SKFP-1277]', () => {
cy.validateXlsxFileContent('DownloadClinicalData.json');
});
});

describe('Page Data Exploration (Participants) - Télécharger le clinical data (family)', () => {
beforeEach(() => {
cy.clickAndIntercept('[data-menu-id*="-familyClinicalData"]', 'POST', '**/family-clinical-data', 1);
cy.waitUntilFile(oneMinute);
});

it('Valider le nom du fichier', () => {
cy.validateFileName(`kf_familyClinicalData_${strDate.slice(0, 4)}${strDate.slice(4, 6)}${strDate.slice(6, 8)}T*.xlsx`);
});

it('Valider le contenu du fichier [SKFP-1277]', () => {
cy.validateXlsxFileContent('DownloadClinicalDataFamily.json');
});
});
46 changes: 46 additions & 0 deletions cypress/fixtures/DownloadClinicalData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ "content": ["Participant ID",
"External Participant ID",
"Family ID",
"Proband",
"Study Name",
"Study Code",
"Family Composition",
"Sex",
"Race",
"Ethnicity",
"Vital Status",
"Age at Last Vital Status (Days)",
"PT_01236T3G",
"01-0665",
"FM_Z4Y7FP70",
"Yes",
"Kids First: Genomic Analysis of Congenital Diaphragmatic Hernia",
"KF-CDH",
"trio",
"female",
"White",
"Not Hispanic or Latino",
"Deceased",
"Phenotype (HPO)",
"Phenotype (Source Text)",
"Interpretation",
"Age at Phenotype Assignment (Days)",
"Congenital diaphragmatic hernia (HP:0000776)",
"congential diaphragmatic hernia",
"Observed",
"congenital diaphragmatic hernia",
"Diagnosis (MONDO)",
"Diagnosis (NCIT)",
"Diagnosis (Source Text)",
"Age at Diagnosis (Days)",
"Tumor Location (Source Text)",
"congenital diaphragmatic hernia (MONDO:0005711)",
"Congenital Diaphragmatic Hernia (NCIT:C98893)",
"Not Reported",
"Family Role",
"PT_1DYA8779",
"mother",
"PT_RZVC67GC",
"father",
"--"]
}
51 changes: 51 additions & 0 deletions cypress/fixtures/DownloadClinicalDataFamily.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{ "content": ["Participant ID",
"External Participant ID",
"Family ID",
"Proband",
"Study Name",
"Study Code",
"Family Composition",
"Family Role",
"Sex",
"Race",
"Ethnicity",
"Vital Status",
"Age at Last Vital Status (Days)",
"PT_01236T3G",
"01-0665",
"FM_Z4Y7FP70",
"Yes",
"Kids First: Genomic Analysis of Congenital Diaphragmatic Hernia",
"KF-CDH",
"trio",
"female",
"White",
"Not Hispanic or Latino",
"Deceased",
"PT_1DYA8779",
"667",
"No",
"mother",
"PT_RZVC67GC",
"668",
"father",
"male",
"Phenotype (HPO)",
"Phenotype (Source Text)",
"Interpretation",
"Age at Phenotype Assignment (Days)",
"Congenital diaphragmatic hernia (HP:0000776)",
"congential diaphragmatic hernia",
"Observed",
"congenital diaphragmatic hernia",
"Not Observed",
"Diagnosis (MONDO)",
"Diagnosis (NCIT)",
"Diagnosis (Source Text)",
"Age at Diagnosis (Days)",
"Tumor Location (Source Text)",
"congenital diaphragmatic hernia (MONDO:0005711)",
"Congenital Diaphragmatic Hernia (NCIT:C98893)",
"Not Reported",
"--"]
}
18 changes: 18 additions & 0 deletions cypress/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// <reference types="cypress"/>
import fs, { rmdir } from 'fs';
import path from 'path';
import ExcelJS from 'exceljs';

require('dotenv').config();

Expand All @@ -20,6 +21,23 @@ module.exports = (on: Cypress.PluginEvents, config: Cypress.ConfigOptions) => {
});
});
},
async extractTextFromXLSX(filePath) {
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(filePath);

let text = '';

workbook.eachSheet((worksheet) => {
worksheet.eachRow((row) => {
const rowValues = Array.isArray(row.values)
? row.values.map((value: any) => value || '').slice(1)
: [];
text += rowValues.join(',') + '\n';
});
});

return text;
},
fileExists(folder) {
const files = fs.readdirSync(folder);
const regex = new RegExp('.*');
Expand Down
22 changes: 22 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,28 @@ Cypress.Commands.add('validateTotalSelectedQuery', (expectedCount: string|RegExp
cy.get('[class*="QueryBar_selected"] [class*="QueryBar_total"]').contains(expectedCount).should('exist');
});

Cypress.Commands.add('validateXlsxFileContent', (fixture: string, replacements?: Replacement[]) => {
const arrReplacements = replacements !== undefined ? replacements : [];
cy.fixture(fixture).then((expectedData) => {
cy.exec(`/bin/ls ${Cypress.config('downloadsFolder')}/*.xlsx`).then((result) => {
const filename = result.stdout.trim();
cy.task('extractTextFromXLSX', filename).then((file) => {
let fileWithData = typeof file === 'string' ? file : '';
arrReplacements.forEach((replacement) => {
fileWithData = fileWithData.replace(replacement.placeholder, replacement.value);
});
expectedData.content.forEach((value: any) => {
let valueWithData = value;
arrReplacements.forEach((replacement) => {
valueWithData = valueWithData.replace(replacement.placeholder, replacement.value);
});
assert.include(fileWithData, valueWithData);
});
});
});
});
});

Cypress.Commands.add('visitAndIntercept', (url: string, methodHTTP: string, routeMatcher: string, nbCalls: number) => {
cy.intercept(methodHTTP, routeMatcher).as('getRouteMatcher');

Expand Down
1 change: 1 addition & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ declare namespace Cypress {
validateTableFirstRow(expectedValue: string|RegExp, eq: number, hasCheckbox: boolean = false): cy & CyEventEmitter;
validateTableResultsCount(expectedCount: string|RegExp, shouldExist: boolean = true): cy & CyEventEmitter;
validateTotalSelectedQuery(expectedCount: string|RegExp): cy & CyEventEmitter;
validateXlsxFileContent(fixture: string, replacements?: Replacement[]): cy & CyEventEmitter;
visitAndIntercept(url: string, methodHTTP: string, routeMatcher: string, nbCalls: number): cy & CyEventEmitter;
visitCommunityPage(): cy & CyEventEmitter;
visitDashboard(): cy & CyEventEmitter;
Expand Down
Loading
Loading