ssoForm.spec.jsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {browserHistory} from 'react-router';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import SsoForm from 'sentry/views/auth/ssoForm';
  4. function doSso(wrapper, apiRequest) {
  5. wrapper.find('#id-organization').simulate('change', {target: {value: 'org123'}});
  6. wrapper.find('form').simulate('submit');
  7. expect(apiRequest).toHaveBeenCalledWith(
  8. '/auth/sso-locate/',
  9. expect.objectContaining({data: {organization: 'org123'}})
  10. );
  11. }
  12. describe('SsoForm', function () {
  13. const api = new MockApiClient();
  14. it('renders', function () {
  15. const authConfig = {
  16. serverHostname: 'testserver',
  17. };
  18. const wrapper = mountWithTheme(<SsoForm api={api} authConfig={authConfig} />);
  19. expect(wrapper.find('.help-block').text()).toBe(
  20. 'Your ID is the slug after the hostname. e.g. testserver/acme is acme.'
  21. );
  22. });
  23. it('handles errors', async function () {
  24. const mockRequest = MockApiClient.addMockResponse({
  25. url: '/auth/sso-locate/',
  26. method: 'POST',
  27. statusCode: 400,
  28. body: {
  29. detail: 'Invalid org name',
  30. },
  31. });
  32. const authConfig = {};
  33. const wrapper = mountWithTheme(<SsoForm api={api} authConfig={authConfig} />);
  34. doSso(wrapper, mockRequest);
  35. await tick();
  36. wrapper.update();
  37. expect(wrapper.find('.alert').exists()).toBe(true);
  38. });
  39. it('handles success', async function () {
  40. const mockRequest = MockApiClient.addMockResponse({
  41. url: '/auth/sso-locate/',
  42. method: 'POST',
  43. statusCode: 200,
  44. body: {
  45. nextUri: '/next/',
  46. },
  47. });
  48. const authConfig = {};
  49. const wrapper = mountWithTheme(<SsoForm api={api} authConfig={authConfig} />);
  50. doSso(wrapper, mockRequest);
  51. await tick();
  52. expect(browserHistory.push).toHaveBeenCalledWith({pathname: '/next/'});
  53. });
  54. });