Skip to content

Commit 344ac52

Browse files
committed
tests: add tests for markRepoNotificationsDone
1 parent fa65359 commit 344ac52

File tree

3 files changed

+154
-3
lines changed

3 files changed

+154
-3
lines changed

src/components/Repository.test.tsx

+18-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jest.mock('./NotificationRow', () => ({
1414

1515
describe('components/Repository.tsx', () => {
1616
const markRepoNotifications = jest.fn();
17+
const markRepoNotificationsDone = jest.fn();
1718

1819
const props = {
1920
hostname: 'github.com',
@@ -52,17 +53,32 @@ describe('components/Repository.tsx', () => {
5253
});
5354

5455
it('should mark a repo as read', function () {
55-
const { getByRole } = render(
56+
const { getByTitle } = render(
5657
<AppContext.Provider value={{ markRepoNotifications }}>
5758
<RepositoryNotifications {...props} />
5859
</AppContext.Provider>,
5960
);
6061

61-
fireEvent.click(getByRole('button'));
62+
fireEvent.click(getByTitle('Mark Repository as Read'));
6263

6364
expect(markRepoNotifications).toHaveBeenCalledWith(
6465
'manosim/notifications-test',
6566
'github.com',
6667
);
6768
});
69+
70+
it('should mark a repo as done', function () {
71+
const { getByTitle } = render(
72+
<AppContext.Provider value={{ markRepoNotificationsDone }}>
73+
<RepositoryNotifications {...props} />
74+
</AppContext.Provider>,
75+
);
76+
77+
fireEvent.click(getByTitle('Mark Repository as Done'));
78+
79+
expect(markRepoNotificationsDone).toHaveBeenCalledWith(
80+
'manosim/notifications-test',
81+
'github.com',
82+
);
83+
});
6884
});

src/components/__snapshots__/Repository.test.tsx.snap

+33-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,40 @@ exports[`components/Repository.tsx should render itself & its children 1`] = `
1919
</span>
2020
</div>
2121
<div
22-
className="flex justify-center items-center"
22+
className="flex justify-center items-center gap-2"
2323
>
24+
<button
25+
className="focus:outline-none h-full hover:text-green-500"
26+
onClick={[Function]}
27+
title="Mark Repository as Done"
28+
>
29+
<svg
30+
aria-hidden="false"
31+
aria-label="Mark Repository as Done"
32+
className="octicon octicon-check"
33+
fill="currentColor"
34+
focusable="false"
35+
height={16}
36+
role="img"
37+
style={
38+
{
39+
"display": "inline-block",
40+
"overflow": "visible",
41+
"userSelect": "none",
42+
"verticalAlign": "text-bottom",
43+
}
44+
}
45+
viewBox="0 0 16 16"
46+
width={16}
47+
>
48+
<path
49+
d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"
50+
/>
51+
</svg>
52+
</button>
53+
<div
54+
className="w-[14px]"
55+
/>
2456
<button
2557
className="focus:outline-none h-full hover:text-green-500"
2658
onClick={[Function]}

src/hooks/useNotifications.test.ts

+103
Original file line numberDiff line numberDiff line change
@@ -636,4 +636,107 @@ describe('hooks/useNotifications.ts', () => {
636636
});
637637
});
638638
});
639+
640+
describe('markRepoNotificationsDone', () => {
641+
const repoSlug = 'manosim/gitify';
642+
const id = 'notification-123';
643+
644+
describe('github.com', () => {
645+
const accounts = { ...mockAccounts, enterpriseAccounts: [] };
646+
const hostname = 'github.com';
647+
648+
it("should mark a repository's notifications as done with success - github.com", async () => {
649+
nock('https://api.github.com/')
650+
.delete(`/notifications/threads/${id}`)
651+
.reply(200);
652+
653+
const { result } = renderHook(() => useNotifications(false));
654+
655+
act(() => {
656+
result.current.markRepoNotificationsDone(
657+
accounts,
658+
repoSlug,
659+
hostname,
660+
);
661+
});
662+
663+
await waitFor(() => {
664+
expect(result.current.isFetching).toBe(false);
665+
});
666+
667+
expect(result.current.notifications.length).toBe(0);
668+
});
669+
670+
it("should mark a repository's notifications as done with failure - github.com", async () => {
671+
nock('https://api.github.com/')
672+
.delete(`/notifications/threads/${id}`)
673+
.reply(400);
674+
675+
const { result } = renderHook(() => useNotifications(false));
676+
677+
act(() => {
678+
result.current.markRepoNotificationsDone(
679+
accounts,
680+
repoSlug,
681+
hostname,
682+
);
683+
});
684+
685+
await waitFor(() => {
686+
expect(result.current.isFetching).toBe(false);
687+
});
688+
689+
expect(result.current.notifications.length).toBe(0);
690+
});
691+
});
692+
693+
describe('enterprise', () => {
694+
const accounts = { ...mockAccounts, token: null };
695+
const hostname = 'github.gitify.io';
696+
697+
it("should mark a repository's notifications as done with success - enterprise", async () => {
698+
nock('https://api.github.com/')
699+
.delete(`/notifications/threads/${id}`)
700+
.reply(200);
701+
702+
const { result } = renderHook(() => useNotifications(false));
703+
704+
act(() => {
705+
result.current.markRepoNotificationsDone(
706+
accounts,
707+
repoSlug,
708+
hostname,
709+
);
710+
});
711+
712+
await waitFor(() => {
713+
expect(result.current.isFetching).toBe(false);
714+
});
715+
716+
expect(result.current.notifications.length).toBe(0);
717+
});
718+
719+
it("should mark a repository's notifications as done with failure - enterprise", async () => {
720+
nock('https://api.github.com/')
721+
.delete(`/notifications/threads/${id}`)
722+
.reply(400);
723+
724+
const { result } = renderHook(() => useNotifications(false));
725+
726+
act(() => {
727+
result.current.markRepoNotificationsDone(
728+
accounts,
729+
repoSlug,
730+
hostname,
731+
);
732+
});
733+
734+
await waitFor(() => {
735+
expect(result.current.isFetching).toBe(false);
736+
});
737+
738+
expect(result.current.notifications.length).toBe(0);
739+
});
740+
});
741+
});
639742
});

0 commit comments

Comments
 (0)