Skip to content

Commit

Permalink
test: update mocks
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Setch <adam.setch@outlook.com>
  • Loading branch information
setchy committed Sep 20, 2024
1 parent 1ee212e commit 786f7ec
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 169 deletions.
72 changes: 70 additions & 2 deletions src/__mocks__/notifications-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
import type { AccountNotifications } from '../types';
import { mockAtlassifyNotifications } from '../utils/api/__mocks__/response-mocks';
import { BitbucketIcon, ConfluenceIcon } from '@atlaskit/logo';
import type {
AccountNotifications,
AtlassifyNotification,
Link,
} from '../types';
import { mockAtlassianCloudAccount } from './state-mocks';

export const mockAtlassifyNotifications: AtlassifyNotification[] = [
{
account: mockAtlassianCloudAccount,
id: '138661096',
title: 'I am a robot and this is a test!',
unread: true,
updated_at: '2020-09-13T21:12:16.662Z',
entity: {
title: 'Repository',
iconUrl: 'https://github.atlassify.io/favicon.ico' as Link,
url: 'https://github.atlassify.io/myorg/notifications-test' as Link,
},
path: {
title: 'Repository',
iconUrl: 'https://github.atlassify.io/favicon.ico' as Link,
url: 'https://github.atlassify.io/myorg/notifications-test' as Link,
},
product: {
name: 'bitbucket',
icon: BitbucketIcon,
},
actor: {
displayName: 'atlassify-app',
avatarURL:
'https://avatars.githubusercontent.com/u/133795385?s=200&v=4' as Link,
},
category: 'direct',
readState: 'unread',
url: 'https://api.github.com/notifications/threads/138661096' as Link,
},
{
id: '148827438',
title: 'I am a robot and this is a test!',
unread: true,
updated_at: '2020-09-13T21:12:16.662Z',
entity: {
title: 'Repository',
iconUrl: 'https://github.atlassify.io/favicon.ico' as Link,
url: 'https://github.atlassify.io/myorg/notifications-test' as Link,
},
path: {
title: 'Repository',
iconUrl: 'https://github.atlassify.io/favicon.ico' as Link,
url: 'https://github.atlassify.io/myorg/notifications-test' as Link,
},
product: {
name: 'confluence',
icon: ConfluenceIcon,
},
actor: {
displayName: 'atlassify-app',
avatarURL:
'https://avatars.githubusercontent.com/u/133795385?s=200&v=4' as Link,
},
category: 'direct',
readState: 'unread',
account: mockAtlassianCloudAccount,
url: 'https://api.github.com/notifications/threads/148827438' as Link,
},
];

export const mockSingleNotification: AtlassifyNotification =
mockAtlassifyNotifications[0];

export const mockAccountNotifications: AccountNotifications[] = [
{
account: mockAtlassianCloudAccount,
Expand Down
2 changes: 1 addition & 1 deletion src/components/AccountNotifications.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { act, fireEvent, render, screen } from '@testing-library/react';
import { mockAtlassifyNotifications } from '../__mocks__/notifications-mocks';
import {
mockAtlassianCloudAccount,
mockSettings,
} from '../__mocks__/state-mocks';
import { ensureStableEmojis, mockDirectoryPath } from '../__mocks__/utils';
import { AppContext } from '../context/App';
import { mockAtlassifyNotifications } from '../utils/api/__mocks__/response-mocks';
import * as links from '../utils/links';
import { AccountNotifications } from './AccountNotifications';

Expand Down
2 changes: 1 addition & 1 deletion src/components/NotificationRow.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { mockSingleNotification } from '../__mocks__/notifications-mocks';
import {
mockAtlassianCloudAccount,
mockAuth,
mockSettings,
} from '../__mocks__/state-mocks';
import { AppContext } from '../context/App';
import { mockSingleNotification } from '../utils/api/__mocks__/response-mocks';
import type { ReadState } from '../utils/api/types';
import * as comms from '../utils/comms';
import * as links from '../utils/links';
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProductNotifications.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { act, fireEvent, render, screen } from '@testing-library/react';
import { mockAtlassifyNotifications } from '../__mocks__/notifications-mocks';
import {
mockAtlassianCloudAccount,
mockSettings,
} from '../__mocks__/state-mocks';
import { AppContext } from '../context/App';
import { mockAtlassifyNotifications } from '../utils/api/__mocks__/response-mocks';
import type { Product } from '../utils/api/types';
import * as comms from '../utils/comms';
import { ProductNotifications } from './ProductNotifications';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Spinner from '@atlaskit/spinner';
import Toggle from '@atlaskit/toggle';
import { AppContext } from '../context/App';
import { quitApp } from '../utils/comms';
import { getFilterCount } from '../utils/helpers';
import { getFilterCount } from '../utils/filters';
import { openMyNotifications } from '../utils/links';
import { getNotificationCount } from '../utils/notifications/notifications';

Expand Down
32 changes: 16 additions & 16 deletions src/components/__snapshots__/AccountNotifications.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/components/__snapshots__/NotificationRow.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/context/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { act, fireEvent, render, waitFor } from '@testing-library/react';
import type { AxiosPromise, AxiosResponse } from 'axios';
import { useContext } from 'react';
import { mockSingleNotification } from '../__mocks__/notifications-mocks';
import { mockAuth, mockSettings } from '../__mocks__/state-mocks';
import { useNotifications } from '../hooks/useNotifications';
import type { AuthState, SettingsState, Token, Username } from '../types';
import { mockSingleNotification } from '../utils/api/__mocks__/response-mocks';
import * as apiRequests from '../utils/api/request';
import * as comms from '../utils/comms';
import { Constants } from '../utils/constants';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import axios, { AxiosError } from 'axios';
import nock from 'nock';

import log from 'electron-log';
import { mockSingleNotification } from '../__mocks__/notifications-mocks';
import { mockAuth, mockSettings, mockState } from '../__mocks__/state-mocks';
import { mockSingleNotification } from '../utils/api/__mocks__/response-mocks';
import { Errors } from '../utils/errors';
import { useNotifications } from './useNotifications';

Expand Down
67 changes: 0 additions & 67 deletions src/utils/api/__mocks__/response-mocks.ts

This file was deleted.

35 changes: 35 additions & 0 deletions src/utils/filters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { defaultSettings } from '../context/App';
import type { SettingsState } from '../types';
import { getFilterCount } from './filters';

describe('utils/filters.ts', () => {
describe('filter count', () => {
it('default filter settings', () => {
expect(getFilterCount(defaultSettings)).toBe(0);
});

it('non-default category filters', () => {
const settings = {
...defaultSettings,
filterCategories: ['direct'],
} as SettingsState;
expect(getFilterCount(settings)).toBe(1);
});

it('non-default read state filters', () => {
const settings = {
...defaultSettings,
filterReadStates: ['read'],
} as SettingsState;
expect(getFilterCount(settings)).toBe(1);
});

it('non-default product filters', () => {
const settings = {
...defaultSettings,
filterProducts: ['bitbucket'],
} as SettingsState;
expect(getFilterCount(settings)).toBe(1);
});
});
});
Loading

0 comments on commit 786f7ec

Please sign in to comment.