Skip to content

Commit 1f587f1

Browse files
committed
feat(accounts): warn when missing scopes
Signed-off-by: Adam Setch <[email protected]>
1 parent 8ea2773 commit 1f587f1

File tree

3 files changed

+29
-165
lines changed

3 files changed

+29
-165
lines changed

src/renderer/routes/Accounts.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ describe('renderer/routes/Accounts.tsx', () => {
5858
});
5959

6060
it('should render with PAT scopes warning', async () => {
61+
const openExternalLinkMock = jest
62+
.spyOn(comms, 'openExternalLink')
63+
.mockImplementation();
64+
6165
await act(async () => {
6266
render(
6367
<AppContext.Provider
@@ -83,6 +87,13 @@ describe('renderer/routes/Accounts.tsx', () => {
8387
});
8488

8589
expect(screen.getByTestId('accounts')).toMatchSnapshot();
90+
91+
fireEvent.click(screen.getByLabelText('missing-scopes'));
92+
93+
expect(openExternalLinkMock).toHaveBeenCalledTimes(1);
94+
expect(openExternalLinkMock).toHaveBeenCalledWith(
95+
'https://github.com/settings/tokens',
96+
);
8697
});
8798

8899
it('should go back by pressing the icon', async () => {

src/renderer/routes/Accounts.tsx

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,23 @@ export const AccountsRoute: FC = () => {
102102
</span>
103103
</button>
104104

105-
<span
106-
hidden={
107-
account.method === 'Personal Access Token' &&
108-
account.hasRequiredScopes === true
109-
}
110-
className="text-xs font-medium italic"
111-
>
112-
<button
113-
type="button"
114-
className="cursor-pointer"
115-
title={`This account is missing one or more required scopes: \n - ${Constants.AUTH_SCOPE.join('\n - ')}`}
116-
onClick={() => openDeveloperSettings(account)}
117-
>
118-
<AlertFillIcon
119-
size={Size.XSMALL}
120-
className={IconColor.RED}
121-
/>
122-
</button>
123-
</span>
105+
{account.method === 'Personal Access Token' &&
106+
account.hasRequiredScopes === false && (
107+
<span className="text-xs font-medium italic">
108+
<button
109+
type="button"
110+
className="cursor-pointer"
111+
title={`This account is missing one or more required scopes: \n - ${Constants.AUTH_SCOPE.join('\n - ')}`}
112+
aria-label="missing-scopes"
113+
onClick={() => openDeveloperSettings(account)}
114+
>
115+
<AlertFillIcon
116+
size={Size.XSMALL}
117+
className={IconColor.RED}
118+
/>
119+
</button>
120+
</span>
121+
)}
124122
</div>
125123
<div>
126124
<button

src/renderer/routes/__snapshots__/Accounts.test.tsx.snap

Lines changed: 1 addition & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)