Skip to content

Commit

Permalink
update query mock in home test
Browse files Browse the repository at this point in the history
  • Loading branch information
garyjzhao committed Oct 21, 2024
1 parent 288e094 commit eede462
Showing 1 changed file with 47 additions and 51 deletions.
98 changes: 47 additions & 51 deletions src/features/Home/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ import {
} from '@testing-library/react';
import {
GetFavoritesDocument,
GetFavoritesQuery,
GetHomepageSettingsDocument,
ModelPlanFilter,
ModelStatus,
TeamRole,
ViewCustomizationType
} from 'gql/generated/graphql';
import { set } from 'lodash';
import configureMockStore from 'redux-mock-store';
import { modelPlanCollectionMock } from 'tests/mock/general';
import VerboseMockedProvider from 'tests/MockedProvider';

import MessageProvider from 'contexts/MessageContext';

import HomeNew from '.';

type FavoritesType = GetFavoritesQuery['modelPlanCollection'][0];

vi.mock('@okta/okta-react', () => ({
useOktaAuth: () => {
return {
Expand All @@ -35,6 +41,44 @@ vi.mock('@okta/okta-react', () => ({
}
}));

const mockModel: FavoritesType = {
id: '0186774a-80b0-454c-b69e-c4e949343483',
modelName: 'Plan For General Characteristics',
nameHistory: ['first', 'second'],
isFavorite: true,
status: ModelStatus.PLAN_DRAFT,
isCollaborator: false,
echimpCRsAndTDLs: [
{
id: '123',
__typename: 'EChimpCR'
},
{
id: '456',
__typename: 'EChimpTDL'
}
],
basics: {
id: '123',
performancePeriodStarts: '2022-06-03T17:41:40.962971Z',
goal: 'The goal',
__typename: 'PlanBasics'
},
collaborators: [
{
userAccount: {
id: '890',
__typename: 'UserAccount',
commonName: 'Test User'
},
id: '2134234',
teamRoles: [TeamRole.MODEL_LEAD],
__typename: 'PlanCollaborator'
}
],
__typename: 'ModelPlan'
};

const settingsMock = [
{
request: {
Expand All @@ -60,55 +104,7 @@ const settingsMock = [
},
result: {
data: {
modelPlanCollection: [
{
id: 'e671f056-2634-4af4-abad-a63850832a0a',
modelName: 'Plan With Collaborators',
isFavorite: true,
nameHistory: ['Plan With Collaborators'],
isCollaborator: true,
status: 'PLAN_DRAFT',
basics: {
id: '3a1584a5-6712-4ab8-8832-86faa183d3b1',
goal: null,
performancePeriodStarts: null,
__typename: 'PlanBasics'
},
collaborators: [
{
id: '064c52cf-854f-4c53-acdf-ab27ffb9cca5',
userAccount: {
id: '83bb8c56-b871-43e5-9fe4-2701ad6c593e',
commonName: 'MINT Doe',
__typename: 'UserAccount'
},
teamRoles: ['MODEL_LEAD'],
__typename: 'PlanCollaborator'
},
{
id: 'c6866efe-30d3-4926-bf50-68d9a0150cb0',
userAccount: {
id: 'ae6ed775-b4de-4b82-ab19-75c03a907726',
commonName: 'BTAL Doe',
__typename: 'UserAccount'
},
teamRoles: ['LEADERSHIP'],
__typename: 'PlanCollaborator'
}
],
echimpCRsAndTDLs: [
{
id: '123',
__typename: 'EChimpCR'
},
{
id: '456',
__typename: 'EChimpTDL'
}
],
__typename: 'ModelPlan'
}
]
modelPlanCollection: [mockModel]
}
}
}
Expand All @@ -127,7 +123,7 @@ describe('The home page', () => {
it('renders empty message for no settings selected', async () => {
const { getByText, getByTestId } = render(
<MemoryRouter initialEntries={[`/`]}>
<MockedProvider
<VerboseMockedProvider
mocks={[
...settingsMock,
...modelPlanCollectionMock(ModelPlanFilter.INCLUDE_ALL),
Expand All @@ -142,7 +138,7 @@ describe('The home page', () => {
</MessageProvider>
</Provider>
</Route>
</MockedProvider>
</VerboseMockedProvider>
</MemoryRouter>
);

Expand Down

0 comments on commit eede462

Please sign in to comment.