Skip to content

Commit

Permalink
[FIX] test to use explicit file loading
Browse files Browse the repository at this point in the history
Previously we relied on a files position in the list of downloaded files.
That's brittle. If we look for the correct file instead, it's not brittle.
Not brittle is better.

Co-authored-by: Arman Jahanpour <[email protected]>
  • Loading branch information
surchs and rmanaem committed Nov 2, 2023
1 parent 5581d54 commit 235cb35
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions cypress/e2e/page/download-pagetests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,23 @@ describe("tests on download page ui via programmatic state loading and store int
// 2. Check contents of downloads folder
cy.task("downloads", "cypress/downloads").then(folderStateAfter => {

// A. Check number of files in downloads folder has increased by one
// Check that we actually downloaded a file
expect(folderStateAfter.length).to.be.eq(folderStateBefore.length + 1);

// B. Check that the last file retrieved by fs.readdirSync contains the data dictionary input file prefix
// as stored in dataDictionary.filename

cy.getVuexStoreValue("dataDictionary").then(dataDictionary => {

const dataDictionaryFilenameNoExt = dataDictionary.filename.split(".").slice(0, -1).join(".");

expect(folderStateAfter[folderStateAfter.length - 1]).to.contain(dataDictionaryFilenameNoExt);
expect(folderStateAfter.some(filename => filename.includes(dataDictionaryFilenameNoExt))).to.be.true;

// Because we only have access to dataDictionary within the scope of this promise,
// we need to run our next assertion in here
const targetFile = folderStateAfter.filter(filename => filename.includes(dataDictionaryFilenameNoExt))[0];
cy.readFile('cypress/downloads/' + targetFile).then((fileContent) => {
expect(fileContent.participant_id.Annotations).to.have.property("Identifies");
expect(fileContent.participant_id.Annotations.Identifies).to.eq("participant");
});
});
// C. Check if the last file retrieved contains the Identifies property and its value under the participant_id key
cy.readFile('cypress/downloads/' + folderStateAfter[folderStateAfter.length - 1]).then((fileContent) => {
expect(fileContent.participant_id.Annotations).to.have.property("Identifies");
expect(fileContent.participant_id.Annotations.Identifies).to.eq("participant");
});
});
});
});
Expand Down

0 comments on commit 235cb35

Please sign in to comment.