Skip to content

Commit

Permalink
feat: CQDG-865 Add Clinical Data Cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Karine St-Onge committed Sep 12, 2024
1 parent 8f60b1d commit 4691f17
Show file tree
Hide file tree
Showing 10 changed files with 23,084 additions and 72 deletions.
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('PT0000010');
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', '**/file-manifest', 1);
cy.waitUntilFile(oneMinute);
});

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

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

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

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

it('Valider le contenu du fichier [CQDG-861]', () => {
cy.validateXlsxFileContent('DownloadClinicalDataFamily.json');
});
});
27 changes: 27 additions & 0 deletions cypress/e2e/Telechargement/ClinicalDataPageStudy.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// <reference types="cypress"/>
import '../../support/commands';
import { getDateTime, oneMinute } from '../../support/utils';

const { strDate } = getDateTime();

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

cy.login();
cy.visitStudyEntity('STUDY1', 1);
cy.get('[class*="EntityTitle"] button[class*="ant-btn-default"]').eq(0).click({force: true});
});

describe('Page d\'une étude - Télécharger le clinical data', () => {
beforeEach(() => {
cy.waitUntilFile(oneMinute);
});

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

it('Valider le contenu du fichier [CQDG-861]', () => {
cy.validateXlsxFileContent('DownloadClinicalDataFamily.json');
});
});
44 changes: 44 additions & 0 deletions cypress/e2e/Telechargement/ClinicalDataTableauParticipants.cy.ts
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=f586eafb-ed2d-4cde-8ac0-c0c44fa2a504');
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', '**/file-manifest', 1);
cy.waitUntilFile(oneMinute);
});

it('Valider le nom du fichier [CQDG-861]', () => {
cy.validateFileName(`cqdg_clinicalData_${strDate.slice(0, 4)}${strDate.slice(4, 6)}${strDate.slice(6, 8)}.xlsx`);
});

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

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

it('Valider le nom du fichier [CQDG-861]', () => {
cy.validateFileName(`cqdg_familyClinicalData_${strDate.slice(0, 4)}${strDate.slice(4, 6)}${strDate.slice(6, 8)}.xlsx`);
});

it('Valider le contenu du fichier [CQDG-861]', () => {
cy.validateXlsxFileContent('DownloadClinicalDataFamily.json');
});
});
36 changes: 36 additions & 0 deletions cypress/fixtures/DownloadClinicalData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ "content": ["Participant ID",
"External Participant ID",
"Family ID",
"External Family ID",
"Relationship to Proband",
"Study Name",
"Study Code",
"Family Type",
"Sex",
"Ethnicity",
"Vital Status",
"Affected Status",
"Age at Recruitment",
"Participant ID",
"External Participant ID",
"Family ID",
"External Family ID",
"Relationship to Proband",
"Phenotype (HPO)",
"Phenotype (Source Text)",
"Interpretation",
"Age at Phenotype Participant ID",
"External Participant ID",
"Family ID",
"External Family ID",
"Relationship to Proband",
"Diagnosis (MONDO)",
"Diagnosis (ICD)",
"Diagnosis (Source Text)",
"Age at Diagnosis Participant ID",
"External Participant ID",
"Family ID",
"External Family ID",
"Family Member ID",
"Relationship to Proband"]
}
30 changes: 30 additions & 0 deletions cypress/fixtures/DownloadClinicalDataFamily.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ "content": ["Participant ID",
"External Participant ID",
"Family ID",
"External Family ID",
"Relationship to Proband",
"Study Name",
"Study Code",
"Family Type",
"Sex",
"Ethnicity",
"Vital Status",
"Affected Status",
"Age at Recruitment Participant ID",
"External Participant ID",
"Family ID",
"External Family ID",
"Relationship to Proband",
"Phenotype (HPO)",
"Phenotype (Source Text)",
"Interpretation",
"Age at Phenotype Participant ID",
"External Participant ID",
"Family ID",
"External Family ID",
"Relationship to Proband",
"Diagnosis (MONDO)",
"Diagnosis (ICD)",
"Diagnosis (Source Text)",
"Age at Diagnosis"]
}
13 changes: 13 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 XLSX from 'xlsx';

require('dotenv').config();

Expand All @@ -20,6 +21,18 @@ module.exports = (on: Cypress.PluginEvents, config: Cypress.ConfigOptions) => {
});
});
},
async extractTextFromXLSX(filePath) {
const workbook = XLSX.readFile(filePath);
let text = '';

workbook.SheetNames.forEach(sheetName => {
const sheet = workbook.Sheets[sheetName];
const sheetText = XLSX.utils.sheet_to_csv(sheet);
text += sheetText;
});

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 @@ -397,6 +397,28 @@ Cypress.Commands.add('validateTotalSelectedQuery', (expectedCount: string|RegExp
cy.get('[class*="QueryBar_selected"]').find('[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 @@ -38,6 +38,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

0 comments on commit 4691f17

Please sign in to comment.