Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
fhennig committed Jan 22, 2025
1 parent a9f5b03 commit 74a36ce
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions website/tests/pages/submission/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ test.describe('The submit page', () => {

let download = await submitPage.downloadTsvMetadataTemplate();

const expectedHeaders = ['submissionId', 'country', 'date'];

expect(download.suggestedFilename()).toBe('Test_Dummy_Organism_metadata_template.tsv');
const content = await getDownloadedContent(download);
const content = await getDownloadedContentAsString(download);
expect(content).toStrictEqual('submissionId\tcountry\tdate\n');

download = await submitPage.downloadXlsMetadataTemplate();
expect(download.suggestedFilename()).toBe('Test_Dummy_Organism_metadata_template.xls');
let workbook = await getDownloadedContentAsExcel(download);
expectHeaders(workbook, expectedHeaders);

download = await submitPage.downloadXlsMetadataTemplate();
download = await submitPage.downloadXlsxMetadataTemplate();
expect(download.suggestedFilename()).toBe('Test_Dummy_Organism_metadata_template.xlsx');
workbook = await getDownloadedContentAsExcel(download);
expectHeaders(workbook, expectedHeaders);
});

test('should download the metadata file template for revision', async ({
Expand All @@ -39,20 +45,20 @@ test.describe('The submit page', () => {

let download = await revisePage.downloadTsvMetadataTemplate();

const expectedHeaders = ["accession", "submissionId", "country", "date"];
const expectedHeaders = ['accession', 'submissionId', 'country', 'date'];

expect(download.suggestedFilename()).toBe('Test_Dummy_Organism_metadata_revision_template.tsv');
const content = await getDownloadedContentAsString(download);
expect(content).toStrictEqual('accession\tsubmissionId\tcountry\tdate\n');

download = await revisePage.downloadXlsMetadataTemplate();
expect(download.suggestedFilename()).toBe('Test_Dummy_Organism_metadata_revision_template.xls');
var workbook = await getDownloadedContentAsXls(download);
let workbook = await getDownloadedContentAsExcel(download);
expectHeaders(workbook, expectedHeaders);

download = await revisePage.downloadXlsxMetadataTemplate();
expect(download.suggestedFilename()).toBe('Test_Dummy_Organism_metadata_revision_template.xlsx');
workbook = await getDownloadedContentAsXls(download);
workbook = await getDownloadedContentAsExcel(download);
expectHeaders(workbook, expectedHeaders);
});

Expand All @@ -74,22 +80,21 @@ test.describe('The submit page', () => {
return new TextDecoder().decode(arrayBuffer);
}

async function getDownloadedContentAsXls(download: Download): Promise<XLSX.WorkBook> {
async function getDownloadedContentAsExcel(download: Download): Promise<XLSX.WorkBook> {
const arrayBuffer = await getDownloadedContent(download);
return XLSX.read(arrayBuffer);
}

function expectHeaders(workBook: XLSX.WorkBook, headers: string[]) {
expect(workBook.SheetNames.length).toBe(1);
const sheet = workBook.Sheets[workBook.SheetNames[0]];

const aoa = XLSX.utils.sheet_to_json(sheet, { header: 1 });
expect(aoa.length).toBeGreaterThan(0);

const sheetHeaders = aoa[0];
expect(sheetHeaders).toEqual(headers);
}


function skipDownloadTestInWebkit(browserName: 'chromium' | 'firefox' | 'webkit') {
test.skip(
Expand Down

0 comments on commit 74a36ce

Please sign in to comment.