index.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  5. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  6. import ThresholdsList from 'sentry/views/releases/thresholdsList/';
  7. describe('ReleaseThresholdsList', () => {
  8. const organization = OrganizationFixture({
  9. slug: 'test-thresholds',
  10. features: ['releases-v2'],
  11. });
  12. const {router, routerContext} = initializeOrg({
  13. organization,
  14. });
  15. let mockThresholdFetch;
  16. beforeEach(() => {
  17. mockThresholdFetch = MockApiClient.addMockResponse({
  18. url: `/organizations/${organization.slug}/release-thresholds/`,
  19. method: 'GET',
  20. body: [],
  21. });
  22. PageFiltersStore.init();
  23. });
  24. afterEach(() => {
  25. PageFiltersStore.reset();
  26. MockApiClient.clearMockResponses();
  27. });
  28. it('redirects to releases if flag is not set', () => {
  29. const organization2 = OrganizationFixture({
  30. slug: 'test-thresholds-no-flag',
  31. features: [],
  32. });
  33. const {router: flaglessRouter, routerContext: flaglessRouterContext} = initializeOrg({
  34. organization: organization2,
  35. });
  36. const expectedRedirect = normalizeUrl(
  37. `/organizations/${organization2.slug}/releases/`
  38. );
  39. render(<ThresholdsList />, {
  40. context: flaglessRouterContext,
  41. organization: organization2,
  42. });
  43. expect(flaglessRouter.replace).toHaveBeenCalledTimes(1);
  44. expect(flaglessRouter.replace).toHaveBeenCalledWith(expectedRedirect);
  45. });
  46. it('fetches release thresholds for selected projects', async () => {
  47. const query = {
  48. project: [-1],
  49. };
  50. PageFiltersStore.onInitializeUrlState(
  51. {
  52. projects: [],
  53. environments: [],
  54. datetime: {start: null, end: null, period: '1d', utc: null},
  55. },
  56. new Set()
  57. );
  58. routerContext.context.location.pathname = normalizeUrl(
  59. `/organizations/${organization.slug}/release-thresholds/`
  60. );
  61. render(<ThresholdsList />, {
  62. context: routerContext,
  63. organization,
  64. });
  65. expect(await screen.findByText('Thresholds')).toBeInTheDocument();
  66. expect(mockThresholdFetch).toHaveBeenCalledWith(
  67. '/organizations/test-thresholds/release-thresholds/',
  68. expect.objectContaining({query})
  69. );
  70. expect(router.replace).not.toHaveBeenCalled();
  71. });
  72. it('filters fetch based on projects/environments selected', async () => {
  73. const expectedQuery = {
  74. project: [1, 2, 3],
  75. environment: ['foo'],
  76. };
  77. PageFiltersStore.onInitializeUrlState(
  78. {
  79. projects: [1, 2, 3],
  80. environments: ['foo'],
  81. datetime: {start: null, end: null, period: '14d', utc: null},
  82. },
  83. new Set()
  84. );
  85. routerContext.context.location.pathname = normalizeUrl(
  86. `/organizations/${organization.slug}/release-thresholds/`
  87. );
  88. render(<ThresholdsList />, {context: routerContext, organization});
  89. expect(await screen.findByText('Thresholds')).toBeInTheDocument();
  90. expect(mockThresholdFetch).toHaveBeenCalledWith(
  91. '/organizations/test-thresholds/release-thresholds/',
  92. expect.objectContaining({query: expectedQuery})
  93. );
  94. });
  95. });