2019-09-19 19:45:01 +03:00
|
|
|
/* global expect */
|
|
|
|
import React from 'react';
|
|
|
|
import ShallowRenderer from 'react-test-renderer/shallow';
|
|
|
|
import TestRenderer from 'react-test-renderer';
|
2019-10-04 18:00:17 +03:00
|
|
|
import { UniversalNav } from './components/UniversalNav';
|
2019-09-19 19:45:01 +03:00
|
|
|
import NavLinks from './components/NavLinks';
|
|
|
|
|
2020-08-14 11:56:14 +02:00
|
|
|
import { forumLocation } from '../../../config/env.json';
|
|
|
|
|
2019-10-04 18:00:17 +03:00
|
|
|
describe('<UniversalNav />', () => {
|
2019-09-19 19:45:01 +03:00
|
|
|
it('renders to the DOM', () => {
|
|
|
|
const shallow = new ShallowRenderer();
|
2019-10-04 18:00:17 +03:00
|
|
|
shallow.render(<UniversalNav {...UniversalNavProps} />);
|
2019-09-19 19:45:01 +03:00
|
|
|
const result = shallow.getRenderOutput();
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('<NavLinks />', () => {
|
|
|
|
const root = TestRenderer.create(<NavLinks />).root;
|
|
|
|
const aTags = root.findAllByType('a');
|
|
|
|
|
|
|
|
// reduces the aTags to href links
|
|
|
|
const links = aTags.reduce((acc, item) => {
|
|
|
|
acc.push(item._fiber.pendingProps.href);
|
|
|
|
return acc;
|
|
|
|
}, []);
|
|
|
|
|
2020-08-14 11:56:14 +02:00
|
|
|
const expectedLinks = ['/learn', '/news', forumLocation];
|
2019-09-19 19:45:01 +03:00
|
|
|
|
|
|
|
it('renders to the DOM', () => {
|
|
|
|
expect(root).toBeTruthy();
|
|
|
|
});
|
2019-10-22 13:38:19 +03:00
|
|
|
it('has 3 links', () => {
|
|
|
|
expect(aTags.length === 3).toBeTruthy();
|
2019-09-19 19:45:01 +03:00
|
|
|
});
|
|
|
|
|
2019-10-16 17:09:31 +03:00
|
|
|
it('has links to news, forum, learn and portfolio', () => {
|
2019-09-19 19:45:01 +03:00
|
|
|
// checks if all links in expected links exist in links
|
|
|
|
expect(expectedLinks.every(elem => links.indexOf(elem) > -1)).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2019-10-04 18:00:17 +03:00
|
|
|
|
|
|
|
const UniversalNavProps = {
|
|
|
|
displayMenu: false,
|
|
|
|
menuButtonRef: {},
|
2019-10-07 13:33:47 +01:00
|
|
|
searchBarRef: {},
|
2019-10-04 18:00:17 +03:00
|
|
|
toggleDisplayMenu: function() {}
|
|
|
|
};
|