From d5234584c58908cf7f56113fefd2720b15cf7a69 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 10 Sep 2023 14:27:08 +0530 Subject: [PATCH 1/2] fix for failing tests in member profile page --- jest.config.js | 1 + src/store/keyboard/context.js | 6 +- .../components/member-profile/index.test.js | 65 ++++++++++++++----- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/jest.config.js b/jest.config.js index aad1cc9d..cc4721ae 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,5 +8,6 @@ module.exports = { '^@store(.*)$': '/src/store$1', '^@helper-functions(.*)$': '/src/helper-functions$1', '^@constants(.*)$': '/src/constants$1', + '^@custom-hooks(.*)$': '/src/custom-hooks$1', }, }; diff --git a/src/store/keyboard/context.js b/src/store/keyboard/context.js index 63361209..22aa4626 100644 --- a/src/store/keyboard/context.js +++ b/src/store/keyboard/context.js @@ -2,16 +2,16 @@ import { createContext, useContext, useState } from 'react'; const KeyboardContext = createContext(); -export const KeyboardProvider = ({ children }) => { +export const KeyboardProvider = ({ children, initialValue }) => { const [isOptionKeyPressed, setIsOptionKeyPressed] = useState(false); - const initialValue = { + const value = { isOptionKeyPressed, setIsOptionKeyPressed, }; return ( - + {children} ); diff --git a/src/test/unit/components/member-profile/index.test.js b/src/test/unit/components/member-profile/index.test.js index 5c53a91a..33fada76 100644 --- a/src/test/unit/components/member-profile/index.test.js +++ b/src/test/unit/components/member-profile/index.test.js @@ -2,6 +2,7 @@ import { render, screen } from '@testing-library/react'; import Profile from '@components/member-profile'; import { TaskContextProvider } from '@store/tasks/tasks-context'; import { UserContextProvider } from '@store/user/user-context'; +import { KeyboardProvider } from '@store/keyboard/context'; const notaMember = { roles: { @@ -20,24 +21,49 @@ const initialUserContext = { isSuperUser: true, }; +jest.mock('next/router', () => { + return { + useRouter: jest.fn().mockReturnValue({ + query: { + dev: true, + }, + }), + }; +}); + describe('Members Profile', () => { - it('Should render member status properly', () => { + it('Should render member status properly', async () => { render( - - - - - + + + + + + + ); let memberStatus = screen.getByText('User is not a Member'); expect(memberStatus).toBeInTheDocument(); + render( - - - - - + + + + + + + ); memberStatus = screen.getByText('User is a Member'); @@ -46,11 +72,18 @@ describe('Members Profile', () => { it('Should render the info icon correctly', () => { render( - - - - - + + + + + + + ); const icon = screen.getByAltText('info icon'); From fb57d96e73143286336ad9f23807fe3b21d769d3 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 10 Sep 2023 14:29:56 +0530 Subject: [PATCH 2/2] removed async added by mistake --- src/test/unit/components/member-profile/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/unit/components/member-profile/index.test.js b/src/test/unit/components/member-profile/index.test.js index 33fada76..d3244232 100644 --- a/src/test/unit/components/member-profile/index.test.js +++ b/src/test/unit/components/member-profile/index.test.js @@ -32,7 +32,7 @@ jest.mock('next/router', () => { }); describe('Members Profile', () => { - it('Should render member status properly', async () => { + it('Should render member status properly', () => { render(