login.spec.tsx 2.3 KB

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