Skip to content
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 src/__mocks__/mock-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const mockSettings: SettingsState = {
participating: false,
playSound: true,
showNotifications: true,
showBots: true,
openAtStartup: false,
appearance: Appearance.SYSTEM,
colors: false,
Expand Down
22 changes: 22 additions & 0 deletions src/__mocks__/mockedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-20T18:33:39Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [],
Expand All @@ -309,6 +310,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-21T03:30:42Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [],
Expand All @@ -319,6 +321,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-21T18:26:27Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [
Expand All @@ -327,6 +330,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-23T00:57:58Z',
author: {
login: 'reply-user',
type: 'User',
},
},
],
Expand All @@ -337,6 +341,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-23T00:57:49Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [],
Expand All @@ -347,6 +352,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-27T01:22:20Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [
Expand All @@ -355,6 +361,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-03-05T17:43:52Z',
author: {
login: 'reply-user',
type: 'User',
},
},
],
Expand All @@ -365,6 +372,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-03-04T20:39:44Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [
Expand All @@ -373,6 +381,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-03-05T17:41:04Z',
author: {
login: 'reply-user',
type: 'User',
},
},
],
Expand All @@ -383,6 +392,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-03-05T11:05:42Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [
Expand All @@ -391,6 +401,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-03-05T17:41:44Z',
author: {
login: 'reply-user',
type: 'User',
},
},
],
Expand All @@ -412,6 +423,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-20T18:33:39Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [],
Expand All @@ -422,6 +434,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-21T03:30:42Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [],
Expand All @@ -432,6 +445,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-21T18:26:27Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [
Expand All @@ -440,6 +454,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-23T00:57:58Z',
author: {
login: 'reply-user',
type: 'User',
},
},
],
Expand All @@ -450,6 +465,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-23T00:57:49Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [],
Expand All @@ -460,6 +476,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-02-27T01:22:20Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [
Expand All @@ -468,6 +485,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-03-05T17:43:52Z',
author: {
login: 'reply-user',
type: 'User',
},
},
],
Expand All @@ -478,6 +496,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-03-04T20:39:44Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [
Expand All @@ -486,6 +505,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-03-05T17:41:04Z',
author: {
login: 'reply-user',
type: 'User',
},
},
],
Expand All @@ -496,6 +516,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-03-05T11:05:42Z',
author: {
login: 'comment-user',
type: 'User',
},
replies: {
nodes: [
Expand All @@ -504,6 +525,7 @@ export const mockedGraphQLResponse: GraphQLSearch<Discussion> = {
createdAt: '2022-03-05T17:41:44Z',
author: {
login: 'reply-user',
type: 'User',
},
},
],
Expand Down
2 changes: 2 additions & 0 deletions src/context/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ describe('context/App.tsx', () => {
participating: true,
playSound: true,
showNotifications: true,
showBots: true,
colors: null,
markAsDoneOnOpen: false,
},
Expand Down Expand Up @@ -328,6 +329,7 @@ describe('context/App.tsx', () => {
participating: false,
playSound: true,
showNotifications: true,
showBots: true,
colors: null,
markAsDoneOnOpen: false,
},
Expand Down
3 changes: 2 additions & 1 deletion src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const defaultSettings: SettingsState = {
participating: false,
playSound: true,
showNotifications: true,
showBots: true,
openAtStartup: false,
appearance: Appearance.SYSTEM,
colors: null,
Expand Down Expand Up @@ -91,7 +92,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {

useEffect(() => {
fetchNotifications(accounts, settings);
}, [settings.participating]);
}, [settings.participating, settings.showBots]);

useEffect(() => {
fetchNotifications(accounts, settings);
Expand Down
100 changes: 96 additions & 4 deletions src/hooks/useNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,30 @@ describe('hooks/useNotifications.ts', () => {

nock('https://api.github.com')
.get('/3')
.reply(200, { state: 'closed', merged: true });
.reply(200, {
state: 'closed',
merged: true,
user: {
login: 'some-user',
type: 'User',
},
});
nock('https://api.github.com')
.get('/3/comments')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter', type: 'User' } });
nock('https://api.github.com')
.get('/4')
.reply(200, { state: 'closed', merged: false });
.reply(200, {
state: 'closed',
merged: false,
user: {
login: 'some-user',
type: 'User',
},
});
nock('https://api.github.com')
.get('/4/comments')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter', type: 'User' } });

const { result } = renderHook(() => useNotifications(true));

Expand All @@ -332,6 +346,84 @@ describe('hooks/useNotifications.ts', () => {
expect(result.current.notifications[0].notifications.length).toBe(6);
});
});

describe('showBots', () => {
it('should hide bot notifications when set to false', async () => {
const accounts: AuthState = {
...mockAccounts,
enterpriseAccounts: [],
user: mockedUser,
};

const notifications = [
{
id: 1,
subject: {
title: 'This is an Issue.',
type: 'Issue',
url: 'https://api.github.com/1',
latest_comment_url: null,
},
repository: {
full_name: 'some/repo',
},
},
{
id: 2,
subject: {
title: 'This is a Pull Request.',
type: 'PullRequest',
url: 'https://api.github.com/2',
latest_comment_url: null,
},
repository: {
full_name: 'some/repo',
},
},
];

nock('https://api.github.com')
.get('/notifications?participating=false')
.reply(200, notifications);
nock('https://api.github.com')
.get('/1')
.reply(200, {
state: 'closed',
merged: true,
user: {
login: 'some-user',
type: 'User',
},
});
nock('https://api.github.com')
.get('/2')
.reply(200, {
state: 'closed',
merged: false,
user: {
login: 'some-bot',
type: 'Bot',
},
});

const { result } = renderHook(() => useNotifications(true));

act(() => {
result.current.fetchNotifications(accounts, {
...mockSettings,
showBots: false,
});
});

expect(result.current.isFetching).toBe(true);

await waitFor(() => {
expect(result.current.notifications[0].hostname).toBe('github.com');
});

expect(result.current.notifications[0].notifications.length).toBe(1);
});
});
});

describe('removeNotificationFromState', () => {
Expand Down
Loading