Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
#729 - enhance home page testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescd18 committed Jun 19, 2022
1 parent eb35984 commit a253ce0
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/frontend/pages/HomePage/home.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import { render, screen, routerWrapperBuilder } from '../../../test-support/test-utils';
import { routes } from '../../../shared/routes';
import Home from './home';
import { useAuth } from '../../../services/auth.hooks';
import { Auth } from '../../../shared/types';
import { exampleAdminUser } from '../../../test-support/test-data/users.stub';
import { mockAuth } from '../../../test-support/test-data/test-utils.stub';

jest.mock('./useful-links/useful-links', () => {
return {
Expand All @@ -25,6 +29,23 @@ jest.mock('./upcoming-deadlines/upcoming-deadlines', () => {
};
});

jest.mock('./work-packages-by-timeline-status/work-packages-by-timeline-status', () => {
return {
__esModule: true,
default: () => {
return <div>work-packages-by-timeline-status</div>;
}
};
});

jest.mock('../../../services/auth.hooks');

const mockedUseAuth = useAuth as jest.Mock<Auth>;

const mockAuthHook = (user = exampleAdminUser) => {
mockedUseAuth.mockReturnValue(mockAuth(false, user));
};

/**
* Sets up the component under test with the desired values and renders it.
*/
Expand All @@ -38,9 +59,13 @@ const renderComponent = () => {
};

describe('home component', () => {
beforeEach(() => {
mockAuthHook();
});

it('renders welcome', () => {
renderComponent();
expect(screen.getByText(/Welcome/i)).toBeInTheDocument();
expect(screen.getByText(`Welcome, ${exampleAdminUser.firstName}!`)).toBeInTheDocument();
});

it('renders useful links', () => {
Expand All @@ -52,4 +77,9 @@ describe('home component', () => {
renderComponent();
expect(screen.getByText('upcoming-deadlines')).toBeInTheDocument();
});

it('renders work packages by timeline status', () => {
renderComponent();
expect(screen.getByText('work-packages-by-timeline-status')).toBeInTheDocument();
});
});

0 comments on commit a253ce0

Please sign in to comment.