diff --git a/src/renderer/__mocks__/partial-mocks.ts b/src/renderer/__mocks__/partial-mocks.ts index 5db97d316..04ff306bc 100644 --- a/src/renderer/__mocks__/partial-mocks.ts +++ b/src/renderer/__mocks__/partial-mocks.ts @@ -13,6 +13,7 @@ export function partialMockNotification( hostname: Constants.GITHUB_API_BASE_URL as Hostname, token: mockToken, user: mockGitifyUser, + hasRequiredScopes: true, }, subject: subject as Subject, }; diff --git a/src/renderer/__mocks__/state-mocks.ts b/src/renderer/__mocks__/state-mocks.ts index 4b3eb4232..c88b8f460 100644 --- a/src/renderer/__mocks__/state-mocks.ts +++ b/src/renderer/__mocks__/state-mocks.ts @@ -34,6 +34,7 @@ export const mockPersonalAccessTokenAccount: Account = { token: 'token-123-456' as Token, hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname, user: mockGitifyUser, + hasRequiredScopes: true, }; export const mockOAuthAccount: Account = { @@ -42,6 +43,7 @@ export const mockOAuthAccount: Account = { token: '1234568790' as Token, hostname: 'github.gitify.io' as Hostname, user: mockGitifyUser, + hasRequiredScopes: true, }; export const mockGitHubCloudAccount: Account = { @@ -51,6 +53,7 @@ export const mockGitHubCloudAccount: Account = { hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname, user: mockGitifyUser, version: 'latest', + hasRequiredScopes: true, }; export const mockGitHubEnterpriseServerAccount: Account = { @@ -59,6 +62,7 @@ export const mockGitHubEnterpriseServerAccount: Account = { token: '1234568790' as Token, hostname: 'github.gitify.io' as Hostname, user: mockGitifyUser, + hasRequiredScopes: true, }; export const mockGitHubAppAccount: Account = { @@ -67,6 +71,7 @@ export const mockGitHubAppAccount: Account = { token: '987654321' as Token, hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname, user: mockGitifyUser, + hasRequiredScopes: true, }; export const mockAuth: AuthState = { diff --git a/src/renderer/routes/Accounts.test.tsx b/src/renderer/routes/Accounts.test.tsx index e2b23052f..e06fd5486 100644 --- a/src/renderer/routes/Accounts.test.tsx +++ b/src/renderer/routes/Accounts.test.tsx @@ -57,6 +57,45 @@ describe('renderer/routes/Accounts.tsx', () => { expect(screen.getByTestId('accounts')).toMatchSnapshot(); }); + it('should render with PAT scopes warning', async () => { + const openExternalLinkMock = jest + .spyOn(comms, 'openExternalLink') + .mockImplementation(); + + await act(async () => { + render( + + + + + , + ); + }); + + expect(screen.getByTestId('accounts')).toMatchSnapshot(); + + fireEvent.click(screen.getByLabelText('missing-scopes')); + + expect(openExternalLinkMock).toHaveBeenCalledTimes(1); + expect(openExternalLinkMock).toHaveBeenCalledWith( + 'https://github.com/settings/tokens', + ); + }); + it('should go back by pressing the icon', async () => { await act(async () => { render( diff --git a/src/renderer/routes/Accounts.tsx b/src/renderer/routes/Accounts.tsx index 8682860cf..2238401e4 100644 --- a/src/renderer/routes/Accounts.tsx +++ b/src/renderer/routes/Accounts.tsx @@ -1,4 +1,5 @@ import { + AlertFillIcon, FeedPersonIcon, KeyIcon, MarkGithubIcon, @@ -23,6 +24,7 @@ import { type Account, IconColor, Size } from '../types'; import { getAccountUUID, refreshAccount } from '../utils/auth/utils'; import { cn } from '../utils/cn'; import { updateTrayIcon, updateTrayTitle } from '../utils/comms'; +import { Constants } from '../utils/constants'; import { openAccountProfile, openDeveloperSettings, @@ -78,7 +80,7 @@ export const AccountsRoute: FC = () => { className="mb-4 flex items-center justify-between rounded-md bg-gray-100 p-2 dark:bg-gray-sidebar" >
-
+
+ + {account.hasRequiredScopes === false && ( + + + + )}
+
+
+ +
+ +
+
+
+ + + + +
+
+ + +
+
+ Add new account +
+
+ + + +
+
+ +`; + +exports[`renderer/routes/Accounts.tsx General should render with PAT scopes warning 1`] = ` +
+
+ +

+ + + Accounts + +

+
+
+
+
+
+
+ + + + +
+
+ +
+
+ +
+
+
+ + + + +
+
+
+
+
+ +
+
+ +
+
+ +
+
+
+ + + + +
+
+
+
+