Skip to content

Commit

Permalink
tests extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrrsin committed Apr 26, 2024
1 parent 35d726c commit e81ca65
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
32 changes: 30 additions & 2 deletions webapp/src/components/MainPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,41 @@ describe('MainPage', () => {
useAuthUser.mockReturnValue({ username: 'testUser' });
const { getByText } = render(<MainPage />);
expect(getByText('Welcome back, testUser!')).toBeInTheDocument();
expect(getByText('Start Playing')).toBeInTheDocument();
expect(getByText('Squads')).toBeInTheDocument();
expect(getByText('My stats')).toBeInTheDocument();
});

it('renders welcome message for unauthenticated user', () => {
useIsAuthenticated.mockReturnValue(() => false);
const { getByText } = render(<MainPage />);
expect(getByText('Welcome to WIQ, Please log in to play!')).toBeInTheDocument();
});


it('navigates to /play when Start Playing button is clicked', () => {
useIsAuthenticated.mockReturnValue(() => true);
useAuthUser.mockReturnValue({ username: 'testUser' });
const { getByText } = render(<MainPage />);
fireEvent.click(getByText('Start Playing'));
expect(mock).toHaveBeenCalledWith('/play');
});
it('navigates to /squads when Squads button is clicked', () => {
useIsAuthenticated.mockReturnValue(() => true);
useAuthUser.mockReturnValue({ username: 'testUser' });
const { getByText } = render(<MainPage />);
fireEvent.click(getByText('Squads'));
expect(mock).toHaveBeenCalledWith('/squads');
});
it('navigates to /userProfile when My stats button is clicked', () => {
useIsAuthenticated.mockReturnValue(() => true);
useAuthUser.mockReturnValue({ username: 'testUser' });
const { getByText } = render(<MainPage />);
fireEvent.click(getByText('My stats'));
expect(mock).toHaveBeenCalledWith('/userProfile');
});
it('navigates to /register when Create account button is clicked', () => {
useIsAuthenticated.mockReturnValue(() => false);
const { getByText } = render(<MainPage />);
fireEvent.click(getByText('Create account'));
expect(mock).toHaveBeenCalledWith('/register');
});
});
12 changes: 12 additions & 0 deletions webapp/src/components/Navbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,17 @@ describe('Navbar', () => {
expect(getByText('Rankings')).toBeInTheDocument();
expect(getByText('Log In')).toBeInTheDocument();
});
it('calls signOut when Log out button is clicked', () => {
useIsAuthenticated.mockReturnValue(() => true);
useSignOut.mockReturnValue(() => {});
const { getByText } = render(
<MemoryRouter>
<Navbar />
</MemoryRouter>
);

fireEvent.click(getByText('Log out'));
expect(useSignOut).toHaveBeenCalled();
});

});

0 comments on commit e81ca65

Please sign in to comment.