Skip to content

Commit 4ba9afd

Browse files
authored
feat(settings): show account hostname (#966)
* feat(settings): show account hostname
1 parent c1ebda3 commit 4ba9afd

File tree

10 files changed

+225
-2
lines changed

10 files changed

+225
-2
lines changed

src/__mocks__/mock-state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ export const mockSettings: SettingsState = {
1717
theme: Theme.SYSTEM,
1818
colors: false,
1919
markAsDoneOnOpen: false,
20+
showAccountHostname: false,
2021
};

src/context/App.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ describe('context/App.tsx', () => {
300300
theme: 'SYSTEM',
301301
colors: null,
302302
markAsDoneOnOpen: false,
303+
showAccountHostname: false,
303304
},
304305
);
305306
});
@@ -340,6 +341,7 @@ describe('context/App.tsx', () => {
340341
theme: 'SYSTEM',
341342
colors: null,
342343
markAsDoneOnOpen: false,
344+
showAccountHostname: false,
343345
},
344346
);
345347
});

src/context/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const defaultSettings: SettingsState = {
4141
theme: Theme.SYSTEM,
4242
colors: null,
4343
markAsDoneOnOpen: false,
44+
showAccountHostname: false,
4445
};
4546

4647
interface AppContextState {

src/routes/Notifications.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import TestRenderer from 'react-test-renderer';
44
import { AppContext } from '../context/App';
55
import { mockedAccountNotifications } from '../__mocks__/mockedData';
66
import { NotificationsRoute } from './Notifications';
7+
import { mockSettings } from '../__mocks__/mock-state';
78

89
jest.mock('../components/AccountNotifications', () => ({
910
AccountNotifications: 'AccountNotifications',
@@ -39,6 +40,20 @@ describe('routes/Notifications.tsx', () => {
3940
expect(tree).toMatchSnapshot();
4041
});
4142

43+
it('should render itself & its children (show account hostname)', () => {
44+
const tree = TestRenderer.create(
45+
<AppContext.Provider
46+
value={{
47+
notifications: [mockedAccountNotifications[0]],
48+
settings: { ...mockSettings, showAccountHostname: true },
49+
}}
50+
>
51+
<NotificationsRoute />
52+
</AppContext.Provider>,
53+
);
54+
expect(tree).toMatchSnapshot();
55+
});
56+
4257
it('should render itself & its children (error page - oops)', () => {
4358
const tree = TestRenderer.create(
4459
<AppContext.Provider value={{ notifications: [], requestFailed: true }}>

src/routes/Notifications.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Oops } from '../components/Oops';
77
import { getNotificationCount } from '../utils/notifications';
88

99
export const NotificationsRoute: React.FC = (props) => {
10-
const { notifications, requestFailed } = useContext(AppContext);
10+
const { notifications, requestFailed, settings } = useContext(AppContext);
1111

1212
const hasMultipleAccounts = useMemo(
1313
() => notifications.length > 1,
@@ -37,7 +37,9 @@ export const NotificationsRoute: React.FC = (props) => {
3737
key={account.hostname}
3838
hostname={account.hostname}
3939
notifications={account.notifications}
40-
showAccountHostname={hasMultipleAccounts}
40+
showAccountHostname={
41+
hasMultipleAccounts || settings.showAccountHostname
42+
}
4143
/>
4244
))}
4345
</div>

src/routes/Settings.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,34 @@ describe('routes/Settings.tsx', () => {
156156
expect(updateSetting).toHaveBeenCalledWith('showBots', false);
157157
});
158158

159+
it('should toggle the showAccountHostname checkbox', async () => {
160+
let getByLabelText;
161+
162+
await act(async () => {
163+
const { getByLabelText: getByLabelTextLocal } = render(
164+
<AppContext.Provider
165+
value={{
166+
settings: mockSettings,
167+
accounts: mockAccounts,
168+
updateSetting,
169+
}}
170+
>
171+
<MemoryRouter>
172+
<SettingsRoute />
173+
</MemoryRouter>
174+
</AppContext.Provider>,
175+
);
176+
getByLabelText = getByLabelTextLocal;
177+
});
178+
179+
fireEvent.click(getByLabelText('Show account hostname'), {
180+
target: { checked: true },
181+
});
182+
183+
expect(updateSetting).toHaveBeenCalledTimes(1);
184+
expect(updateSetting).toHaveBeenCalledWith('showAccountHostname', false);
185+
});
186+
159187
it('should toggle the showNotificationsCountInTray checkbox', async () => {
160188
let getByLabelText;
161189

src/routes/Settings.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ export const SettingsRoute: React.FC = () => {
139139
}
140140
disabled={!colorScope}
141141
/>
142+
<FieldCheckbox
143+
name="showAccountHostname"
144+
label="Show account hostname"
145+
checked={settings.showAccountHostname}
146+
onChange={(evt) =>
147+
updateSetting('showAccountHostname', evt.target.checked)
148+
}
149+
/>
142150
</fieldset>
143151

144152
<fieldset className="mb-3">

src/routes/__snapshots__/Notifications.test.tsx.snap

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,148 @@ exports[`routes/Notifications.tsx should render itself & its children (all read
44

55
exports[`routes/Notifications.tsx should render itself & its children (error page - oops) 1`] = `<Oops />`;
66

7+
exports[`routes/Notifications.tsx should render itself & its children (show account hostname) 1`] = `
8+
<div
9+
className="flex flex-col flex-1 bg-white dark:bg-gray-dark"
10+
>
11+
<AccountNotifications
12+
hostname="github.com"
13+
notifications={
14+
[
15+
{
16+
"hostname": "github.com",
17+
"id": "138661096",
18+
"last_read_at": "2017-05-20T17:06:51Z",
19+
"reason": "subscribed",
20+
"repository": {
21+
"archive_url": "https://api.github.com/repos/manosim/notifications-test/{archive_format}{/ref}",
22+
"assignees_url": "https://api.github.com/repos/manosim/notifications-test/assignees{/user}",
23+
"blobs_url": "https://api.github.com/repos/manosim/notifications-test/git/blobs{/sha}",
24+
"branches_url": "https://api.github.com/repos/manosim/notifications-test/branches{/branch}",
25+
"collaborators_url": "https://api.github.com/repos/manosim/notifications-test/collaborators{/collaborator}",
26+
"comments_url": "https://api.github.com/repos/manosim/notifications-test/comments{/number}",
27+
"commits_url": "https://api.github.com/repos/manosim/notifications-test/commits{/sha}",
28+
"compare_url": "https://api.github.com/repos/manosim/notifications-test/compare/{base}...{head}",
29+
"contents_url": "https://api.github.com/repos/manosim/notifications-test/contents/{+path}",
30+
"contributors_url": "https://api.github.com/repos/manosim/notifications-test/contributors",
31+
"deployments_url": "https://api.github.com/repos/manosim/notifications-test/deployments",
32+
"description": "Test Repository",
33+
"downloads_url": "https://api.github.com/repos/manosim/notifications-test/downloads",
34+
"events_url": "https://api.github.com/repos/manosim/notifications-test/events",
35+
"fork": false,
36+
"forks_url": "https://api.github.com/repos/manosim/notifications-test/forks",
37+
"full_name": "manosim/notifications-test",
38+
"git_commits_url": "https://api.github.com/repos/manosim/notifications-test/git/commits{/sha}",
39+
"git_refs_url": "https://api.github.com/repos/manosim/notifications-test/git/refs{/sha}",
40+
"git_tags_url": "https://api.github.com/repos/manosim/notifications-test/git/tags{/sha}",
41+
"hooks_url": "https://api.github.com/repos/manosim/notifications-test/hooks",
42+
"html_url": "https://github.com/manosim/notifications-test",
43+
"id": 57216596,
44+
"issue_comment_url": "https://api.github.com/repos/manosim/notifications-test/issues/comments{/number}",
45+
"issue_events_url": "https://api.github.com/repos/manosim/notifications-test/issues/events{/number}",
46+
"issues_url": "https://api.github.com/repos/manosim/notifications-test/issues{/number}",
47+
"keys_url": "https://api.github.com/repos/manosim/notifications-test/keys{/key_id}",
48+
"labels_url": "https://api.github.com/repos/manosim/notifications-test/labels{/name}",
49+
"languages_url": "https://api.github.com/repos/manosim/notifications-test/languages",
50+
"merges_url": "https://api.github.com/repos/manosim/notifications-test/merges",
51+
"milestones_url": "https://api.github.com/repos/manosim/notifications-test/milestones{/number}",
52+
"name": "notifications-test",
53+
"node_id": "MDEwOlJlcG9zaXRvcnkzNjAyOTcwNg==",
54+
"notifications_url": "https://api.github.com/repos/manosim/notifications-test/notifications{?since,all,participating}",
55+
"owner": {
56+
"avatar_url": "https://avatars0.githubusercontent.com/u/6333409?v=3",
57+
"events_url": "https://api.github.com/users/manosim/events{/privacy}",
58+
"followers_url": "https://api.github.com/users/manosim/followers",
59+
"following_url": "https://api.github.com/users/manosim/following{/other_user}",
60+
"gists_url": "https://api.github.com/users/manosim/gists{/gist_id}",
61+
"gravatar_id": "",
62+
"html_url": "https://github.com/manosim",
63+
"id": 6333409,
64+
"login": "manosim",
65+
"node_id": "MDQ6VXNlcjYzMzM0MDk=",
66+
"organizations_url": "https://api.github.com/users/manosim/orgs",
67+
"received_events_url": "https://api.github.com/users/manosim/received_events",
68+
"repos_url": "https://api.github.com/users/manosim/repos",
69+
"site_admin": false,
70+
"starred_url": "https://api.github.com/users/manosim/starred{/owner}{/repo}",
71+
"subscriptions_url": "https://api.github.com/users/manosim/subscriptions",
72+
"type": "User",
73+
"url": "https://api.github.com/users/manosim",
74+
},
75+
"private": true,
76+
"pulls_url": "https://api.github.com/repos/manosim/notifications-test/pulls{/number}",
77+
"releases_url": "https://api.github.com/repos/manosim/notifications-test/releases{/id}",
78+
"stargazers_url": "https://api.github.com/repos/manosim/notifications-test/stargazers",
79+
"statuses_url": "https://api.github.com/repos/manosim/notifications-test/statuses/{sha}",
80+
"subscribers_url": "https://api.github.com/repos/manosim/notifications-test/subscribers",
81+
"subscription_url": "https://api.github.com/repos/manosim/notifications-test/subscription",
82+
"tags_url": "https://api.github.com/repos/manosim/notifications-test/tags",
83+
"teams_url": "https://api.github.com/repos/manosim/notifications-test/teams",
84+
"trees_url": "https://api.github.com/repos/manosim/notifications-test/git/trees{/sha}",
85+
"url": "https://api.github.com/manosim/notifications-test",
86+
},
87+
"subject": {
88+
"latest_comment_url": "https://api.github.com/repos/manosim/notifications-test/issues/comments/302888448",
89+
"state": "open",
90+
"title": "I am a robot and this is a test!",
91+
"type": "Issue",
92+
"url": "https://api.github.com/repos/manosim/notifications-test/issues/1",
93+
},
94+
"subscription_url": "https://api.github.com/notifications/threads/138661096/subscription",
95+
"unread": true,
96+
"updated_at": "2017-05-20T17:51:57Z",
97+
"url": "https://api.github.com/notifications/threads/138661096",
98+
},
99+
{
100+
"id": "148827438",
101+
"last_read_at": "2017-05-20T16:59:03Z",
102+
"reason": "author",
103+
"repository": {
104+
"description": null,
105+
"fork": false,
106+
"full_name": "manosim/notifications-test",
107+
"html_url": "https://github.com/manosim/notifications-test",
108+
"id": 57216596,
109+
"name": "notifications-test",
110+
"owner": {
111+
"avatar_url": "https://avatars0.githubusercontent.com/u/6333409?v=3",
112+
"events_url": "https://api.github.com/users/manosim/events{/privacy}",
113+
"followers_url": "https://api.github.com/users/manosim/followers",
114+
"following_url": "https://api.github.com/users/manosim/following{/other_user}",
115+
"gists_url": "https://api.github.com/users/manosim/gists{/gist_id}",
116+
"gravatar_id": "",
117+
"html_url": "https://github.com/manosim",
118+
"id": 6333409,
119+
"login": "manosim",
120+
"organizations_url": "https://api.github.com/users/manosim/orgs",
121+
"received_events_url": "https://api.github.com/users/manosim/received_events",
122+
"repos_url": "https://api.github.com/users/manosim/repos",
123+
"site_admin": false,
124+
"starred_url": "https://api.github.com/users/manosim/starred{/owner}{/repo}",
125+
"subscriptions_url": "https://api.github.com/users/manosim/subscriptions",
126+
"type": "User",
127+
"url": "https://api.github.com/users/manosim",
128+
},
129+
"private": true,
130+
},
131+
"subject": {
132+
"latest_comment_url": "https://api.github.com/repos/manosim/notifications-test/issues/comments/302885965",
133+
"title": "Improve the UI",
134+
"type": "Issue",
135+
"url": "https://api.github.com/repos/manosim/notifications-test/issues/4",
136+
},
137+
"subscription_url": "https://api.github.com/notifications/threads/148827438/subscription",
138+
"unread": true,
139+
"updated_at": "2017-05-20T17:06:34Z",
140+
"url": "https://api.github.com/notifications/threads/148827438",
141+
},
142+
]
143+
}
144+
showAccountHostname={true}
145+
/>
146+
</div>
147+
`;
148+
7149
exports[`routes/Notifications.tsx should render itself & its children (with notifications) 1`] = `
8150
<div
9151
className="flex flex-col flex-1 bg-white dark:bg-gray-dark"

src/routes/__snapshots__/Settings.test.tsx.snap

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,29 @@ exports[`routes/Settings.tsx should render itself & its children 1`] = `
170170
</label>
171171
</div>
172172
</div>
173+
<div
174+
class="flex items-start mt-1 mb-3"
175+
>
176+
<div
177+
class="flex items-center h-5"
178+
>
179+
<input
180+
class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded"
181+
id="showAccountHostname"
182+
type="checkbox"
183+
/>
184+
</div>
185+
<div
186+
class="ml-3 text-sm"
187+
>
188+
<label
189+
class="font-medium text-gray-700 dark:text-gray-200"
190+
for="showAccountHostname"
191+
>
192+
Show account hostname
193+
</label>
194+
</div>
195+
</div>
173196
</fieldset>
174197
<fieldset
175198
class="mb-3"

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type SettingsState = AppearanceSettingsState &
1313
interface AppearanceSettingsState {
1414
theme: Theme;
1515
colors: boolean | null;
16+
showAccountHostname: boolean;
1617
}
1718

1819
interface NotificationSettingsState {

0 commit comments

Comments
 (0)