Skip to content

Commit

Permalink
fixup! Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Nov 19, 2024
1 parent 8fada32 commit 2493280
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import { InMemoryCache } from '@apollo/client';
import { MockedProvider } from '@apollo/client/testing';
import userEvent from '@testing-library/user-event';
import { DateTime } from 'luxon';
import TestRouter from '__tests__/util/TestRouter';
import TestWrapper from '__tests__/util/TestWrapper';
import { render, waitFor } from '__tests__/util/testingLibraryReactMock';
import { NotificationTypeTypeEnum } from 'src/graphql/types.generated';
Expand All @@ -12,14 +14,10 @@ import {
import acknowledgeUserNotificationMutationMock from './Item.mock';
import NotificationMenuItem from '.';

jest.mock('next/router', () => ({
useRouter: () => {
return {
query: { accountListId: 'abc' },
isReady: true,
};
},
}));
const router = {
query: { accountListId: 'abc' },
isReady: true,
};

describe('NotificationMenuItem', () => {
const id = 'd1b7a8c1-9b2e-4234-b2d6-e52c151bbc7b';
Expand Down Expand Up @@ -103,7 +101,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — No call logged in the past year',
);
});
Expand All @@ -116,7 +114,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Gave a larger gift than their commitment amount',
);
});
Expand All @@ -129,7 +127,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Gave a gift of A$10,000 which is greater than their commitment amount',
);
});
Expand All @@ -142,7 +140,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Gave a gift where commitment frequency is set to semi-annual or greater',
);
});
Expand All @@ -155,7 +153,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Gave a gift of A$10,000 where commitment frequency is set to semi-annual or greater',
);
});
Expand All @@ -170,7 +168,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — On your physical newsletter list but has no mailing address',
);
});
Expand All @@ -185,7 +183,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — On your digital newsletter list but has no people with a valid email address',
);
});
Expand All @@ -200,7 +198,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Added through your Give Site subscription form',
);
});
Expand All @@ -215,7 +213,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Added and merged',
);
});
Expand All @@ -230,7 +228,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Added but not merged',
);
});
Expand All @@ -245,7 +243,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Added with no duplicate found',
);
});
Expand All @@ -258,7 +256,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Recontinued giving',
);
});
Expand All @@ -273,7 +271,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Semi-annual or greater gift is expected one month from now',
);
});
Expand All @@ -286,7 +284,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Gave a smaller gift than their commitment amount',
);
});
Expand All @@ -299,7 +297,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Gave a gift of A$10,000 which is less than their commitment amount',
);
});
Expand All @@ -312,7 +310,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Gave a special gift',
);
});
Expand All @@ -325,7 +323,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Gave a special gift of A$10,000',
);
});
Expand All @@ -338,7 +336,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Started giving',
);
});
Expand All @@ -351,7 +349,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Missed a gift',
);
});
Expand All @@ -366,7 +364,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — No thank you note logged in the past year',
);
});
Expand All @@ -381,7 +379,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Upcoming anniversary',
);
});
Expand All @@ -394,7 +392,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Upcoming birthday',
);
});
Expand All @@ -409,7 +407,7 @@ describe('NotificationMenuItem', () => {
/>
</TestWrapper>,
);
expect(getByRole('button').textContent).toEqual(
expect(getByRole('link').textContent).toEqual(
'SSmith, RogerMay 25, 2020 — Custom notification description',
);
});
Expand Down Expand Up @@ -462,19 +460,21 @@ describe('NotificationMenuItem', () => {
});
const handleClick = jest.fn();
const { getByRole } = render(
<TestWrapper
mocks={[acknowledgeUserNotificationMutationMock(id)]}
cache={cache}
>
<NotificationMenuItem
item={itemWithoutDonation(
NotificationTypeTypeEnum.CallPartnerOncePerYear,
)}
onClick={handleClick}
/>
</TestWrapper>,
<TestRouter router={router}>
<MockedProvider
mocks={[acknowledgeUserNotificationMutationMock(id)]}
cache={cache}
>
<NotificationMenuItem
item={itemWithoutDonation(
NotificationTypeTypeEnum.CallPartnerOncePerYear,
)}
onClick={handleClick}
/>
</MockedProvider>
</TestRouter>,
);
userEvent.click(getByRole('button'));
userEvent.click(getByRole('link'));
await waitFor(() => expect(handleClick).toHaveBeenCalled());
expect(cache.writeQuery).toHaveBeenCalledWith({
query: GetNotificationsDocument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ describe('NotificationMenu', () => {
).toBeInTheDocument(),
);
expect(
getByRole('button', {
getByRole('link', {
name: 'S Smith, Roger May 26, 2020 — Upcoming anniversary',
}),
).toBeInTheDocument();
expect(
getByRole('button', {
getByRole('link', {
name: 'R Robertson, Tara May 26, 2020 — Upcoming birthday',
}),
).toBeInTheDocument();
Expand Down

0 comments on commit 2493280

Please sign in to comment.