Skip to content

Commit

Permalink
feat(auth): add create oauth app link to enterprise route
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed May 17, 2024
1 parent cb6581d commit c1e7fd4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/routes/LoginEnterprise.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import * as TestRenderer from 'react-test-renderer';
const { ipcRenderer } = require('electron');
import { shell } from 'electron';
import { mockedEnterpriseAccounts } from '../__mocks__/mockedData';
import { AppContext } from '../context/App';
import type { AuthState } from '../types';
Expand All @@ -14,6 +15,8 @@ jest.mock('react-router-dom', () => ({
}));

describe('routes/LoginEnterprise.tsx', () => {
const openExternalMock = jest.spyOn(shell, 'openExternal');

const mockAccounts: AuthState = {
enterpriseAccounts: [],
user: null,
Expand Down Expand Up @@ -75,6 +78,40 @@ describe('routes/LoginEnterprise.tsx', () => {
expect(validate(values).clientSecret).toBe('Invalid client secret.');
});

describe("'Create new OAuth App' button", () => {
it('should be disabled if no hostname configured', async () => {
render(
<AppContext.Provider value={{ accounts: mockAccounts }}>
<MemoryRouter>
<LoginEnterpriseRoute />
</MemoryRouter>
</AppContext.Provider>,
);

fireEvent.click(screen.getByText('Create new OAuth App'));

expect(openExternalMock).toHaveBeenCalledTimes(0);
});

it('should open if hostname configured', async () => {
render(
<AppContext.Provider value={{ accounts: mockAccounts }}>
<MemoryRouter>
<LoginEnterpriseRoute />
</MemoryRouter>
</AppContext.Provider>,
);

fireEvent.change(screen.getByLabelText('Hostname'), {
target: { value: 'company.github.com' },
});

fireEvent.click(screen.getByText('Create new OAuth App'));

expect(openExternalMock).toHaveBeenCalledTimes(1);
});
});

it('should receive a logged-in enterprise account', () => {
const { rerender } = render(
<AppContext.Provider value={{ accounts: mockAccounts }}>
Expand Down

0 comments on commit c1e7fd4

Please sign in to comment.