notificationSettingsByEntity.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import ConfigStore from 'sentry/stores/configStore';
  5. import NotificationSettingsByEntity from 'sentry/views/settings/account/notifications/notificationSettingsByEntity';
  6. describe('NotificationSettingsByEntity', function () {
  7. afterEach(() => {
  8. MockApiClient.clearMockResponses();
  9. jest.clearAllMocks();
  10. });
  11. it('should default to the subdomain org', async function () {
  12. const organization = OrganizationFixture();
  13. const otherOrganization = OrganizationFixture({
  14. id: '2',
  15. slug: 'other-org',
  16. name: 'other org',
  17. });
  18. ConfigStore.set('customerDomain', {
  19. ...ConfigStore.get('customerDomain')!,
  20. subdomain: otherOrganization.slug,
  21. });
  22. const projectsMock = MockApiClient.addMockResponse({
  23. url: `/organizations/${otherOrganization.slug}/projects/`,
  24. method: 'GET',
  25. body: [],
  26. });
  27. render(
  28. <NotificationSettingsByEntity
  29. organizations={[organization, otherOrganization]}
  30. notificationType="alerts"
  31. notificationOptions={[]}
  32. handleRemoveNotificationOption={jest.fn()}
  33. handleAddNotificationOption={jest.fn()}
  34. handleEditNotificationOption={jest.fn()}
  35. entityType={'project' as const}
  36. />
  37. );
  38. expect(await screen.findByText(otherOrganization.name)).toBeInTheDocument();
  39. expect(projectsMock).toHaveBeenCalledTimes(1);
  40. });
  41. it('should load from the organization region', async function () {
  42. const organization = OrganizationFixture();
  43. const deOrg = OrganizationFixture({
  44. id: '2',
  45. slug: 'de-org',
  46. name: 'de org',
  47. links: {
  48. organizationUrl: 'https://de-org.sentry.io',
  49. regionUrl: 'https://de.sentry.io',
  50. },
  51. });
  52. ConfigStore.set('customerDomain', {
  53. ...ConfigStore.get('customerDomain')!,
  54. subdomain: deOrg.slug,
  55. });
  56. const projectsMock = MockApiClient.addMockResponse({
  57. url: `/organizations/${deOrg.slug}/projects/`,
  58. method: 'GET',
  59. body: [ProjectFixture({organization: deOrg})],
  60. match: [
  61. function (_url: string, options: Record<string, any>) {
  62. return options.host === 'https://de.sentry.io';
  63. },
  64. ],
  65. });
  66. render(
  67. <NotificationSettingsByEntity
  68. organizations={[organization, deOrg]}
  69. notificationType="alerts"
  70. notificationOptions={[]}
  71. handleRemoveNotificationOption={jest.fn()}
  72. handleAddNotificationOption={jest.fn()}
  73. handleEditNotificationOption={jest.fn()}
  74. entityType={'project' as const}
  75. />
  76. );
  77. expect(await screen.findByText(deOrg.name)).toBeInTheDocument();
  78. expect(projectsMock).toHaveBeenCalledTimes(1);
  79. });
  80. });