From f1b9b15a340f59209a82c0559f36f98fa7e8e26a Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 01:07:33 +0000 Subject: [PATCH 01/14] ignore development code block --- src/js/store/configureStore.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/store/configureStore.ts b/src/js/store/configureStore.ts index 0781aae1a..434c0120e 100644 --- a/src/js/store/configureStore.ts +++ b/src/js/store/configureStore.ts @@ -34,6 +34,7 @@ export default function configureStore() { storageMiddleware, ]; + /* istanbul ignore next */ if (isDev) { const { createLogger } = require('redux-logger'); const logger = createLogger({ collapsed: true }); From 88d9c24868a646f322ee26ec29be64c9f036529a Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 01:07:52 +0000 Subject: [PATCH 02/14] test untested cases --- src/js/utils/__snapshots__/github-api.test.ts.snap | 7 +++++++ src/js/utils/github-api.test.ts | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/js/utils/__snapshots__/github-api.test.ts.snap b/src/js/utils/__snapshots__/github-api.test.ts.snap index 00b13d719..deb0d7a85 100644 --- a/src/js/utils/__snapshots__/github-api.test.ts.snap +++ b/src/js/utils/__snapshots__/github-api.test.ts.snap @@ -78,6 +78,13 @@ Object { `; exports[`./utils/github-api.ts should format the notification reason 12`] = ` +Object { + "description": undefined, + "type": "Workflow Run", +} +`; + +exports[`./utils/github-api.ts should format the notification reason 13`] = ` Object { "description": "The reason for this notification is not supported by the app.", "type": "Unknown", diff --git a/src/js/utils/github-api.test.ts b/src/js/utils/github-api.test.ts index 68f4a89a3..27eb705dd 100644 --- a/src/js/utils/github-api.test.ts +++ b/src/js/utils/github-api.test.ts @@ -14,6 +14,7 @@ describe('./utils/github-api.ts', () => { expect(formatReason('state_change')).toMatchSnapshot(); expect(formatReason('subscribed')).toMatchSnapshot(); expect(formatReason('team_mention')).toMatchSnapshot(); + expect(formatReason('ci_activity')).toMatchSnapshot(); expect(formatReason('something_else_unknown' as Reason)).toMatchSnapshot(); }); @@ -25,6 +26,7 @@ describe('./utils/github-api.ts', () => { expect(getNotificationTypeIcon('RepositoryVulnerabilityAlert')).toBe( 'alert' ); + expect(getNotificationTypeIcon('CheckSuite')).toBe('sync'); expect(getNotificationTypeIcon('Unknown' as SubjectType)).toBe('question'); }); }); From f15c520732530838750130c587a40c0e5d758c39 Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 01:28:52 +0000 Subject: [PATCH 03/14] test notification and login states --- src/js/components/sidebar.test.tsx | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/js/components/sidebar.test.tsx b/src/js/components/sidebar.test.tsx index 3eb132432..eec589100 100644 --- a/src/js/components/sidebar.test.tsx +++ b/src/js/components/sidebar.test.tsx @@ -42,20 +42,39 @@ describe('components/Sidebar.tsx', () => { clock.clearAllTimers(); }); - it('should test the mapStateToProps method', () => { + describe('mapStateToProps', () => { const state = { auth: { token: '12345', enterpriseAccounts: mockedEnterpriseAccounts, } as AuthState, notifications: { - response: [], + response: [{ hostname: 'Dolores', notifications: [{}, {}] }], }, } as AppState; - const mappedProps = mapStateToProps(state); - - expect(mappedProps.isEitherLoggedIn).toBeTruthy(); + it('should accept a provided token', () => { + const mappedProps = mapStateToProps(state); + expect(mappedProps.isEitherLoggedIn).toBeTruthy(); + expect(mappedProps.connectedAccounts).toBe(2); + }); + + it('should count notification lengths', () => { + const mappedProps = mapStateToProps(state); + expect(mappedProps.notificationsCount).toBe(2); + }); + + it('should accept a null token', () => { + const mappedProps = mapStateToProps({ + ...state, + auth: { + ...state.auth, + token: null, + }, + }); + expect(mappedProps.isEitherLoggedIn).toBeTruthy(); + expect(mappedProps.connectedAccounts).toBe(1); + }); }); it('should render itself & its children (logged in)', () => { From f96708249de7be51dd716fc05d549b443dd44295 Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 02:02:56 +0000 Subject: [PATCH 04/14] test clicking back --- src/js/routes/enterprise-login.test.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/js/routes/enterprise-login.test.tsx b/src/js/routes/enterprise-login.test.tsx index 344a94727..af0207624 100644 --- a/src/js/routes/enterprise-login.test.tsx +++ b/src/js/routes/enterprise-login.test.tsx @@ -29,6 +29,7 @@ describe('routes/enterprise-login.js', () => { new BrowserWindow().loadURL.mockReset(); spyOn(ipcRenderer, 'send'); props.dispatch.mockReset(); + props.history.goBack = jest.fn(); }); it('should test the mapStateToProps method', () => { @@ -57,6 +58,19 @@ describe('routes/enterprise-login.js', () => { expect(tree).toMatchSnapshot(); }); + it('let us go back', () => { + props.history.goBack = jest.fn(); + const { getByLabelText } = render( + {})}> + + + + + ); + fireEvent.click(getByLabelText('Go Back')); + expect(props.history.goBack).toHaveBeenCalledTimes(1); + }); + it('should validate the form values', () => { let values; const emptyValues = { From 5d280096ea7a0e7c9fdfad1009fab8e485d4ae0b Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 02:03:09 +0000 Subject: [PATCH 05/14] test restoreSetting method --- src/js/utils/comms.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/js/utils/comms.test.ts b/src/js/utils/comms.test.ts index d9b787a60..91dda11b9 100644 --- a/src/js/utils/comms.test.ts +++ b/src/js/utils/comms.test.ts @@ -3,6 +3,7 @@ import { reOpenWindow, openExternalLink, setAutoLaunch, + restoreSetting, } from './comms'; const { ipcRenderer, remote, shell } = require('electron'); @@ -32,6 +33,12 @@ describe('utils/comms.ts', () => { expect(ipcRenderer.send).toHaveBeenCalledWith('reopen-window'); }); + it('should restore a setting', () => { + restoreSetting('foo', 'bar'); + expect(ipcRenderer.send).toHaveBeenCalledTimes(1); + expect(ipcRenderer.send).toHaveBeenCalledWith('foo', 'bar'); + }); + it('should open an external link', () => { openExternalLink('http://www.gitify.io/'); expect(shell.openExternal).toHaveBeenCalledTimes(1); From 97ef59a351e7861e051eb7b77288697b767644bc Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 02:33:02 +0000 Subject: [PATCH 06/14] add settings test for single account --- src/js/routes/settings.test.tsx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/js/routes/settings.test.tsx b/src/js/routes/settings.test.tsx index 58f0acc4b..79479fdc2 100644 --- a/src/js/routes/settings.test.tsx +++ b/src/js/routes/settings.test.tsx @@ -42,7 +42,7 @@ describe('routes/settings.tsx', () => { props.history.replace.mockReset(); }); - it('should test the mapStateToProps method', () => { + describe('mapStateToProps', () => { const state = { auth: { token: '123-456', @@ -52,11 +52,24 @@ describe('routes/settings.tsx', () => { participating: false, } as SettingsState, } as AppState; + it('should test the method', () => { + const mappedProps = mapStateToProps(state); - const mappedProps = mapStateToProps(state); + expect(mappedProps.hasMultipleAccounts).toBeTruthy(); + expect(mappedProps.settings.participating).toBeFalsy(); + }); + + it('should recognize when only one account logged in', () => { + const mappedProps = mapStateToProps({ + ...state, + auth: { + ...state.auth, + token: null, + }, + }); - expect(mappedProps.hasMultipleAccounts).toBeTruthy(); - expect(mappedProps.settings.participating).toBeFalsy(); + expect(mappedProps.hasMultipleAccounts).toBeFalsy(); + }); }); it('should render itself & its children', () => { From 7b4ccbae38c1357d5218f1b6acab464d9a78a2db Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 02:37:11 +0000 Subject: [PATCH 07/14] correct typo mockedNotificationsRecuderData --- src/js/__mocks__/mockedData.ts | 2 +- src/js/middleware/notifications.test.ts | 6 +++--- src/js/routes/notifications.test.tsx | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/js/__mocks__/mockedData.ts b/src/js/__mocks__/mockedData.ts index 79cbfc4d0..8a4391ab4 100644 --- a/src/js/__mocks__/mockedData.ts +++ b/src/js/__mocks__/mockedData.ts @@ -251,7 +251,7 @@ export const mockedEnterpriseNotifications = [ } as Notification, ]; -export const mockedNotificationsRecuderData = [ +export const mockedNotificationsReducerData = [ { hostname: 'github.com', notifications: mockedGithubNotifications, diff --git a/src/js/middleware/notifications.test.ts b/src/js/middleware/notifications.test.ts index 5ba1e3a4a..aa08685aa 100644 --- a/src/js/middleware/notifications.test.ts +++ b/src/js/middleware/notifications.test.ts @@ -2,14 +2,14 @@ import * as actions from '../actions'; import * as comms from '../utils/comms'; import { mockedGithubNotifications, - mockedNotificationsRecuderData, + mockedNotificationsReducerData, } from '../__mocks__/mockedData'; import notificationsMiddleware from './notifications'; import NativeNotifications from '../utils/notifications'; // Keep 3 notifications // Ps. To receive 4 on actions.NOTIFICATIONS.SUCCESS, -const mockedNotifications = mockedNotificationsRecuderData.map( +const mockedNotifications = mockedNotificationsReducerData.map( (account, accountIndex) => { if (accountIndex === 0) { return { @@ -54,7 +54,7 @@ describe('middleware/notifications.js', () => { it('should raise notifications (native & sound, update tray icon, set badge)', () => { const action = { type: actions.NOTIFICATIONS.SUCCESS, - payload: mockedNotificationsRecuderData, + payload: mockedNotificationsReducerData, }; expect(dispatchWithStoreOf({}, action)).toEqual(action); diff --git a/src/js/routes/notifications.test.tsx b/src/js/routes/notifications.test.tsx index 4f580b6f1..2f5464990 100644 --- a/src/js/routes/notifications.test.tsx +++ b/src/js/routes/notifications.test.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import * as TestRenderer from 'react-test-renderer'; import { AppState, NotificationsState } from '../../types/reducers'; -import { mockedNotificationsRecuderData } from '../__mocks__/mockedData'; +import { mockedNotificationsReducerData } from '../__mocks__/mockedData'; import { NotificationsRoute, mapStateToProps } from './notifications'; jest.mock('../components/account-notifications', () => ({ @@ -20,7 +20,7 @@ jest.mock('../components/oops', () => ({ describe('routes/notifications.ts', () => { const props = { failed: false, - accountNotifications: mockedNotificationsRecuderData, + accountNotifications: mockedNotificationsReducerData, notificationsCount: 4, hasMultipleAccounts: true, hasNotifications: true, @@ -29,7 +29,7 @@ describe('routes/notifications.ts', () => { it('should test the mapStateToProps method', () => { const state = { notifications: { - response: mockedNotificationsRecuderData, + response: mockedNotificationsReducerData, failed: false, } as NotificationsState, } as AppState; @@ -38,7 +38,7 @@ describe('routes/notifications.ts', () => { expect(mappedProps.failed).toBeFalsy(); expect(mappedProps.accountNotifications).toEqual( - mockedNotificationsRecuderData + mockedNotificationsReducerData ); expect(mappedProps.hasNotifications).toBeTruthy(); expect(mappedProps.notificationsCount).toBe(4); From 5ebbba37c9c7c9b1bf59c232e45b8a398caebae0 Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 02:57:26 +0000 Subject: [PATCH 08/14] test no new notifications --- src/js/middleware/notifications.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/js/middleware/notifications.test.ts b/src/js/middleware/notifications.test.ts index aa08685aa..9da1601e7 100644 --- a/src/js/middleware/notifications.test.ts +++ b/src/js/middleware/notifications.test.ts @@ -93,4 +93,17 @@ describe('middleware/notifications.js', () => { expect(comms.updateTrayIcon).toHaveBeenCalledTimes(1); expect(comms.updateTrayIcon).toHaveBeenCalledWith(2); }); + + it('should handle no notifications without error', () => { + const action = { + type: actions.NOTIFICATIONS.SUCCESS, + payload: mockedNotificationsReducerData.map((host) => ({ + ...host, + notifications: [], + })), + }; + expect(dispatchWithStoreOf({}, action)).toEqual(action); + expect(comms.updateTrayIcon).toHaveBeenCalledTimes(1); + expect(comms.updateTrayIcon).toHaveBeenCalledWith(0); + }); }); From 68f58a731d0e9f3a4ed14d841d765b6b17fc0069 Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 03:52:44 +0000 Subject: [PATCH 09/14] test for no new notifications --- src/js/middleware/notifications.test.ts | 51 +++++++++++++++---------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/js/middleware/notifications.test.ts b/src/js/middleware/notifications.test.ts index 9da1601e7..db7321997 100644 --- a/src/js/middleware/notifications.test.ts +++ b/src/js/middleware/notifications.test.ts @@ -22,25 +22,27 @@ const mockedNotifications = mockedNotificationsReducerData.map( } ); -const createFakeStore = () => ({ +const DEFAULT_STORE = { + notifications: { + response: mockedNotifications, + }, + settings: { + playSound: false, + showNotifications: false, + }, +}; + +const createFakeStore = (storeData) => ({ getState() { - return { - notifications: { - response: mockedNotifications, - }, - settings: { - playSound: false, - showNotifications: false, - }, - }; + return storeData; }, }); -const dispatchWithStoreOf = (_, action) => { +const dispatchWithStoreOf = (storeData, action) => { let dispatched = null; - const dispatch = notificationsMiddleware(createFakeStore())( - (actionAttempt) => (dispatched = actionAttempt) - ); + const dispatch = notificationsMiddleware( + createFakeStore({ ...DEFAULT_STORE, ...storeData }) + )((actionAttempt) => (dispatched = actionAttempt)); dispatch(action); return dispatched; }; @@ -94,15 +96,24 @@ describe('middleware/notifications.js', () => { expect(comms.updateTrayIcon).toHaveBeenCalledWith(2); }); - it('should handle no notifications without error', () => { + it('should update tray icon with no notifications', () => { + const noNewNotifications = mockedNotificationsReducerData.map((host) => ({ + ...host, + notifications: [], + })); const action = { type: actions.NOTIFICATIONS.SUCCESS, - payload: mockedNotificationsReducerData.map((host) => ({ - ...host, - notifications: [], - })), + payload: noNewNotifications, }; - expect(dispatchWithStoreOf({}, action)).toEqual(action); + dispatchWithStoreOf( + { + ...DEFAULT_STORE, + notifications: { + response: noNewNotifications, + }, + }, + action + ); expect(comms.updateTrayIcon).toHaveBeenCalledTimes(1); expect(comms.updateTrayIcon).toHaveBeenCalledWith(0); }); From e4abf089d35e71b9733306c528091f90df5cc686 Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 03:55:55 +0000 Subject: [PATCH 10/14] test for empty response list --- src/js/middleware/notifications.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/js/middleware/notifications.test.ts b/src/js/middleware/notifications.test.ts index db7321997..751eb6884 100644 --- a/src/js/middleware/notifications.test.ts +++ b/src/js/middleware/notifications.test.ts @@ -117,4 +117,22 @@ describe('middleware/notifications.js', () => { expect(comms.updateTrayIcon).toHaveBeenCalledTimes(1); expect(comms.updateTrayIcon).toHaveBeenCalledWith(0); }); + + it('should show 0 notifications if no accounts logged in', () => { + const action = { + type: actions.NOTIFICATIONS.SUCCESS, + payload: mockedNotificationsReducerData, + }; + dispatchWithStoreOf( + { + ...DEFAULT_STORE, + notifications: { + response: [], + }, + }, + action + ); + expect(comms.updateTrayIcon).toHaveBeenCalledTimes(1); + expect(comms.updateTrayIcon).toHaveBeenCalledWith(4); + }); }); From 4f9be515dce7ce955431420b052831ccd00a654c Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 22:43:16 +0000 Subject: [PATCH 11/14] remove dead debug code --- package.json | 1 - src/js/store/configureStore.ts | 10 ---------- yarn.lock | 12 ------------ 3 files changed, 23 deletions(-) diff --git a/package.json b/package.json index 200dc4d22..b1a5c7e89 100644 --- a/package.json +++ b/package.json @@ -147,7 +147,6 @@ "nock": "^12.0.3", "prettier": "=2.0.2", "react-test-renderer": "=16.13.1", - "redux-logger": "=3.0.6", "redux-mock-store": "=1.5.4", "ts-jest": "^25.3.1", "webpack": "^4.42.1", diff --git a/src/js/store/configureStore.ts b/src/js/store/configureStore.ts index 434c0120e..ef570075a 100644 --- a/src/js/store/configureStore.ts +++ b/src/js/store/configureStore.ts @@ -12,8 +12,6 @@ import notificationsMiddlware from '../middleware/notifications'; import rootReducer from '../reducers'; import settingsMiddleware from '../middleware/settings'; -const isDev = false; - export default function configureStore() { const engine = filter(createEngine(constants.STORAGE_KEY), [ 'settings', @@ -34,14 +32,6 @@ export default function configureStore() { storageMiddleware, ]; - /* istanbul ignore next */ - if (isDev) { - const { createLogger } = require('redux-logger'); - const logger = createLogger({ collapsed: true }); - middlewares.push(logger); - console.log('adss'); - } - let store = createStore( rootReducer, undefined, diff --git a/yarn.lock b/yarn.lock index df9ada47a..8164f290c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1930,11 +1930,6 @@ decompress-response@^3.3.0: dependencies: mimic-response "^1.0.0" -deep-diff@^0.3.5: - version "0.3.8" - resolved "https://registry.yarnpkg.com/deep-diff/-/deep-diff-0.3.8.tgz#c01de63efb0eec9798801d40c7e0dae25b582c84" - integrity sha1-wB3mPvsO7JeYgB1Ax+Da4ltYLIQ= - deep-extend@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" @@ -5034,13 +5029,6 @@ redux-actions@^0.10.1: dependencies: reduce-reducers "^0.1.0" -redux-logger@=3.0.6: - version "3.0.6" - resolved "https://registry.yarnpkg.com/redux-logger/-/redux-logger-3.0.6.tgz#f7555966f3098f3c88604c449cf0baf5778274bf" - integrity sha1-91VZZvMJjzyIYExEnPC69XeCdL8= - dependencies: - deep-diff "^0.3.5" - redux-mock-store@=1.5.4: version "1.5.4" resolved "https://registry.yarnpkg.com/redux-mock-store/-/redux-mock-store-1.5.4.tgz#90d02495fd918ddbaa96b83aef626287c9ab5872" From c7caa73ced0166e3c65ad15cf760d22d2bcbc667 Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 22:43:54 +0000 Subject: [PATCH 12/14] return proper CI_ACTIVITY --- src/js/utils/github-api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/utils/github-api.ts b/src/js/utils/github-api.ts index 8684d7987..5849d73b0 100644 --- a/src/js/utils/github-api.ts +++ b/src/js/utils/github-api.ts @@ -45,7 +45,7 @@ export function formatReason( case 'team_mention': return { type: 'Team Mention', description: DESCRIPTIONS['TEAM_MENTION'] }; case 'ci_activity': - return { type: 'Workflow Run', description: DESCRIPTIONS['WORKFLOW_RUN'] }; + return { type: 'Workflow Run', description: DESCRIPTIONS['CI_ACTIVITY'] }; default: return { type: 'Unknown', description: DESCRIPTIONS['UNKNOWN'] }; } From 2e9448a81c3daef31bde90109e0f661932e7fda0 Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 22:48:26 +0000 Subject: [PATCH 13/14] snapshot updated --- src/js/utils/__snapshots__/github-api.test.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/utils/__snapshots__/github-api.test.ts.snap b/src/js/utils/__snapshots__/github-api.test.ts.snap index deb0d7a85..f2ea912cd 100644 --- a/src/js/utils/__snapshots__/github-api.test.ts.snap +++ b/src/js/utils/__snapshots__/github-api.test.ts.snap @@ -79,7 +79,7 @@ Object { exports[`./utils/github-api.ts should format the notification reason 12`] = ` Object { - "description": undefined, + "description": "A GitHub Actions workflow run was triggered for your repository", "type": "Workflow Run", } `; From 22149b9ac753b8acbffa939d053f8a9e8ef068ab Mon Sep 17 00:00:00 2001 From: Philihp Busby Date: Sat, 2 May 2020 22:49:29 +0000 Subject: [PATCH 14/14] unnecessary mock of redux-logger --- src/js/__mocks__/redux-logger.js | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/js/__mocks__/redux-logger.js diff --git a/src/js/__mocks__/redux-logger.js b/src/js/__mocks__/redux-logger.js deleted file mode 100644 index 19f22a579..000000000 --- a/src/js/__mocks__/redux-logger.js +++ /dev/null @@ -1,5 +0,0 @@ -export function createLogger() { - return () => (next) => (action) => { - return next(action); - }; -}