Files
freeCodeCamp/cypress/integration/learn/challenges/output.js
Radi Totev e581bd9081 feat(client): shortcuts legend modal available on pressing the ? key (#45530)
* Add modal texts in translations.json file

* Add shortcuts modal state in redux

* Create shortcuts modal

* Integrate shortcuts modal

* Resolve codefactor.io issues

* Extend list of shortcuts

Based on this comment:
https://github.com/freeCodeCamp/freeCodeCamp/issues/36841#issuecomment-933310078

* Remove temporary placeholder for modal title

* Open modal fom Hotkeys instead of learn.tsx

As suggested in this comment:
https://github.com/freeCodeCamp/freeCodeCamp/pull/45530#issuecomment-1101224993

* Complete list in transaltions

* Change shortcut presentation fo better a11y

Use table instead of list items as suggestedin this comment:
https://github.com/freeCodeCamp/freeCodeCamp/pull/45530#issuecomment-1101796368

* Add aria-labelledby

* Remove GAnalytics

* Remove leftover style

* Remove table caption

* autofocus on modal close button

* Improve modal a11y

- Add requested changes from https://github.com/freeCodeCamp/freeCodeCamp/pull/45530#issuecomment-1104764766
- Leave autofocus and parent div role=dialog changes for later. (https://github.com/freeCodeCamp/freeCodeCamp/pull/45530#issuecomment-1107754148)

* [WIP] Alllow users to turn off keyboard shortcuts

* Add keyboard shortcuts switch in settings

* Disable shortcuts

* Remove toggle switch description

* Refactor and cleanup

* Remove close button from modal header

Suggested by bbsmooth:
https://github.com/freeCodeCamp/freeCodeCamp/pull/45530#issuecomment-1107861091

* Fix lint issues

* Disable shortcuts

* Disable shortcuts by default

* Update challenge output test

* Update challenge-hot-keys test

* Disable shortcuts from inside handlers

Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
2022-06-03 09:57:52 -07:00

128 lines
3.2 KiB
JavaScript

const selectors = {
defaultOutput: '.output-text',
editor: 'div.monaco-editor textarea',
hotkeys: '.default-layout > div',
runTestsButton: 'button:contains("Run the Tests")'
};
const locations = {
index:
'/learn/responsive-web-design/basic-html-and-html5/' +
'say-hello-to-html-elements',
jQuery:
'/learn/front-end-development-libraries/jquery/' +
'target-html-elements-with-selectors-using-jquery',
js:
'/learn/javascript-algorithms-and-data-structures/basic-javascript/' +
'comment-your-javascript-code'
};
const defaultOutput = `
/**
* Your test output will go here
*/`;
const runningOutput = '// running tests';
const finishedOutput = '// tests completed';
describe('Classic challenge', function () {
before(() => {
cy.visit(locations.index);
});
it('renders the default output text', () => {
cy.title().should(
'eq',
'Basic HTML and HTML5: Say Hello to HTML Elements |' + ' freeCodeCamp.org'
);
cy.get(selectors.defaultOutput).contains(defaultOutput);
});
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);
});
});
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
})
.focus()
.type('{ctrl}{enter}')
.then(() => {
cy.get(selectors.defaultOutput)
.contains(runningOutput)
.contains(finishedOutput);
});
});
});
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'
);
});
});
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})'
);
});
});