notificationSettingsByProjects.spec.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {Project} from 'sentry/types';
  4. import NotificationSettingsByProjects from 'sentry/views/settings/account/notifications/notificationSettingsByProjects';
  5. const createWrapper = (projects: Project[]) => {
  6. const {routerContext} = initializeOrg();
  7. MockApiClient.addMockResponse({
  8. url: '/projects/',
  9. method: 'GET',
  10. body: projects,
  11. });
  12. const notificationSettings = {
  13. alerts: {
  14. user: {me: {email: 'always', slack: 'always'}},
  15. project: Object.fromEntries(
  16. projects.map(project => [project.id, {email: 'never', slack: 'never'}])
  17. ),
  18. },
  19. };
  20. return mountWithTheme(
  21. <NotificationSettingsByProjects
  22. notificationType="alerts"
  23. notificationSettings={notificationSettings}
  24. onChange={jest.fn()}
  25. onSubmitSuccess={jest.fn()}
  26. />,
  27. routerContext
  28. );
  29. };
  30. describe('NotificationSettingsByProjects', function () {
  31. it('should render when there are no projects', function () {
  32. const wrapper = createWrapper([]);
  33. expect(wrapper.find('EmptyMessage').text()).toEqual('No projects found');
  34. expect(wrapper.find('AsyncComponentSearchInput')).toHaveLength(0);
  35. expect(wrapper.find('Pagination')).toHaveLength(0);
  36. });
  37. it('should show search bar when there are enough projects', function () {
  38. const organization = TestStubs.Organization();
  39. const projects = [...Array(3).keys()].map(id =>
  40. TestStubs.Project({organization, id})
  41. );
  42. const wrapper = createWrapper(projects);
  43. expect(wrapper.find('AsyncComponentSearchInput')).toHaveLength(1);
  44. });
  45. });