settingsIndex.spec.jsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {shallow, mount} from 'enzyme';
  2. import React from 'react';
  3. import * as OrgActions from 'app/actionCreators/organizations';
  4. import {SettingsIndex} from 'app/views/settings/settingsIndex';
  5. import ConfigStore from 'app/stores/configStore';
  6. describe('SettingsIndex', function() {
  7. let wrapper;
  8. it('renders', function() {
  9. wrapper = shallow(<SettingsIndex organization={TestStubs.Organization()} />);
  10. expect(wrapper).toMatchSnapshot();
  11. });
  12. it('has loading when there is no organization', function() {
  13. wrapper = shallow(<SettingsIndex organization={null} />);
  14. expect(wrapper.find('LoadingIndicator')).toHaveLength(1);
  15. });
  16. it('has different links for on premise users', function() {
  17. ConfigStore.set('isOnPremise', true);
  18. wrapper = shallow(<SettingsIndex organization={TestStubs.Organization()} />);
  19. expect(
  20. wrapper.find(
  21. 'HomePanelHeader SupportLinkComponent[href="https://forum.sentry.io/"]'
  22. )
  23. ).toHaveLength(1);
  24. expect(
  25. wrapper
  26. .find('HomePanelBody SupportLinkComponent[href="https://forum.sentry.io/"]')
  27. .prop('children')
  28. ).toBe('Community Forums');
  29. });
  30. describe('Fetch org details for Sidebar', function() {
  31. let spy;
  32. let api;
  33. const organization = {
  34. id: '44',
  35. name: 'Org Index',
  36. slug: 'org-index',
  37. };
  38. beforeEach(function() {
  39. spy = jest.spyOn(OrgActions, 'fetchOrganizationDetails');
  40. api = MockApiClient.addMockResponse({
  41. url: `/organizations/${organization.slug}/`,
  42. });
  43. ConfigStore.config.isOnPremise = false;
  44. wrapper = mount(<SettingsIndex params={{}} />, TestStubs.routerContext());
  45. });
  46. it('fetches org details for SidebarDropdown', function() {
  47. // org from index endpoint, no `access` info
  48. wrapper.setProps({organization});
  49. wrapper.update();
  50. expect(spy).toHaveBeenCalledWith(organization.slug, {
  51. setActive: true,
  52. loadProjects: true,
  53. });
  54. expect(api).toHaveBeenCalledTimes(1);
  55. });
  56. it('does not fetch org details for SidebarDropdown', function() {
  57. // org already has details
  58. wrapper.setProps({organization: TestStubs.Organization()});
  59. wrapper.update();
  60. expect(spy).not.toHaveBeenCalledWith();
  61. expect(api).not.toHaveBeenCalled();
  62. });
  63. });
  64. });