feat(test, e2e) test suit for cypress (#42138)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Sem Bauke
2021-06-14 18:37:52 +02:00
committed by GitHub
parent 08fc4014c7
commit 22b45761a7
35 changed files with 367 additions and 55 deletions

View File

@ -1,31 +0,0 @@
/* global cy */
const selectors = {
footer: '.site-footer'
};
describe('Footer', () => {
it('Should render on landing page', () => {
cy.visit('/');
cy.get(selectors.footer).should('be.visible');
});
it('Should render on learn page', () => {
cy.visit('/learn');
cy.get(selectors.footer).should('be.visible');
cy.visit('/learn/');
cy.get(selectors.footer).should('be.visible');
});
it('Should render on superblock page', () => {
cy.visit('/learn/responsive-web-design/');
cy.get(selectors.footer).should('be.visible');
});
it('Should not render on challenge page', () => {
cy.visit(
'/learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements'
);
cy.get(selectors.footer).should('not.exist');
});
});

View File

@ -1,36 +0,0 @@
/* global cy */
describe('Help Button', () => {
it('should be visible', () => {
cy.visit(
'/learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements'
);
cy.get('#get-help-dropdown').scrollIntoView().should('be.visible');
});
it('should toggle the dropdown menu', () => {
cy.get('#get-help-dropdown').scrollIntoView().click();
cy.get('ul[role="menu"]').should('be.visible');
});
it('should render three links when video is available', () => {
cy.get('ul[role="menu"]').within(() => {
cy.get('a').should('have.length', 3);
cy.get('a').eq(0).contains('Get a Hint');
cy.get('a').eq(1).contains('Watch a Video');
cy.get('a').eq(2).contains('Ask for Help');
});
});
it('should render two links when video is not available', () => {
cy.visit(
'/learn/front-end-libraries/bootstrap/apply-the-default-bootstrap-button-style'
);
cy.get('#get-help-dropdown').scrollIntoView().click();
cy.get('ul[role="menu"]').within(() => {
cy.get('a').should('have.length', 2);
cy.get('a').eq(0).contains('Get a Hint');
cy.get('a').eq(1).contains('Ask for Help');
});
});
});

View File

@ -1,109 +0,0 @@
/* global cy */
const selectors = {
heading: "[data-test-label='landing-header']",
smallCallToAction: "[data-test-label='landing-small-cta']",
navigationLinks: '.nav-list',
avatarContainer: '.avatar-container',
defaultAvatar: '.avatar-container',
menuButton: '.toggle-button-nav',
avatarImage: '.avatar-container .avatar'
};
let appHasStarted;
function spyOnListener(win) {
const addListener = win.EventTarget.prototype.addEventListener;
win.EventTarget.prototype.addEventListener = function (name) {
if (name === 'click') {
appHasStarted = true;
win.EventTarget.prototype.addEventListener = addListener;
}
return addListener.apply(this, arguments);
};
}
function waitForAppStart() {
return new Promise(resolve => {
const isReady = () => {
if (appHasStarted) {
return resolve();
}
return setTimeout(isReady, 0);
};
isReady();
});
}
describe('Navbar', () => {
beforeEach(() => {
appHasStarted = false;
cy.visit('/', {
onBeforeLoad: spyOnListener
}).then(waitForAppStart);
cy.viewport(1300, 660);
});
it('Should render properly', () => {
cy.get('#universal-nav').should('be.visible');
cy.get('#universal-nav').should('have.class', 'universal-nav');
});
it(
'Should take user to learn page when clicked on ' + 'the freeCodeCamp logo',
() => {
cy.get('.universal-nav-middle').within(() => {
cy.get('svg').click();
});
cy.url().should('include', '/learn');
}
);
it('Should have a "Sign in" button', () => {
cy.contains("[data-test-label='landing-small-cta']", 'Sign in');
});
// have the curriculum and CTA on landing and /learn pages.
it(
'Should have `Radio`, `Forum`, and `Curriculum` links on landing and learn pages' +
'page when not signed in',
() => {
cy.get(selectors.menuButton).click();
cy.get(selectors.navigationLinks).contains('Forum');
cy.get(selectors.navigationLinks).contains('Curriculum').click();
cy.url().should('include', '/learn');
cy.get(selectors.navigationLinks).contains('Curriculum');
cy.get(selectors.navigationLinks).contains('Forum');
cy.get(selectors.navigationLinks).contains('Radio');
}
);
it(
'Should have `Sign in` link on landing and learn pages' +
' when not signed in',
() => {
cy.contains(selectors.smallCallToAction, 'Sign in');
cy.get(selectors.menuButton).click();
cy.get(selectors.navigationLinks).contains('Curriculum').click();
cy.contains(selectors.smallCallToAction, 'Sign in');
}
);
it('Should have `Profile` link when user is signed in', () => {
cy.login();
cy.get(selectors.menuButton).click();
cy.get(selectors.navigationLinks).contains('Profile').click();
cy.url().should('include', '/developmentuser');
});
it('Should have a profile image with class `default-border`', () => {
cy.login();
cy.get(selectors.avatarContainer).should('have.class', 'default-border');
cy.get(selectors.defaultAvatar).should('exist');
});
it('Should have a profile image with dimensions that are <= 31px', () => {
cy.login();
cy.get(selectors.avatarImage).invoke('width').should('lte', 31);
cy.get(selectors.avatarImage).invoke('height').should('lte', 31);
});
});

View File

@ -1,77 +0,0 @@
/* global cy */
const search = query => {
cy.get('.ais-SearchBox').within(() => {
cy.get('input').type(query);
});
cy.wait(300);
};
const clear = () => {
cy.get('.ais-SearchBox').within(() => {
cy.get('input').clear();
});
};
describe('Search bar', () => {
before(() => {
cy.visit('/');
});
beforeEach(() => {
clear();
});
it('Should render properly', () => {
cy.get('.ais-SearchBox').should('be.visible');
});
it('Should accept input and display hits', () => {
search('freeCodeCamp');
cy.get('.ais-Hits-list').children().should('to.have.length.of.at.least', 1);
});
it('Should clear hits when input is cleared', () => {
search('freeCodeCamp');
cy.get('.ais-Hits-list').children().should('to.have.length.of.at.least', 1);
clear();
cy.get('div.ais-Hits').should('not.exist');
});
it('Should show up to 8 hits when height >= 768px', () => {
cy.viewport(1300, 768);
search('freeCodeCamp');
cy.get('.ais-Hits-list').children().should('to.have.length.of', 8);
});
it('Should show up to 5 hits when height < 768px', () => {
cy.viewport(1300, 767);
search('freeCodeCamp');
cy.get('.ais-Hits-list').children().should('to.have.length.of', 5);
});
it('Should show no hits for queries that do not exist in the Algolia index', () => {
search('testtttt');
cy.get('.ais-Hits-list').children().should('to.have.length.of', 0);
cy.contains('No tutorials found');
});
it('Should not redirect to the News search page if there are no hits', () => {
search('testtttt');
cy.get('.ais-SearchBox-form').submit();
cy.url('/');
});
});