From e81ca65e4abb41228a01f015644efa7327fc3aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Cadenas?= <77900120+andrrsin@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:12:59 +0200 Subject: [PATCH] tests extensions --- webapp/src/components/MainPage.test.js | 32 ++++++++++++++++++++++++-- webapp/src/components/Navbar.test.js | 12 ++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/MainPage.test.js b/webapp/src/components/MainPage.test.js index f91691e..4efc663 100644 --- a/webapp/src/components/MainPage.test.js +++ b/webapp/src/components/MainPage.test.js @@ -18,6 +18,9 @@ describe('MainPage', () => { useAuthUser.mockReturnValue({ username: 'testUser' }); const { getByText } = render(); 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', () => { @@ -25,6 +28,31 @@ describe('MainPage', () => { const { getByText } = render(); 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(); + 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(); + 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(); + 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(); + fireEvent.click(getByText('Create account')); + expect(mock).toHaveBeenCalledWith('/register'); + }); }); \ No newline at end of file diff --git a/webapp/src/components/Navbar.test.js b/webapp/src/components/Navbar.test.js index b94af19..2327945 100644 --- a/webapp/src/components/Navbar.test.js +++ b/webapp/src/components/Navbar.test.js @@ -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( + + + + ); + + fireEvent.click(getByText('Log out')); + expect(useSignOut).toHaveBeenCalled(); + }); });