-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ import selectors from "../support/selectors"; | |
context("Transcript Export Tests", () => { | ||
|
||
beforeEach(() => { | ||
Cypress.Commands.add("getFileName", (projName) => { | ||
const userName = Cypress.env('oauthMode') ? 'foo bar (foo)' : 'user1' | ||
return `./cypress/downloads/${projName} - ${userName} - Transcript.pdf` | ||
}) | ||
}) | ||
if (Utils.skillsServiceVersionLaterThan('3.1.0')) { | ||
const expectedHeaderAndFooter = 'For All Dragons enjoyment' | ||
|
@@ -37,7 +41,7 @@ context("Transcript Export Tests", () => { | |
cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click() | ||
|
||
Cypress.Commands.add("readTranscript", () => { | ||
const pathToPdf = `./cypress/downloads/${projName} - user1 - Transcript.pdf` | ||
const pathToPdf = cy.getFileName(projName) | ||
cy.readFile(pathToPdf, { timeout: 10000 }).then(() => { | ||
// file exists and was successfully read | ||
cy.log(`Transcript [${pathToPdf}] Found!`) | ||
|
@@ -85,7 +89,7 @@ context("Transcript Export Tests", () => { | |
|
||
cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click() | ||
Cypress.Commands.add("readTranscript", () => { | ||
const pathToPdf = `cypress/downloads/${projName} - user1 - Transcript.pdf` | ||
const pathToPdf = cy.getFileName(projName) | ||
cy.readFile(pathToPdf, { timeout: 10000 }).then(() => { | ||
// file exists and was successfully read | ||
cy.log(`Transcript [${pathToPdf}] Found!`) | ||
|
@@ -114,72 +118,74 @@ context("Transcript Export Tests", () => { | |
}) | ||
}); | ||
|
||
it('export user transcript - community protected header', () => { | ||
cy.intercept('GET', '/public/config', (req) => { | ||
req.reply((res) => { | ||
const conf = res.body; | ||
conf.exportHeaderAndFooter = 'For {{community.project.descriptor}} enjoyment'; | ||
res.send(conf); | ||
if (!Cypress.env('oauthMode')) { | ||
it('export user transcript - community protected header', () => { | ||
cy.intercept('GET', '/public/config', (req) => { | ||
req.reply((res) => { | ||
const conf = res.body; | ||
conf.exportHeaderAndFooter = 'For {{community.project.descriptor}} enjoyment'; | ||
res.send(conf); | ||
}); | ||
}).as('getPublicConfig'); | ||
const projName = 'Export3' | ||
cy.createDefaultTinyProject('proj1', projName) | ||
|
||
const allDragonsUser = '[email protected]' | ||
cy.fixture('vars.json').then((vars) => { | ||
cy.backendLogout(); | ||
cy.backendRegister('user1', vars.defaultPass); | ||
cy.backendLogin(vars.rootUser, vars.defaultPass, true); | ||
cy.backendPost(`/root/users/user1/tags/dragons`, {tags: ['DivineDragon']}); | ||
cy.backendPost(`/root/users/${vars.defaultUser}/tags/dragons`, {tags: ['DivineDragon']}); | ||
cy.backendLogout(); | ||
|
||
cy.backendRegister(allDragonsUser, vars.defaultPass); | ||
cy.backendLogout(); | ||
|
||
cy.backendLogin(vars.defaultUser, vars.defaultPass); | ||
}); | ||
}).as('getPublicConfig'); | ||
const projName = 'Export3' | ||
cy.createDefaultTinyProject('proj1', projName) | ||
|
||
const allDragonsUser = '[email protected]' | ||
cy.fixture('vars.json').then((vars) => { | ||
cy.backendLogout(); | ||
cy.backendRegister('user1', vars.defaultPass); | ||
cy.backendLogin(vars.rootUser, vars.defaultPass, true); | ||
cy.backendPost( `/root/users/user1/tags/dragons`, { tags: ['DivineDragon'] }); | ||
cy.backendPost( `/root/users/${vars.defaultUser}/tags/dragons`, { tags: ['DivineDragon'] }); | ||
cy.backendLogout(); | ||
|
||
cy.backendRegister(allDragonsUser, vars.defaultPass); | ||
cy.backendLogout(); | ||
|
||
cy.backendLogin(vars.defaultUser, vars.defaultPass); | ||
}); | ||
cy.backendPost(`/admin/projects/proj1`, { | ||
projectId: 'proj1', | ||
name: projName, | ||
enableProtectedUserCommunity: true | ||
}) | ||
|
||
// visit client display | ||
cy.visitSkillsDisplay(); | ||
cy.wait('@getPublicConfig') | ||
cy.clientDisplay().find(selectors.titleSection).contains('User Skills'); | ||
cy.clientDisplay().find(selectors.myRankButton) | ||
cy.backendPost(`/admin/projects/proj1`, { | ||
projectId: 'proj1', | ||
name: projName, | ||
enableProtectedUserCommunity: true | ||
}) | ||
|
||
cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click() | ||
Cypress.Commands.add("readTranscript", () => { | ||
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!`) | ||
// visit client display | ||
cy.visitSkillsDisplay(); | ||
cy.wait('@getPublicConfig') | ||
cy.clientDisplay().find(selectors.titleSection).contains('User Skills'); | ||
cy.clientDisplay().find(selectors.myRankButton) | ||
|
||
cy.wrapIframe().find('[data-cy="downloadTranscriptBtn"]').click() | ||
Cypress.Commands.add("readTranscript", () => { | ||
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!`) | ||
}) | ||
return cy.task('readPdf', pathToPdf) | ||
}); | ||
const clean = (text) => { | ||
return text.replace(/\n/g, '') | ||
} | ||
cy.readTranscript().then((doc) => { | ||
expect(doc.numpages).to.equal(2) | ||
expect(clean(doc.text)).to.include('SkillTree Transcript') | ||
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 ') | ||
expect(clean(doc.text)).to.include('user1') | ||
expect(clean(doc.text)).to.not.include('Badges') | ||
|
||
// should be a title on the 2nd page | ||
expect(clean(doc.text)).to.include('Subject: Subject 0'.toUpperCase()) | ||
|
||
expect(clean(doc.text)).to.not.include(expectedHeaderAndFooter) | ||
expect(clean(doc.text)).to.include(expectedHeaderAndFooterCommunityProtected) | ||
expect(clean(doc.text)).to.not.include('null') | ||
}) | ||
return cy.task('readPdf', pathToPdf) | ||
}); | ||
const clean = (text) => { | ||
return text.replace(/\n/g, '') | ||
} | ||
cy.readTranscript().then((doc) => { | ||
expect(doc.numpages).to.equal(2) | ||
expect(clean(doc.text)).to.include('SkillTree Transcript') | ||
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 ') | ||
expect(clean(doc.text)).to.include('user1') | ||
expect(clean(doc.text)).to.not.include('Badges') | ||
|
||
// should be a title on the 2nd page | ||
expect(clean(doc.text)).to.include('Subject: Subject 0'.toUpperCase()) | ||
|
||
expect(clean(doc.text)).to.not.include(expectedHeaderAndFooter) | ||
expect(clean(doc.text)).to.include(expectedHeaderAndFooterCommunityProtected) | ||
expect(clean(doc.text)).to.not.include('null') | ||
}) | ||
}); | ||
} | ||
} | ||
}); |