Skip to content

Commit

Permalink
#242: fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-may committed Sep 30, 2024
1 parent 0097090 commit b74e94e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
/skills-client-ng/package-lock.json
/skills-client-ng/dist/
/skills-client-ng/projects/skilltree/skills-client-ng/src/version.js
/skills-client-integration/skills-int-e2e-test/cypress/downloads/*
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,25 @@ import selectors from "../support/selectors";

context("Transcript Export Tests", () => {

const deleteDownloadDir = () => {
try {
cy.log('trying to remove downloads dir')
cy.exec('rm cypress/downloads/*');
cy.log('remove downloads dir')
} catch (error) {
throw Error(`Failed to remove downloads with ${error}`);
} finally {
return null;
}
};


beforeEach(() => {
deleteDownloadDir()

Cypress.Commands.add("printLocInfo", () => {
cy.wait(2000)
cy.exec('ls ./').then((result) => {
cy.log(result.stdout);
});
cy.exec('ls ./cypress/downloads').then((result) => {
cy.log(result.stdout);
});
})
})
if (Utils.skillsServiceVersionLaterThan('3.1.0')) {
const expectedHeaderAndFooter = 'For All Dragons enjoyment'
const expectedHeaderAndFooterCommunityProtected = 'For Divine Dragon enjoyment'

it('export user transcript', () => {
cy.createDefaultTinyProject()
const projName = 'Export1'
cy.createDefaultTinyProject('proj1', projName)

// visit client display
cy.visitSkillsDisplay();
cy.clientDisplay().find(selectors.titleSection).contains('User Skills');
cy.clientDisplay().find(selectors.myRankButton)

cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click()
cy.printLocInfo()

Cypress.Commands.add("readTranscript", () => {
const pathToPdf = './cypress/downloads/Very Cool Project with id proj1 - user1 - Transcript.pdf'
const pathToPdf = `./cypress/downloads/${projName} - user1 - Transcript.pdf`
cy.readFile(pathToPdf, { timeout: 10000 }).then(() => {
// file exists and was successfully read
cy.log(`Transcript [${pathToPdf}] Found!`)
Expand All @@ -74,7 +50,7 @@ context("Transcript Export Tests", () => {
cy.readTranscript().then((doc) => {
expect(doc.numpages).to.equal(2)
expect(clean(doc.text)).to.include('SkillTree Transcript')
expect(clean(doc.text)).to.include('Very Cool Project with id proj1')
expect(clean(doc.text)).to.include(projName)
expect(clean(doc.text)).to.include('Level: 0 / 5 ')
expect(clean(doc.text)).to.include('Points: 0 / 100 ')
expect(clean(doc.text)).to.include('Skills: 0 / 2 ')
Expand All @@ -98,7 +74,8 @@ context("Transcript Export Tests", () => {
res.send(conf);
});
}).as('getPublicConfig');
cy.createDefaultTinyProject()
const projName = 'Export2'
cy.createDefaultTinyProject('proj1', projName)

// visit client display
cy.visitSkillsDisplay();
Expand All @@ -107,9 +84,8 @@ context("Transcript Export Tests", () => {
cy.clientDisplay().find(selectors.myRankButton)

cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click()
cy.printLocInfo()
Cypress.Commands.add("readTranscript", () => {
const pathToPdf = 'cypress/downloads/Very Cool Project with id proj1 - user1 - Transcript.pdf'
const pathToPdf = `cypress/downloads/${projName} - user1 - Transcript.pdf`
cy.readFile(pathToPdf, { timeout: 10000 }).then(() => {
// file exists and was successfully read
cy.log(`Transcript [${pathToPdf}] Found!`)
Expand All @@ -122,7 +98,7 @@ context("Transcript Export Tests", () => {
cy.readTranscript().then((doc) => {
expect(doc.numpages).to.equal(2)
expect(clean(doc.text)).to.include('SkillTree Transcript')
expect(clean(doc.text)).to.include('Very Cool Project with id proj1')
expect(clean(doc.text)).to.include(projName)
expect(clean(doc.text)).to.include('Level: 0 / 5 ')
expect(clean(doc.text)).to.include('Points: 0 / 100 ')
expect(clean(doc.text)).to.include('Skills: 0 / 2 ')
Expand All @@ -146,7 +122,8 @@ context("Transcript Export Tests", () => {
res.send(conf);
});
}).as('getPublicConfig');
cy.createDefaultTinyProject()
const projName = 'Export3'
cy.createDefaultTinyProject('proj1', projName)

const allDragonsUser = '[email protected]'
cy.fixture('vars.json').then((vars) => {
Expand All @@ -164,7 +141,7 @@ context("Transcript Export Tests", () => {
});
cy.backendPost(`/admin/projects/proj1`, {
projectId: 'proj1',
name: `Very Cool Project with id proj1`,
name: projName,
enableProtectedUserCommunity: true
})

Expand All @@ -175,9 +152,8 @@ context("Transcript Export Tests", () => {
cy.clientDisplay().find(selectors.myRankButton)

cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click()
cy.printLocInfo()
Cypress.Commands.add("readTranscript", () => {
const pathToPdf = 'cypress/downloads/Very Cool Project with id proj1 - Firstname LastName (user1) - Transcript.pdf'
const pathToPdf = `cypress/downloads/${projName} - Firstname LastName (user1) - Transcript.pdf`
cy.readFile(pathToPdf, { timeout: 10000 }).then(() => {
// file exists and was successfully read
cy.log(`Transcript [${pathToPdf}] Found!`)
Expand All @@ -190,7 +166,7 @@ context("Transcript Export Tests", () => {
cy.readTranscript().then((doc) => {
expect(doc.numpages).to.equal(2)
expect(clean(doc.text)).to.include('SkillTree Transcript')
expect(clean(doc.text)).to.include('Very Cool Project with id proj1')
expect(clean(doc.text)).to.include(projName)
expect(clean(doc.text)).to.include('Level: 0 / 5 ')
expect(clean(doc.text)).to.include('Points: 0 / 100 ')
expect(clean(doc.text)).to.include('Skills: 0 / 2 ')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ Cypress.Commands.add("backendAddSkill", (skillId, version = 0, projId = 'proj1',
})
});

Cypress.Commands.add("createDefaultProject", (numSubj = 3, numSkillsPerSubj = 2, pointIncrement = 50, numPerformToCompletion = 1, projId = 'proj1') => {
Cypress.Commands.add("createDefaultProject", (numSubj = 3, numSkillsPerSubj = 2, pointIncrement = 50, numPerformToCompletion = 1, projId = 'proj1', projName = null) => {
const skillIdsToCreate = ['IronMan', 'Thor']
cy.backendPost(`/app/projects/${projId}`, {
projectId: projId,
name: `Very Cool Project with id ${projId}`
name: projName || `Very Cool Project with id ${projId}`
}).then((resp => {
if (Cypress.env('oauthMode')) {
// if we're in oauthMode, then the foo-hyrda user will own the project. so we need to give the
Expand Down Expand Up @@ -154,8 +154,8 @@ Cypress.Commands.add("createDefaultProject", (numSubj = 3, numSkillsPerSubj = 2,
}
});

Cypress.Commands.add("createDefaultTinyProject", (projId = 'proj1') => {
cy.createDefaultProject(1, 2, 50, 1, projId)
Cypress.Commands.add("createDefaultTinyProject", (projId = 'proj1', projName = null) => {
cy.createDefaultProject(1, 2, 50, 1, projId, projName)
});

Cypress.Commands.add("iframe", (handleIframeBody) => {
Expand Down

0 comments on commit b74e94e

Please sign in to comment.