login.spec.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import Login from 'sentry/views/auth/login';
  3. describe('Login', function () {
  4. afterEach(function () {
  5. MockApiClient.clearMockResponses();
  6. });
  7. it('renders a loading indicator', function () {
  8. MockApiClient.addMockResponse({
  9. url: '/auth/config/',
  10. body: {},
  11. });
  12. render(<Login params={{}} />);
  13. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  14. });
  15. it('renders an error if auth config cannot be loaded', async function () {
  16. MockApiClient.addMockResponse({
  17. url: '/auth/config/',
  18. statusCode: 500,
  19. });
  20. render(<Login params={{}} />);
  21. expect(
  22. await screen.findByText('Unable to load authentication configuration')
  23. ).toBeInTheDocument();
  24. });
  25. it('does not show register when disabled', async function () {
  26. MockApiClient.addMockResponse({
  27. url: '/auth/config/',
  28. body: {canRegister: false},
  29. });
  30. render(<Login params={{}} />);
  31. expect(await screen.findByText('Lost your password?')).toBeInTheDocument();
  32. expect(screen.queryByText('Register')).not.toBeInTheDocument();
  33. });
  34. it('shows register when canRegister is enabled', async function () {
  35. MockApiClient.addMockResponse({
  36. url: '/auth/config/',
  37. body: {canRegister: true},
  38. });
  39. render(<Login params={{}} />);
  40. expect(await screen.findByRole('link', {name: 'Register'})).toBeInTheDocument();
  41. });
  42. it('toggles between tabs', async function () {
  43. MockApiClient.addMockResponse({
  44. url: '/auth/config/',
  45. body: {canRegister: true},
  46. });
  47. render(<Login params={{}} />);
  48. // Default tab is login
  49. expect(await screen.findByPlaceholderText('username or email')).toBeInTheDocument();
  50. userEvent.click(screen.getByRole('link', {name: 'Single Sign-On'}));
  51. expect(screen.getByRole('textbox', {name: 'Organization ID'})).toBeInTheDocument();
  52. userEvent.click(screen.getByRole('link', {name: 'Register'}));
  53. expect(screen.getByRole('textbox', {name: 'Name'})).toBeInTheDocument();
  54. });
  55. });