Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Challenge page tests for the basic HTML certification #2

Draft
wants to merge 2 commits into
base: tests-in-browser
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api-server/server/resources/pathMigration.json

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions cypress/integration/learn/challengePages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* global cy */

export function challengePageTests(topicName, baseUrl, selectors, lessons) {
const defaultOutput = `
/**
* Your test output will go here.
*/`;

const runningOutput = '// running tests';
const finishedOutput = '// tests completed';

lessons.forEach(lesson => {
describe(`${topicName} - ${lesson.name}`, function() {
const url = `${baseUrl}${lesson.slug}`;

it('renders', () => {
// cy.wait(500);
cy.visit(url);

cy.title().should(
'eq',
`Learn ${topicName}: ${lesson.name} | freeCodeCamp.org`
);
});

it('renders the default output text', () => {
// cy.wait(500);
cy.visit(url);
cy.get(selectors.defaultOutput).contains(defaultOutput);
});

it('shows the right number of challenges', () => {
// cy.wait(500);
cy.visit(url);
cy.get(selectors.challenges).should(
'have.length',
lesson.challengeCount || 1
);
});

it('shows test output when the tests are run', () => {
// cy.wait(500);
cy.visit(url);
// first wait for the editor to load
cy.get(selectors.editor, { timeout: 15000 });
cy.get(selectors.runTestsButton)
.click()
.then(() => {
cy.get(selectors.defaultOutput).contains(runningOutput);
cy.get(selectors.defaultOutput).contains(finishedOutput);
cy.get(selectors.successModal).should('not.be.visible');
});
});

if (lesson.solution) {
it('shows success modal', () => {
cy.visit(url);
// first wait for the editor to load
cy.get(selectors.editor, { timeout: 10000 })
.type(lesson.solution)
.then(() => {
cy.get(selectors.runTestsButton)
.click()
.then(() => {
cy.get(selectors.successModal).should('be.visible');
});
});
});
}
});
});
}
5 changes: 2 additions & 3 deletions cypress/integration/learn/challenges/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ describe('Classic challenge', function() {
cy.get(selectors.runTestsButton)
.click()
.then(() => {
cy.get(selectors.defaultOutput)
.contains(runningOutput)
.contains(finishedOutput);
cy.get(selectors.defaultOutput).contains(runningOutput);
cy.get(selectors.defaultOutput).contains(finishedOutput);
});
});

Expand Down
23 changes: 13 additions & 10 deletions cypress/integration/learn/introductionPages.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
export function introductionPageTests(
testTitle,
pageTitle,
locations,
selectors,
lessonNames
) {
/* global cy */

export function introductionPageTests(testTitle, url, selectors, lessonNames) {
console.log('lessonName ', lessonNames);
const warningMessage =
'Note: Some browser extensions may interfere with elements on the page. ' +
'If the tests fail, try disabling your extensions for the most reliable ' +
'experience.';

describe(`Basic ${testTitle} Introduction page`, function() {
it('renders', () => {
cy.visit(locations.index);
cy.title().should('eq', pageTitle);
cy.visit(url);
cy.title().should('eq', `${testTitle} | freeCodeCamp.org`);
});

if (selectors.warningMessage) {
it('renders a warning user about extensions', () => {
cy.visit(locations.index);
cy.visit(url);
cy.get(selectors.warningMessage).contains(warningMessage);
});
}

it('has go to the first lesson button', () => {
cy.visit(url);
cy.get('a').contains('Go to the first lesson');
});

it('renders a lesson index', () => {
cy.visit(url);
lessonNames.forEach(name => {
cy.get(selectors.tableOfContents).contains('span', name);
});
Expand Down
Loading