diff --git a/src/__mocks__/mock-state.ts b/src/__mocks__/mock-state.ts index 59b9fcbcb..bb71f3574 100644 --- a/src/__mocks__/mock-state.ts +++ b/src/__mocks__/mock-state.ts @@ -17,4 +17,5 @@ export const mockSettings: SettingsState = { theme: Theme.SYSTEM, colors: false, markAsDoneOnOpen: false, + showAccountHostname: false, }; diff --git a/src/context/App.test.tsx b/src/context/App.test.tsx index 24ca1f099..76ff5c25c 100644 --- a/src/context/App.test.tsx +++ b/src/context/App.test.tsx @@ -300,6 +300,7 @@ describe('context/App.tsx', () => { theme: 'SYSTEM', colors: null, markAsDoneOnOpen: false, + showAccountHostname: false, }, ); }); @@ -340,6 +341,7 @@ describe('context/App.tsx', () => { theme: 'SYSTEM', colors: null, markAsDoneOnOpen: false, + showAccountHostname: false, }, ); }); diff --git a/src/context/App.tsx b/src/context/App.tsx index b600889db..9b785fb08 100644 --- a/src/context/App.tsx +++ b/src/context/App.tsx @@ -41,6 +41,7 @@ export const defaultSettings: SettingsState = { theme: Theme.SYSTEM, colors: null, markAsDoneOnOpen: false, + showAccountHostname: false, }; interface AppContextState { diff --git a/src/routes/Notifications.test.tsx b/src/routes/Notifications.test.tsx index 9f7f8ee65..2ad5db7e1 100644 --- a/src/routes/Notifications.test.tsx +++ b/src/routes/Notifications.test.tsx @@ -4,6 +4,7 @@ import TestRenderer from 'react-test-renderer'; import { AppContext } from '../context/App'; import { mockedAccountNotifications } from '../__mocks__/mockedData'; import { NotificationsRoute } from './Notifications'; +import { mockSettings } from '../__mocks__/mock-state'; jest.mock('../components/AccountNotifications', () => ({ AccountNotifications: 'AccountNotifications', @@ -39,6 +40,20 @@ describe('routes/Notifications.tsx', () => { expect(tree).toMatchSnapshot(); }); + it('should render itself & its children (show account hostname)', () => { + const tree = TestRenderer.create( + + + , + ); + expect(tree).toMatchSnapshot(); + }); + it('should render itself & its children (error page - oops)', () => { const tree = TestRenderer.create( diff --git a/src/routes/Notifications.tsx b/src/routes/Notifications.tsx index 478f549a4..75b794ca4 100644 --- a/src/routes/Notifications.tsx +++ b/src/routes/Notifications.tsx @@ -7,7 +7,7 @@ import { Oops } from '../components/Oops'; import { getNotificationCount } from '../utils/notifications'; export const NotificationsRoute: React.FC = (props) => { - const { notifications, requestFailed } = useContext(AppContext); + const { notifications, requestFailed, settings } = useContext(AppContext); const hasMultipleAccounts = useMemo( () => notifications.length > 1, @@ -37,7 +37,9 @@ export const NotificationsRoute: React.FC = (props) => { key={account.hostname} hostname={account.hostname} notifications={account.notifications} - showAccountHostname={hasMultipleAccounts} + showAccountHostname={ + hasMultipleAccounts || settings.showAccountHostname + } /> ))} diff --git a/src/routes/Settings.test.tsx b/src/routes/Settings.test.tsx index e8b608b9e..35703d262 100644 --- a/src/routes/Settings.test.tsx +++ b/src/routes/Settings.test.tsx @@ -156,6 +156,34 @@ describe('routes/Settings.tsx', () => { expect(updateSetting).toHaveBeenCalledWith('showBots', false); }); + it('should toggle the showAccountHostname checkbox', async () => { + let getByLabelText; + + await act(async () => { + const { getByLabelText: getByLabelTextLocal } = render( + + + + + , + ); + getByLabelText = getByLabelTextLocal; + }); + + fireEvent.click(getByLabelText('Show account hostname'), { + target: { checked: true }, + }); + + expect(updateSetting).toHaveBeenCalledTimes(1); + expect(updateSetting).toHaveBeenCalledWith('showAccountHostname', false); + }); + it('should toggle the showNotificationsCountInTray checkbox', async () => { let getByLabelText; diff --git a/src/routes/Settings.tsx b/src/routes/Settings.tsx index 3017d2941..6bbf66560 100644 --- a/src/routes/Settings.tsx +++ b/src/routes/Settings.tsx @@ -139,6 +139,14 @@ export const SettingsRoute: React.FC = () => { } disabled={!colorScope} /> + + updateSetting('showAccountHostname', evt.target.checked) + } + />
diff --git a/src/routes/__snapshots__/Notifications.test.tsx.snap b/src/routes/__snapshots__/Notifications.test.tsx.snap index 7ca8cdc41..8c42ddd1c 100644 --- a/src/routes/__snapshots__/Notifications.test.tsx.snap +++ b/src/routes/__snapshots__/Notifications.test.tsx.snap @@ -4,6 +4,148 @@ exports[`routes/Notifications.tsx should render itself & its children (all read exports[`routes/Notifications.tsx should render itself & its children (error page - oops) 1`] = ``; +exports[`routes/Notifications.tsx should render itself & its children (show account hostname) 1`] = ` +
+ +
+`; + exports[`routes/Notifications.tsx should render itself & its children (with notifications) 1`] = `
+
+
+ +
+
+ +
+