feat(client): redesigned navigation (#40709)
Co-authored-by: moT01 <20648924+moT01@users.noreply.github.com>
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
9014fff6c4
commit
58c6c54c67
@ -5,18 +5,46 @@ const selectors = {
|
||||
smallCallToAction: "[data-test-label='landing-small-cta']",
|
||||
navigationLinks: '.nav-list',
|
||||
avatarContainer: '.avatar-container',
|
||||
defaultAvatar: '.avatar-container svg'
|
||||
defaultAvatar: '.avatar-container',
|
||||
menuButton: '.toggle-button-nav'
|
||||
};
|
||||
|
||||
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(() => {
|
||||
cy.visit('/');
|
||||
cy.viewport(1200, 660);
|
||||
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 nav-padding');
|
||||
cy.get('#universal-nav').should('have.class', 'universal-nav');
|
||||
});
|
||||
|
||||
it(
|
||||
@ -51,9 +79,10 @@ describe('Navbar', () => {
|
||||
|
||||
// have the curriculum and CTA on landing and /learn pages.
|
||||
it(
|
||||
'Should have `Forum` and `Curriculum` links on landing and learn pages' +
|
||||
'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')
|
||||
@ -61,14 +90,16 @@ describe('Navbar', () => {
|
||||
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' +
|
||||
'page when not signed in',
|
||||
' when not signed in',
|
||||
() => {
|
||||
cy.contains(selectors.smallCallToAction, 'Sign in');
|
||||
cy.get(selectors.menuButton).click();
|
||||
cy.get(selectors.navigationLinks)
|
||||
.contains('Curriculum')
|
||||
.click();
|
||||
@ -77,17 +108,18 @@ describe('Navbar', () => {
|
||||
);
|
||||
|
||||
it('Should have `Profile` link when user is signed in', () => {
|
||||
cy.login()
|
||||
.get(selectors.navigationLinks)
|
||||
cy.login();
|
||||
cy.get('a[href*="/settings"]').should('be.visible');
|
||||
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()
|
||||
.get(selectors.avatarContainer)
|
||||
.should('have.class', 'default-border');
|
||||
cy.login();
|
||||
cy.get(selectors.avatarContainer).should('have.class', 'default-border');
|
||||
cy.get(selectors.defaultAvatar).should('exist');
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user