12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import {shallow, mount} from 'enzyme';
- import React from 'react';
- import * as OrgActions from 'app/actionCreators/organizations';
- import {SettingsIndex} from 'app/views/settings/settingsIndex';
- import ConfigStore from 'app/stores/configStore';
- describe('SettingsIndex', function() {
- let wrapper;
- it('renders', function() {
- wrapper = shallow(<SettingsIndex organization={TestStubs.Organization()} />);
- expect(wrapper).toMatchSnapshot();
- });
- it('has loading when there is no organization', function() {
- wrapper = shallow(<SettingsIndex organization={null} />);
- expect(wrapper.find('LoadingIndicator')).toHaveLength(1);
- });
- it('has different links for on premise users', function() {
- ConfigStore.set('isOnPremise', true);
- wrapper = shallow(<SettingsIndex organization={TestStubs.Organization()} />);
- expect(
- wrapper.find(
- 'HomePanelHeader SupportLinkComponent[href="https://forum.sentry.io/"]'
- )
- ).toHaveLength(1);
- expect(
- wrapper
- .find('HomePanelBody SupportLinkComponent[href="https://forum.sentry.io/"]')
- .prop('children')
- ).toBe('Community Forums');
- });
- describe('Fetch org details for Sidebar', function() {
- let spy;
- let api;
- const organization = {
- id: '44',
- name: 'Org Index',
- slug: 'org-index',
- };
- beforeEach(function() {
- spy = jest.spyOn(OrgActions, 'fetchOrganizationDetails');
- api = MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/`,
- });
- ConfigStore.config.isOnPremise = false;
- wrapper = mount(<SettingsIndex params={{}} />, TestStubs.routerContext());
- });
- it('fetches org details for SidebarDropdown', function() {
- // org from index endpoint, no `access` info
- wrapper.setProps({organization});
- wrapper.update();
- expect(spy).toHaveBeenCalledWith(organization.slug, {
- setActive: true,
- loadProjects: true,
- });
- expect(api).toHaveBeenCalledTimes(1);
- });
- it('does not fetch org details for SidebarDropdown', function() {
- // org already has details
- wrapper.setProps({organization: TestStubs.Organization()});
- wrapper.update();
- expect(spy).not.toHaveBeenCalledWith();
- expect(api).not.toHaveBeenCalled();
- });
- });
- });
|