feat: add back the forum nav item (#40060)
This commit is contained in:
@ -30,31 +30,14 @@ describe('<NavLinks />', () => {
|
|||||||
const shallow = new ShallowRenderer();
|
const shallow = new ShallowRenderer();
|
||||||
shallow.render(<AuthOrProfile {...landingPageProps} />);
|
shallow.render(<AuthOrProfile {...landingPageProps} />);
|
||||||
const result = shallow.getRenderOutput();
|
const result = shallow.getRenderOutput();
|
||||||
// expect(result.props.children).toEqual('Sign In');
|
|
||||||
|
|
||||||
expect(deepChildrenProp(result, 0).children === 'Curriculum').toBeTruthy();
|
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
result.props.children[1].props['data-test-label'] === 'landing-small-cta'
|
hasForumNavItem(result) &&
|
||||||
|
hasCurriculumNavItem(result) &&
|
||||||
|
hasSignInButton(result)
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has Curriculum and Portfolio links when user signed in on /learn', () => {
|
|
||||||
const defaultUserProps = {
|
|
||||||
user: {
|
|
||||||
username: 'test-user',
|
|
||||||
picture: 'https://freecodecamp.org/image.png'
|
|
||||||
},
|
|
||||||
pending: false
|
|
||||||
};
|
|
||||||
const shallow = new ShallowRenderer();
|
|
||||||
shallow.render(<AuthOrProfile {...defaultUserProps} />);
|
|
||||||
const result = shallow.getRenderOutput();
|
|
||||||
|
|
||||||
expect(hasCurriculumNavItem(result)).toBeTruthy();
|
|
||||||
expect(hasProfileNavItem(result)).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('has avatar with default border for default users', () => {
|
it('has avatar with default border for default users', () => {
|
||||||
const defaultUserProps = {
|
const defaultUserProps = {
|
||||||
user: {
|
user: {
|
||||||
@ -120,28 +103,30 @@ describe('<NavLinks />', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const deepChildrenProp = (component, childNumber) =>
|
const navigationLinks = (component, navItem) => {
|
||||||
component.props.children[childNumber].props.children.props;
|
return component.props.children[0].props.children[navItem].props.children
|
||||||
|
.props;
|
||||||
|
};
|
||||||
|
|
||||||
const hasProfileNavItem = component => {
|
const profileNavItem = component => component[2].children[0];
|
||||||
const profileElement = deepChildrenProp(component, 1);
|
|
||||||
return (
|
const hasForumNavItem = component => {
|
||||||
profileElement.children[0] === 'Profile' &&
|
const { children, to } = navigationLinks(component, 0);
|
||||||
profileElement.to === '/test-user'
|
return children === 'Forum' && to === 'https://forum.freecodecamp.org';
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasCurriculumNavItem = component => {
|
const hasCurriculumNavItem = component => {
|
||||||
const curriculumElement = deepChildrenProp(component, 0);
|
const { children, to } = navigationLinks(component, 1);
|
||||||
return (
|
return children === 'Curriculum' && to === '/learn';
|
||||||
curriculumElement.children === 'Curriculum' &&
|
|
||||||
curriculumElement.to === '/learn'
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hasSignInButton = component =>
|
||||||
|
component.props.children[1].props.children === 'Sign In';
|
||||||
|
|
||||||
const avatarHasClass = (componentTree, classes) => {
|
const avatarHasClass = (componentTree, classes) => {
|
||||||
|
// componentTree[1].children[0].children[1].props.className
|
||||||
return (
|
return (
|
||||||
componentTree[1].children[0].children[1].props.className ===
|
profileNavItem(componentTree).children[1].props.className ===
|
||||||
'avatar-container ' + classes
|
'avatar-container ' + classes
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||||||
import { Link, SkeletonSprite, AvatarRenderer } from '../../helpers';
|
import { Link, SkeletonSprite, AvatarRenderer } from '../../helpers';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Login from '../components/Login';
|
import Login from '../components/Login';
|
||||||
|
import { forumLocation } from '../../../../../config/env.json';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
displayMenu: PropTypes.bool,
|
displayMenu: PropTypes.bool,
|
||||||
@ -15,6 +16,26 @@ export function AuthOrProfile({ user, pending }) {
|
|||||||
const isTopContributor =
|
const isTopContributor =
|
||||||
user && user.yearsTopContributor && user.yearsTopContributor.length > 0;
|
user && user.yearsTopContributor && user.yearsTopContributor.length > 0;
|
||||||
|
|
||||||
|
const CurriculumAndForumLinks = (
|
||||||
|
<>
|
||||||
|
<li>
|
||||||
|
<Link
|
||||||
|
className='nav-link'
|
||||||
|
external={true}
|
||||||
|
sameTab={true}
|
||||||
|
to={forumLocation}
|
||||||
|
>
|
||||||
|
Forum
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<Link className='nav-link' to='/learn'>
|
||||||
|
Curriculum
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
if (pending) {
|
if (pending) {
|
||||||
return (
|
return (
|
||||||
<div className='nav-skeleton'>
|
<div className='nav-skeleton'>
|
||||||
@ -24,22 +45,14 @@ export function AuthOrProfile({ user, pending }) {
|
|||||||
} else if (!isUserSignedIn) {
|
} else if (!isUserSignedIn) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<li>
|
{CurriculumAndForumLinks}
|
||||||
<Link className='nav-link' to='/learn'>
|
|
||||||
Curriculum
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
<Login data-test-label='landing-small-cta'>Sign In</Login>
|
<Login data-test-label='landing-small-cta'>Sign In</Login>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<li>
|
{CurriculumAndForumLinks}
|
||||||
<Link className='nav-link' to='/learn'>
|
|
||||||
Curriculum
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
<li>
|
<li>
|
||||||
<Link className='nav-link' to={`/${user.username}`}>
|
<Link className='nav-link' to={`/${user.username}`}>
|
||||||
Profile
|
Profile
|
||||||
|
@ -127,7 +127,7 @@
|
|||||||
.nav-skeleton {
|
.nav-skeleton {
|
||||||
height: var(--header-height);
|
height: var(--header-height);
|
||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
width: 200px;
|
width: 350px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-list .fcc-loader {
|
.nav-list .fcc-loader {
|
||||||
@ -208,7 +208,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 999px) {
|
@media (max-width: 1079px) {
|
||||||
.site-header {
|
.site-header {
|
||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
@ -274,7 +274,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 1000px) {
|
@media (min-width: 1080px) {
|
||||||
.universal-nav-middle {
|
.universal-nav-middle {
|
||||||
flex: 1 0 30%;
|
flex: 1 0 30%;
|
||||||
margin-right: 0px;
|
margin-right: 0px;
|
||||||
|
@ -136,7 +136,7 @@ and arrow keys */
|
|||||||
right: 15px;
|
right: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 1000px) {
|
@media (min-width: 1080px) {
|
||||||
.ais-SearchBox-input {
|
.ais-SearchBox-input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 500px;
|
max-width: 500px;
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
const selectors = {
|
const selectors = {
|
||||||
heading: "[data-test-label='landing-header']",
|
heading: "[data-test-label='landing-header']",
|
||||||
smallCallToAction: "[data-test-label='landing-small-cta']",
|
smallCallToAction: "[data-test-label='landing-small-cta']",
|
||||||
firstNavigationLink: '.nav-list .nav-link:first-child',
|
navigationLinks: '.nav-list',
|
||||||
lastNavigationLink: '.nav-list .nav-link:last-child',
|
|
||||||
avatarContainer: '.avatar-container',
|
avatarContainer: '.avatar-container',
|
||||||
defaultAvatar: '.avatar-container svg'
|
defaultAvatar: '.avatar-container svg'
|
||||||
};
|
};
|
||||||
@ -12,6 +11,7 @@ const selectors = {
|
|||||||
describe('Navbar', () => {
|
describe('Navbar', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.visit('/');
|
cy.visit('/');
|
||||||
|
cy.viewport(1200, 660);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should render properly', () => {
|
it('Should render properly', () => {
|
||||||
@ -51,14 +51,16 @@ describe('Navbar', () => {
|
|||||||
|
|
||||||
// have the curriculum and CTA on landing and /learn pages.
|
// have the curriculum and CTA on landing and /learn pages.
|
||||||
it(
|
it(
|
||||||
'Should have `Curriculum` link on landing and learn pages' +
|
'Should have `Forum` and `Curriculum` links on landing and learn pages' +
|
||||||
'page when not signed in',
|
'page when not signed in',
|
||||||
() => {
|
() => {
|
||||||
cy.get(selectors.firstNavigationLink)
|
cy.get(selectors.navigationLinks).contains('Forum');
|
||||||
|
cy.get(selectors.navigationLinks)
|
||||||
.contains('Curriculum')
|
.contains('Curriculum')
|
||||||
.click();
|
.click();
|
||||||
cy.url().should('include', '/learn');
|
cy.url().should('include', '/learn');
|
||||||
cy.get(selectors.firstNavigationLink).contains('Curriculum');
|
cy.get(selectors.navigationLinks).contains('Curriculum');
|
||||||
|
cy.get(selectors.navigationLinks).contains('Forum');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -67,7 +69,7 @@ describe('Navbar', () => {
|
|||||||
'page when not signed in',
|
'page when not signed in',
|
||||||
() => {
|
() => {
|
||||||
cy.contains(selectors.smallCallToAction, 'Sign In');
|
cy.contains(selectors.smallCallToAction, 'Sign In');
|
||||||
cy.get(selectors.firstNavigationLink)
|
cy.get(selectors.navigationLinks)
|
||||||
.contains('Curriculum')
|
.contains('Curriculum')
|
||||||
.click();
|
.click();
|
||||||
cy.contains(selectors.smallCallToAction, 'Sign In');
|
cy.contains(selectors.smallCallToAction, 'Sign In');
|
||||||
@ -76,7 +78,7 @@ describe('Navbar', () => {
|
|||||||
|
|
||||||
it('Should have `Profile` link when user is signed in', () => {
|
it('Should have `Profile` link when user is signed in', () => {
|
||||||
cy.login()
|
cy.login()
|
||||||
.get(selectors.lastNavigationLink)
|
.get(selectors.navigationLinks)
|
||||||
.contains('Profile')
|
.contains('Profile')
|
||||||
.click();
|
.click();
|
||||||
cy.url().should('include', '/developmentuser');
|
cy.url().should('include', '/developmentuser');
|
||||||
|
Reference in New Issue
Block a user