Skip to content

Commit

Permalink
test(LandingNav): complete LandingNav testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertazimi committed Aug 4, 2021
1 parent 5f9f24b commit 40f41db
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/components/LandingNav/LandingNav.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { render, fireEvent } from '@testing-library/react';
import { Routes } from '@config';
import LandingNav from './LandingNav';

describe('LandingNav', () => {
test('should render routes correctly (snapshot)', () => {
const component = renderer.create(<LandingNav routes={Routes} />);
let tree = component.toJSON() as renderer.ReactTestRendererJSON[];

expect(tree).toMatchSnapshot();
renderer.act(() => tree[1].props.onClick());
tree = component.toJSON() as renderer.ReactTestRendererJSON[];
expect(tree).toMatchSnapshot();
});

test('should render route with correct structure', () => {
const { getByRole, getAllByRole } = render(<LandingNav routes={Routes} />);
const nav = getByRole('navigation');
const links = getAllByRole('link');
const button = getByRole('button');
const icon = getByRole('img');

expect(nav).toBeInTheDocument();
links.forEach((link) => expect(link).toBeInTheDocument());
expect(button).toBeInTheDocument();
expect(icon).toBeInTheDocument();

links.forEach((link) => expect(nav).toContainElement(link));
expect(button).toContainElement(icon);
});

test('should expanded when clicked', () => {
const { getByRole } = render(<LandingNav routes={Routes} />);
const nav = getByRole('navigation');
const overlay = getByRole('banner');
const button = getByRole('button');

fireEvent.click(button);
expect(nav).toHaveClass('translate-x-0');
expect(overlay).toHaveClass('bg-opacity-80');
});
});

0 comments on commit 40f41db

Please sign in to comment.