notificationSettingsByProjects.spec.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {Project} from 'sentry/types';
  4. import NotificationSettingsByProjects from 'sentry/views/settings/account/notifications/notificationSettingsByProjects';
  5. const renderComponent = (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. render(
  21. <NotificationSettingsByProjects
  22. notificationType="alerts"
  23. notificationSettings={notificationSettings}
  24. onChange={jest.fn()}
  25. onSubmitSuccess={jest.fn()}
  26. />,
  27. {context: routerContext}
  28. );
  29. };
  30. describe('NotificationSettingsByProjects', function () {
  31. it('should render when there are no projects', function () {
  32. renderComponent([]);
  33. expect(screen.getByTestId('empty-message')).toHaveTextContent('No projects found');
  34. expect(screen.queryByPlaceholderText('Search Projects')).not.toBeInTheDocument();
  35. });
  36. it('should show search bar when there are enough projects', function () {
  37. const organization = TestStubs.Organization();
  38. const projects = [...Array(3).keys()].map(id =>
  39. TestStubs.Project({organization, id})
  40. );
  41. renderComponent(projects);
  42. expect(screen.getByPlaceholderText('Search Projects')).toBeInTheDocument();
  43. });
  44. });