notificationSettingsByProjects.spec.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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, organization} = 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. organizationId={organization.id}
  27. organizations={[organization]}
  28. handleOrgChange={jest.fn()}
  29. />,
  30. {context: routerContext}
  31. );
  32. };
  33. describe('NotificationSettingsByProjects', function () {
  34. it('should render when there are no projects', function () {
  35. renderComponent([]);
  36. expect(screen.getByTestId('empty-message')).toHaveTextContent('No projects found');
  37. expect(screen.queryByPlaceholderText('Search Projects')).not.toBeInTheDocument();
  38. });
  39. it('should show search bar when there are enough projects', function () {
  40. const organization = TestStubs.Organization();
  41. const projects = [...Array(3).keys()].map(id =>
  42. TestStubs.Project({organization, id})
  43. );
  44. renderComponent(projects);
  45. expect(screen.getByPlaceholderText('Search Projects')).toBeInTheDocument();
  46. });
  47. });