feat: render nav conditionally
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
422bacd15d
commit
1a66eac990
@ -1,5 +1,14 @@
|
||||
/* global cy */
|
||||
|
||||
const selectors = {
|
||||
heading: "[data-test-label='landing-header']",
|
||||
smallCallToAction: "[data-test-label='landing-small-cta']",
|
||||
firstNavigationLink: '.nav-list .nav-link:first-child',
|
||||
lastNavigationLink: '.nav-list .nav-link:last-child',
|
||||
avatarContainer: '.avatar-container',
|
||||
defaultAvatar: '.avatar-container svg'
|
||||
};
|
||||
|
||||
describe('Navbar', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('/');
|
||||
@ -10,32 +19,6 @@ describe('Navbar', () => {
|
||||
cy.get('#universal-nav').should('have.class', 'universal-nav nav-padding');
|
||||
});
|
||||
|
||||
it('Should take user to news page when clicked on `/news`', () => {
|
||||
cy.get('.nav-news').within(() => {
|
||||
cy.contains('/news').click();
|
||||
});
|
||||
cy.url().should('include', '/news');
|
||||
});
|
||||
|
||||
it('Should take user to forum page when clicked on `/forum`', () => {
|
||||
cy.get('.nav-forum').within(() => {
|
||||
// Can't click on it in test due to CORS policy
|
||||
// So check the link instead
|
||||
cy.contains('/forum').should(
|
||||
'have.attr',
|
||||
'href',
|
||||
'https://forum.freecodecamp.org'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should take user to learn page when clicked on `/learn`', () => {
|
||||
cy.get('.nav-projects').within(() => {
|
||||
cy.contains('/learn').click();
|
||||
});
|
||||
cy.url().should('include', '/learn');
|
||||
});
|
||||
|
||||
it(
|
||||
'Should take user to learn page when clicked on ' + 'the freeCodeCamp logo',
|
||||
() => {
|
||||
@ -53,7 +36,7 @@ describe('Navbar', () => {
|
||||
|
||||
cy.get('.ais-Hits-list')
|
||||
.children()
|
||||
.should('have.length', 1);
|
||||
.should('to.have.length.of.at.least', 1);
|
||||
|
||||
cy.get('.ais-SearchBox').within(() => {
|
||||
cy.get('input').clear();
|
||||
@ -61,4 +44,48 @@ describe('Navbar', () => {
|
||||
|
||||
cy.get('div.ais-Hits').should('not.be.visible');
|
||||
});
|
||||
|
||||
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 `Curriculum` link on landing and learn pages' +
|
||||
'page when not signed in',
|
||||
() => {
|
||||
cy.get(selectors.firstNavigationLink)
|
||||
.contains('Curriculum')
|
||||
.click();
|
||||
cy.url().should('include', '/learn');
|
||||
cy.get(selectors.firstNavigationLink).contains('Curriculum');
|
||||
}
|
||||
);
|
||||
|
||||
it(
|
||||
'Should have `Sign In` link on landing and learn pages' +
|
||||
'page when not signed in',
|
||||
() => {
|
||||
cy.contains(selectors.smallCallToAction, 'Sign In');
|
||||
cy.get(selectors.firstNavigationLink)
|
||||
.contains('Curriculum')
|
||||
.click();
|
||||
cy.contains(selectors.smallCallToAction, 'Sign In');
|
||||
}
|
||||
);
|
||||
|
||||
it('Should have `Profile` link when user is signed in', () => {
|
||||
cy.login()
|
||||
.get(selectors.lastNavigationLink)
|
||||
.contains('Profile')
|
||||
.click();
|
||||
cy.url().should('include', '/developmentuser');
|
||||
});
|
||||
|
||||
it('Should have a profile image with class `default-border`', () => {
|
||||
cy.login()
|
||||
.get(selectors.avatarContainer)
|
||||
.should('have.class', 'default-border');
|
||||
cy.get(selectors.defaultAvatar).should('exist');
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user