Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for failing tests in member profile page #554

Merged
merged 2 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
'^@store(.*)$': '<rootDir>/src/store$1',
'^@helper-functions(.*)$': '<rootDir>/src/helper-functions$1',
'^@constants(.*)$': '<rootDir>/src/constants$1',
'^@custom-hooks(.*)$': '<rootDir>/src/custom-hooks$1',
},
};
6 changes: 3 additions & 3 deletions src/store/keyboard/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<KeyboardContext.Provider value={initialValue}>
<KeyboardContext.Provider value={initialValue || value}>
{children}
</KeyboardContext.Provider>
);
Expand Down
63 changes: 48 additions & 15 deletions src/test/unit/components/member-profile/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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', () => {
render(
<UserContextProvider value={initialUserContext}>
<TaskContextProvider>
<Profile membersData={notaMember} />
</TaskContextProvider>
</UserContextProvider>
<KeyboardProvider
initialValue={{
isOptionKeyPressed: true,
setIsOptionKeyPressed: jest.fn(),
}}
>
<UserContextProvider value={initialUserContext}>
<TaskContextProvider>
<Profile membersData={notaMember} />
</TaskContextProvider>
</UserContextProvider>
</KeyboardProvider>
);

let memberStatus = screen.getByText('User is not a Member');
expect(memberStatus).toBeInTheDocument();

render(
<UserContextProvider value={initialUserContext}>
<TaskContextProvider>
<Profile membersData={isaMember} />
</TaskContextProvider>
</UserContextProvider>
<KeyboardProvider
initialValue={{
isOptionKeyPressed: true,
setIsOptionKeyPressed: jest.fn(),
}}
>
<UserContextProvider value={initialUserContext}>
<TaskContextProvider>
<Profile membersData={isaMember} />
</TaskContextProvider>
</UserContextProvider>
</KeyboardProvider>
);

memberStatus = screen.getByText('User is a Member');
Expand All @@ -46,11 +72,18 @@ describe('Members Profile', () => {

it('Should render the info icon correctly', () => {
render(
<UserContextProvider value={initialUserContext}>
<TaskContextProvider>
<Profile membersData={notaMember} />
</TaskContextProvider>
</UserContextProvider>
<KeyboardProvider
initialValue={{
isOptionKeyPressed: true,
setIsOptionKeyPressed: jest.fn(),
}}
>
<UserContextProvider value={initialUserContext}>
<TaskContextProvider>
<Profile membersData={notaMember} />
</TaskContextProvider>
</UserContextProvider>
</KeyboardProvider>
);

const icon = screen.getByAltText('info icon');
Expand Down
Loading