import {initializeOrg} from 'sentry-test/initializeOrg';
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
import Login from 'sentry/views/auth/login';
describe('Login', function () {
const {routerProps} = initializeOrg();
afterEach(function () {
MockApiClient.clearMockResponses();
});
it('renders a loading indicator', async function () {
MockApiClient.addMockResponse({
url: '/auth/config/',
body: {},
});
render();
expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
expect(await screen.findByText('Lost your password?')).toBeInTheDocument();
});
it('renders an error if auth config cannot be loaded', async function () {
MockApiClient.addMockResponse({
url: '/auth/config/',
statusCode: 500,
});
render();
expect(
await screen.findByText('Unable to load authentication configuration')
).toBeInTheDocument();
});
it('does not show register when disabled', async function () {
MockApiClient.addMockResponse({
url: '/auth/config/',
body: {canRegister: false},
});
render();
expect(await screen.findByText('Lost your password?')).toBeInTheDocument();
expect(screen.queryByText('Register')).not.toBeInTheDocument();
});
it('shows register when canRegister is enabled', async function () {
MockApiClient.addMockResponse({
url: '/auth/config/',
body: {canRegister: true},
});
render();
expect(await screen.findByRole('link', {name: 'Register'})).toBeInTheDocument();
});
it('toggles between tabs', async function () {
MockApiClient.addMockResponse({
url: '/auth/config/',
body: {canRegister: true},
});
render();
// Default tab is login
expect(await screen.findByPlaceholderText('username or email')).toBeInTheDocument();
await userEvent.click(screen.getByRole('link', {name: 'Single Sign-On'}));
expect(screen.getByRole('textbox', {name: 'Organization ID'})).toBeInTheDocument();
await userEvent.click(screen.getByRole('link', {name: 'Register'}));
expect(screen.getByRole('textbox', {name: 'Name'})).toBeInTheDocument();
});
});