2020-07-17 21:03:23 +02:00
|
|
|
const selectors = {
|
|
|
|
defaultOutput: '.output-text',
|
2020-08-25 19:28:27 +02:00
|
|
|
editor: '.monaco-editor',
|
2020-07-17 21:03:23 +02:00
|
|
|
hotkeys: '.default-layout > div',
|
|
|
|
runTestsButton: 'button:contains("Run the Tests")'
|
|
|
|
};
|
|
|
|
|
|
|
|
const locations = {
|
|
|
|
index:
|
|
|
|
'/learn/responsive-web-design/basic-html-and-html5/' +
|
2021-12-08 12:29:16 -08:00
|
|
|
'say-hello-to-html-elements',
|
|
|
|
jQuery:
|
|
|
|
'/learn/front-end-development-libraries/jquery/' +
|
2022-02-10 21:38:03 +01:00
|
|
|
'target-html-elements-with-selectors-using-jquery',
|
|
|
|
js:
|
|
|
|
'/learn/javascript-algorithms-and-data-structures/basic-javascript/' +
|
|
|
|
'comment-your-javascript-code'
|
2020-07-17 21:03:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultOutput = `
|
|
|
|
/**
|
2020-12-16 02:02:52 -06:00
|
|
|
* Your test output will go here
|
2020-07-17 21:03:23 +02:00
|
|
|
*/`;
|
|
|
|
|
2021-04-28 16:04:07 +02:00
|
|
|
const runningOutput = '// running tests';
|
|
|
|
const finishedOutput = '// tests completed';
|
2020-07-17 21:03:23 +02:00
|
|
|
|
2021-03-11 00:31:46 +05:30
|
|
|
describe('Classic challenge', function () {
|
2021-04-28 16:04:07 +02:00
|
|
|
before(() => {
|
2020-07-17 21:03:23 +02:00
|
|
|
cy.visit(locations.index);
|
2021-04-28 16:04:07 +02:00
|
|
|
});
|
2020-07-17 21:03:23 +02:00
|
|
|
|
2021-04-28 16:04:07 +02:00
|
|
|
it('renders the default output text', () => {
|
2020-07-17 21:03:23 +02:00
|
|
|
cy.title().should(
|
|
|
|
'eq',
|
2021-12-01 07:53:37 -08:00
|
|
|
'Basic HTML and HTML5: Say Hello to HTML Elements |' + ' freeCodeCamp.org'
|
2020-07-17 21:03:23 +02:00
|
|
|
);
|
|
|
|
cy.get(selectors.defaultOutput).contains(defaultOutput);
|
|
|
|
});
|
|
|
|
|
2021-04-28 16:04:07 +02:00
|
|
|
it('shows test output when the tests are run', () => {
|
|
|
|
// 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)
|
|
|
|
.contains(finishedOutput);
|
|
|
|
});
|
|
|
|
});
|
2021-02-09 14:15:18 +05:30
|
|
|
|
2021-04-28 16:04:07 +02:00
|
|
|
it('shows test output when the tests are triggered by the keyboard', () => {
|
|
|
|
// first wait for the editor to load
|
|
|
|
cy.get(selectors.editor, {
|
|
|
|
timeout: 15000
|
|
|
|
});
|
|
|
|
cy.get(selectors.hotkeys)
|
|
|
|
.focus()
|
|
|
|
.type('{ctrl}{enter}')
|
|
|
|
.then(() => {
|
|
|
|
cy.get(selectors.defaultOutput)
|
|
|
|
.contains(runningOutput)
|
|
|
|
.contains(finishedOutput);
|
|
|
|
});
|
|
|
|
});
|
2020-07-17 21:03:23 +02:00
|
|
|
});
|
2021-12-08 12:29:16 -08:00
|
|
|
|
|
|
|
describe('jQuery challenge', function () {
|
|
|
|
before(() => {
|
|
|
|
cy.visit(locations.jQuery);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the default output text', () => {
|
|
|
|
cy.title().should(
|
|
|
|
'eq',
|
|
|
|
'jQuery: Target HTML Elements with Selectors Using jQuery | freeCodeCamp.org'
|
|
|
|
);
|
|
|
|
cy.get(selectors.defaultOutput).contains(defaultOutput);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not show a reference error', () => {
|
|
|
|
cy.wait(5000);
|
|
|
|
cy.get(selectors.defaultOutput).should(
|
|
|
|
'not.contain',
|
|
|
|
'ReferenceError: $ is not defined'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2022-02-10 21:38:03 +01:00
|
|
|
|
|
|
|
describe('Custom output for JavaScript objects', function () {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.visit(locations.js);
|
|
|
|
cy.get(selectors.editor, {
|
|
|
|
timeout: 15000
|
|
|
|
})
|
|
|
|
.first()
|
|
|
|
.click()
|
|
|
|
.focused()
|
|
|
|
.type('{ctrl}a')
|
|
|
|
.clear();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Set object', () => {
|
|
|
|
cy.get(selectors.editor)
|
|
|
|
.first()
|
|
|
|
.click()
|
|
|
|
.focused()
|
|
|
|
.type(
|
|
|
|
'const set = new Set();{enter}set.add(1);{enter}set.add("set");{enter}set.add(10);{enter}console.log(set);'
|
|
|
|
);
|
|
|
|
cy.get(selectors.defaultOutput).should('contain', 'Set(3) {1, set, 10}');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Map object', () => {
|
|
|
|
cy.get(selectors.editor)
|
|
|
|
.first()
|
|
|
|
.click()
|
|
|
|
.focused()
|
|
|
|
.type(
|
|
|
|
'const map = new Map();{enter}map.set("first", 1);{enter}map.set("second", 2);{enter}map.set("other", "map");{enter}console.log(map);'
|
|
|
|
);
|
|
|
|
cy.get(selectors.defaultOutput).should(
|
|
|
|
'contain',
|
|
|
|
'Map(3) {first => 1, second => 2, other => map})'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|