ssoForm.spec.jsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {browserHistory} from 'react-router';
  2. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import SsoForm from 'sentry/views/auth/ssoForm';
  4. describe('SsoForm', function () {
  5. const api = new MockApiClient();
  6. async function doSso(apiRequest) {
  7. await userEvent.type(
  8. screen.getByRole('textbox', {name: 'Organization ID'}),
  9. 'org123'
  10. );
  11. await userEvent.click(screen.getByRole('button', {name: 'Continue'}));
  12. expect(apiRequest).toHaveBeenCalledWith(
  13. '/auth/sso-locate/',
  14. expect.objectContaining({data: {organization: 'org123'}})
  15. );
  16. }
  17. it('renders', function () {
  18. const authConfig = {
  19. serverHostname: 'testserver',
  20. };
  21. render(<SsoForm api={api} authConfig={authConfig} />);
  22. expect(screen.getByLabelText('Organization ID')).toBeInTheDocument();
  23. });
  24. it('handles errors', async function () {
  25. const mockRequest = MockApiClient.addMockResponse({
  26. url: '/auth/sso-locate/',
  27. method: 'POST',
  28. statusCode: 400,
  29. body: {
  30. detail: 'Invalid org name',
  31. },
  32. });
  33. const authConfig = {};
  34. render(<SsoForm api={api} authConfig={authConfig} />);
  35. await doSso(mockRequest);
  36. expect(await screen.findByText('Invalid org name')).toBeInTheDocument();
  37. });
  38. it('handles success', async function () {
  39. const mockRequest = MockApiClient.addMockResponse({
  40. url: '/auth/sso-locate/',
  41. method: 'POST',
  42. statusCode: 200,
  43. body: {
  44. nextUri: '/next/',
  45. },
  46. });
  47. const authConfig = {};
  48. render(<SsoForm api={api} authConfig={authConfig} />);
  49. await doSso(mockRequest);
  50. await waitFor(() =>
  51. expect(browserHistory.push).toHaveBeenCalledWith({pathname: '/next/'})
  52. );
  53. });
  54. });