ssoForm.spec.jsx 1.7 KB

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