Skip to content

Commit

Permalink
cde-42 completed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimaoBolota-MetaCell committed Apr 30, 2024
1 parent 540d434 commit 04ec753
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 10 deletions.
6 changes: 6 additions & 0 deletions tests/e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"test": "tests"
},
"scripts": {
"test": "sleep 30 && jest --verbose ControlPanel Intensity SocialContextMap Viewer",
"test": "sleep 30 && jest --verbose Template Dataset",
"puppeteer_test": "jest --verbose"
},
"author": "",
"license": "ISC",
"dependencies": {
"csv-parser": "^3.0.0",
"csv-writer": "^1.6.0",
"jest": "^28.1.3",
"jest-puppeteer": "^6.2.0",
"puppeteer": "^13.7.0",
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/tests/DatasetMapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('CDE: Dataset Mapping Test', () => {
await dm_test_page.click('#submitButton')
await dm_test_page.waitForSelector('.mapping__start-btn', { hidden: false, timeout: TIMEOUT });
await dm_test_page.click('.mapping__start-btn');
await dm_test_page.waitForSelector('.repository__select-btn', { hidden: false, timeout: TIMEOUT });
await dm_test_page.waitForSelector('.collection__select-btn', { hidden: false, timeout: TIMEOUT });
console.log('Files submitted successfully');
})

Expand All @@ -119,10 +119,10 @@ describe('CDE: Dataset Mapping Test', () => {
describe('Select Repo', () => {
test('Select default repo', async () => {
console.log('Selecting default repo ...')
await dm_test_page.waitForSelector('.repository__select-btn', { hidden: false, timeout: TIMEOUT });
await dm_test_page.waitForSelector('.collection__select-btn', { hidden: false, timeout: TIMEOUT });
await dm_test_page.waitForSelector('button[title="Skip tutorial"]', { hidden: false, timeout: TIMEOUT })
await dm_test_page.click('button[title="Skip tutorial"]')
await dm_test_page.click('.repository__select-btn');
await dm_test_page.click('.collection__select-btn');
await dm_test_page.waitForSelector('.cde-suggestions__content', { hidden: false, timeout: TIMEOUT });
console.log('Default repo selected successfully');

Expand Down
92 changes: 86 additions & 6 deletions tests/e2e/tests/TemplateCreation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ expect.extend({ toMatchImageSnapshot })
const fs = require('fs');

Check failure on line 5 in tests/e2e/tests/TemplateCreation.test.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Require statement not part of import statement
const path = require('path');

Check failure on line 6 in tests/e2e/tests/TemplateCreation.test.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Require statement not part of import statement
import * as csv from 'csv-parser';
import { createObjectCsvWriter } from 'csv-writer';


const URL = process.env.url || "https://cde-mapper.dev.metacell.us/";
Expand Down Expand Up @@ -278,7 +279,7 @@ describe('CDE: Template Creation Test', () => {
selector,
'Aut_Test_dataset'
);

await tc_test_page.waitForFunction(
(selector, delay) => {
return new Promise((resolve) => {
Expand All @@ -297,7 +298,7 @@ describe('CDE: Template Creation Test', () => {
},
{ timeout: TIMEOUT },
selector,
15000
15000
);

await tc_test_page.waitForSelector('.MuiBox-root li', { hidden: false, timeout: TIMEOUT })
Expand Down Expand Up @@ -342,17 +343,96 @@ describe('CDE: Template Creation Test', () => {
})
})

describe.skip('Check Template', () => {
describe('Check Template', () => {

test('Check CSV data', async () => {
console.log('Checking CSV data ...')

await tc_test_page.waitForSelector('div > div.MuiStack-root > div.MuiBox-root:nth-child(2)', { timeout: TIMEOUT, hidden: false });
const selectedcde = await tc_test_page.$eval('div > div.MuiStack-root > div.MuiBox-root:nth-child(2)', element => element.textContent);

console.log('CSV data checked successfully');
})
})

const downloadPath = path.resolve(__dirname, 'downloads/TemplateCreation');
const filePath = path.join(downloadPath, 'datasetMapping.csv');
const results = [];


const expectedDictionaryData = [
{
'Variable Name': 'Aut_Test_dataset',
'Abbreviation': 'Aut_Test_dataset',
'Title': 'Automated Testing Dataset',
'Unit of Measure': 'percentage',
'Description': 'description',
'DataType': 'int',
'Multiple Values': 'multiple values',
'Permitted Values': '0-100',
'Minimum Value': '0',
'Maximum Value': '100',
'Comments': 'comment',
},

];

const expectedchosenData = [
{
'Variable Name': selectedcde,
'Abbreviation': selectedcde,
},

];

let firstRow;
let lastRow;
let isFirstRow = true;
return new Promise<void>((resolve, reject) => {
fs.createReadStream(filePath)
.pipe(csv())
.on('data', (data) => {
const keys = Object.keys(data);
delete data[keys[keys.length - 1]]; // delete last column
delete data[keys[keys.length - 2]]; // delete second last column
results.push(data);
lastRow = data;
if (isFirstRow) {
firstRow = {
[keys[0]]: data[keys[0]],
[keys[1]]: data[keys[1]]
};
isFirstRow = false;
}
})
.on('end', () => {
const csvWriter = createObjectCsvWriter({
path: filePath,
header: Object.keys(results[0]).map(key => ({ id: key, title: key })),
});

csvWriter
.writeRecords(results)
.then(() => {
try {
// Compare the first two elements of the first row with the expected data
expect(firstRow).toEqual({
[Object.keys(expectedchosenData[0])[0]]: expectedchosenData[0][Object.keys(expectedchosenData[0])[0]],
[Object.keys(expectedchosenData[0])[1]]: expectedchosenData[0][Object.keys(expectedchosenData[0])[1]]
});
// Compare the last row with the expected data
expect(lastRow).toEqual(expectedDictionaryData[0]);
resolve();
} catch (error) {
reject(error);
}
})

});
console.log('CSV data checked successfully');

});



})

})
});

0 comments on commit 04ec753

Please sign in to comment.