Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(login): add help docs to login flows #1121

Merged
merged 5 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/routes/LoginEnterprise.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('routes/LoginEnterprise.tsx', () => {
};

beforeEach(() => {
openExternalMock.mockReset();
mockNavigate.mockReset();

jest.spyOn(ipcRenderer, 'send');
Expand Down Expand Up @@ -160,10 +161,24 @@ describe('routes/LoginEnterprise.tsx', () => {
target: { value: 'abc' },
});

fireEvent.submit(screen.getByTitle('Login Button'));
fireEvent.submit(screen.getByTitle('Login'));

expect(screen.getByText('Invalid hostname.')).toBeTruthy();
expect(screen.getByText('Invalid client id.')).toBeTruthy();
expect(screen.getByText('Invalid client secret.')).toBeTruthy();
});

it('should open help docs in the browser', async () => {
render(
<AppContext.Provider value={{ accounts: mockAccounts }}>
<MemoryRouter>
<LoginEnterpriseRoute />
</MemoryRouter>
</AppContext.Provider>,
);

fireEvent.click(screen.getByLabelText('GitHub Docs'));

expect(openExternalMock).toHaveBeenCalledTimes(1);
});
});
35 changes: 26 additions & 9 deletions src/routes/LoginEnterprise.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ipcRenderer = require('electron').ipcRenderer;

import { ArrowLeftIcon } from '@primer/octicons-react';
import { ArrowLeftIcon, BookIcon, SignInIcon } from '@primer/octicons-react';

import { type FC, useCallback, useContext, useEffect } from 'react';
import { Form, type FormRenderProps } from 'react-final-form';
Expand All @@ -12,6 +12,9 @@ import type { AuthOptions } from '../types';
import { getNewOAuthAppURL } from '../utils/auth';
import { openExternalLink } from '../utils/comms';

const GITHUB_DOCS_URL =
'https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authenticating-to-the-rest-api-with-an-oauth-app';

interface IValues {
hostname?: string;
clientId?: string;
Expand Down Expand Up @@ -109,14 +112,28 @@ export const LoginEnterpriseRoute: FC = () => {
placeholder="ABC123DEF456"
/>

<button
className="float-right px-4 py-2 my-4 bg-gray-300 font-semibold rounded text-sm text-center hover:bg-gray-500 hover:text-white dark:text-black focus:outline-none"
title="Login Button"
disabled={submitting || pristine}
type="submit"
>
Login
</button>
<div className="flex justify-between items-center">
<div className="text-xs italic hover:text-blue-500 justify-center items-center">
<button
type="button"
aria-label="GitHub Docs"
className={`px-2 py-1 text-xs ${buttonClasses}`}
onClick={() => openLink(GITHUB_DOCS_URL)}
>
<BookIcon size={12} /> Docs
</button>
</div>
<div className="justify-center items-center">
<button
className={`float-right px-4 py-2 my-4 ${buttonClasses}`}
title="Login"
disabled={submitting || pristine}
type="submit"
>
<SignInIcon size={14} /> Login
</button>
</div>
</div>
</form>
);
};
Expand Down
20 changes: 17 additions & 3 deletions src/routes/LoginWithToken.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('routes/LoginWithToken.tsx', () => {
target: { value: 'github.com' },
});

fireEvent.submit(screen.getByTitle('Submit Button'));
fireEvent.submit(screen.getByTitle('Login'));

await waitFor(() => expect(mockValidateToken).toHaveBeenCalledTimes(1));

Expand All @@ -150,7 +150,7 @@ describe('routes/LoginWithToken.tsx', () => {
fireEvent.change(screen.getByLabelText('Hostname'), {
target: { value: 'github.com' },
});
fireEvent.submit(screen.getByTitle('Submit Button'));
fireEvent.submit(screen.getByTitle('Login'));
});

await waitFor(() => expect(mockValidateToken).toHaveBeenCalledTimes(1));
Expand All @@ -173,9 +173,23 @@ describe('routes/LoginWithToken.tsx', () => {
target: { value: '123' },
});

fireEvent.submit(screen.getByTitle('Submit Button'));
fireEvent.submit(screen.getByTitle('Login'));

expect(screen.getByText('Invalid hostname.')).toBeDefined();
expect(screen.getByText('Invalid token.')).toBeDefined();
});

it('should open help docs in the browser', async () => {
render(
<AppContext.Provider value={{ validateToken: mockValidateToken }}>
<MemoryRouter>
<LoginWithToken />
</MemoryRouter>
</AppContext.Provider>,
);

fireEvent.click(screen.getByLabelText('GitHub Docs'));

expect(openExternalMock).toHaveBeenCalledTimes(1);
});
});
35 changes: 26 additions & 9 deletions src/routes/LoginWithToken.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArrowLeftIcon } from '@primer/octicons-react';
import { ArrowLeftIcon, BookIcon, SignInIcon } from '@primer/octicons-react';

import { type FC, useCallback, useContext, useState } from 'react';
import { Form, type FormRenderProps } from 'react-final-form';
Expand All @@ -12,6 +12,9 @@ import { Constants } from '../utils/constants';

import { format } from 'date-fns';

const GITHUB_DOCS_URL =
'https://docs.github.com/en/enterprise-server@3.13/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens';

interface IValues {
token?: string;
hostname?: string;
Expand Down Expand Up @@ -104,14 +107,28 @@ export const LoginWithToken: FC = () => {
</div>
)}

<button
className={`float-right px-4 py-2 my-4 ${buttonClasses}`}
title="Submit Button"
disabled={submitting || pristine}
type="submit"
>
Submit
</button>
<div className="flex justify-between items-center">
<div className="text-xs italic hover:text-blue-500 justify-center items-center">
<button
type="button"
aria-label="GitHub Docs"
className={`px-2 py-1 text-xs ${buttonClasses}`}
onClick={() => openLink(GITHUB_DOCS_URL)}
>
<BookIcon size={12} /> Docs
</button>
</div>
<div className="justify-center items-center">
<button
className={`float-right px-4 py-2 my-4 ${buttonClasses}`}
title="Login"
disabled={submitting || pristine}
type="submit"
>
<SignInIcon size={14} /> Login
</button>
</div>
</div>
</form>
);
};
Expand Down
76 changes: 69 additions & 7 deletions src/routes/__snapshots__/LoginEnterprise.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 69 additions & 7 deletions src/routes/__snapshots__/LoginWithToken.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.