Skip to content

Commit 161f56c

Browse files
authored
refactor: add title to unread notifications button (#896)
* refactor: add title to unread notifications button * test: update snapshot * test: fix tests
1 parent d8ff03f commit 161f56c

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

src/components/Sidebar.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,22 @@ describe('components/Sidebar.tsx', () => {
137137

138138
describe('should render the notifications icon', () => {
139139
it('when there are 0 notifications', () => {
140-
const { getByLabelText } = render(
140+
const { getByTitle } = render(
141141
<AppContext.Provider value={{ isLoggedIn: true, notifications: [] }}>
142142
<MemoryRouter>
143143
<Sidebar />
144144
</MemoryRouter>
145145
</AppContext.Provider>,
146146
);
147147

148-
const notificationsIcon = getByLabelText('0 Unread Notifications');
148+
const notificationsIcon = getByTitle('0 Unread Notifications');
149149
expect(notificationsIcon.className).toContain('text-white');
150150
expect(notificationsIcon.childNodes.length).toBe(1);
151151
expect(notificationsIcon.childNodes[0].nodeName).toBe('svg');
152152
});
153153

154154
it('when there are more than 0 notifications', () => {
155-
const { getByLabelText } = render(
155+
const { getByTitle } = render(
156156
<AppContext.Provider
157157
value={{
158158
isLoggedIn: true,
@@ -165,7 +165,7 @@ describe('components/Sidebar.tsx', () => {
165165
</AppContext.Provider>,
166166
);
167167

168-
const notificationsIcon = getByLabelText('4 Unread Notifications');
168+
const notificationsIcon = getByTitle('4 Unread Notifications');
169169
expect(notificationsIcon.className).toContain('text-green-500');
170170
expect(notificationsIcon.childNodes.length).toBe(2);
171171
expect(notificationsIcon.childNodes[0].nodeName).toBe('svg');

src/components/Sidebar.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,19 @@ export const Sidebar: React.FC = () => {
5252
<Logo aria-label="Open Gitify" />
5353
</button>
5454

55-
<div
55+
<button
5656
className={`flex justify-around self-stretch items-center my-1 py-1 px-2 text-xs font-extrabold cursor-pointer ${
5757
notificationsCount > 0 ? 'text-green-500' : 'text-white'
5858
}`}
5959
onClick={onOpenGitHubNotifications}
60-
aria-label={`${notificationsCount} Unread Notifications`}
60+
title={`${notificationsCount} Unread Notifications`}
6161
>
62-
<BellIcon size={12} />
62+
<BellIcon
63+
size={12}
64+
aria-label={`${notificationsCount} Unread Notifications`}
65+
/>
6366
{notificationsCount > 0 && notificationsCount}
64-
</div>
67+
</button>
6568
</div>
6669

6770
<div className="py-4 px-3">

src/components/__snapshots__/Sidebar.test.tsx.snap

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ exports[`components/Sidebar.tsx should render itself & its children (logged in)
5959
</g>
6060
</svg>
6161
</button>
62-
<div
63-
aria-label="4 Unread Notifications"
62+
<button
6463
className="flex justify-around self-stretch items-center my-1 py-1 px-2 text-xs font-extrabold cursor-pointer text-green-500"
6564
onClick={[Function]}
65+
title="4 Unread Notifications"
6666
>
6767
<svg
68-
aria-hidden="true"
68+
aria-hidden="false"
69+
aria-label="4 Unread Notifications"
6970
className="octicon octicon-bell"
7071
fill="currentColor"
7172
focusable="false"
@@ -87,7 +88,7 @@ exports[`components/Sidebar.tsx should render itself & its children (logged in)
8788
/>
8889
</svg>
8990
4
90-
</div>
91+
</button>
9192
</div>
9293
<div
9394
className="py-4 px-3"
@@ -187,13 +188,14 @@ exports[`components/Sidebar.tsx should render itself & its children (logged out)
187188
</g>
188189
</svg>
189190
</button>
190-
<div
191-
aria-label="4 Unread Notifications"
191+
<button
192192
className="flex justify-around self-stretch items-center my-1 py-1 px-2 text-xs font-extrabold cursor-pointer text-green-500"
193193
onClick={[Function]}
194+
title="4 Unread Notifications"
194195
>
195196
<svg
196-
aria-hidden="true"
197+
aria-hidden="false"
198+
aria-label="4 Unread Notifications"
197199
className="octicon octicon-bell"
198200
fill="currentColor"
199201
focusable="false"
@@ -215,7 +217,7 @@ exports[`components/Sidebar.tsx should render itself & its children (logged out)
215217
/>
216218
</svg>
217219
4
218-
</div>
220+
</button>
219221
</div>
220222
<div
221223
className="py-4 px-3"

0 commit comments

Comments
 (0)