ssoForm.spec.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 routerContext = TestStubs.routerContext();
  14. const api = new MockApiClient();
  15. it('renders', function () {
  16. const authConfig = {
  17. serverHostname: 'testserver',
  18. };
  19. const wrapper = mountWithTheme(
  20. <SsoForm api={api} authConfig={authConfig} />,
  21. routerContext
  22. );
  23. expect(wrapper.find('.help-block').text()).toBe(
  24. 'Your ID is the slug after the hostname. e.g. testserver/acme is acme.'
  25. );
  26. });
  27. it('handles errors', async function () {
  28. const mockRequest = MockApiClient.addMockResponse({
  29. url: '/auth/sso-locate/',
  30. method: 'POST',
  31. statusCode: 400,
  32. body: {
  33. detail: 'Invalid org name',
  34. },
  35. });
  36. const authConfig = {};
  37. const wrapper = mountWithTheme(
  38. <SsoForm api={api} authConfig={authConfig} />,
  39. routerContext
  40. );
  41. doSso(wrapper, mockRequest);
  42. await tick();
  43. wrapper.update();
  44. expect(wrapper.find('.alert').exists()).toBe(true);
  45. });
  46. it('handles success', async function () {
  47. const mockRequest = MockApiClient.addMockResponse({
  48. url: '/auth/sso-locate/',
  49. method: 'POST',
  50. statusCode: 200,
  51. body: {
  52. nextUri: '/next/',
  53. },
  54. });
  55. const authConfig = {};
  56. const wrapper = mountWithTheme(
  57. <SsoForm api={api} authConfig={authConfig} />,
  58. routerContext
  59. );
  60. doSso(wrapper, mockRequest);
  61. await tick();
  62. expect(browserHistory.push).toHaveBeenCalledWith({pathname: '/next/'});
  63. });
  64. });