index.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import {Organization} 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 ThresholdsList from 'sentry/views/releases/thresholdsList/';
  6. import {THRESHOLDS_PATH} from '../utils/constants';
  7. describe('ReleaseThresholdsList', () => {
  8. const organization = Organization({
  9. slug: 'test-thresholds',
  10. features: ['release-ui-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 = Organization({
  30. slug: 'test-thresholds-no-flag',
  31. features: [],
  32. });
  33. const {router: flaglessRouter, routerContext: flaglessRouterContext} = initializeOrg({
  34. organization: organization2,
  35. });
  36. render(<ThresholdsList />, {
  37. context: flaglessRouterContext,
  38. organization: organization2,
  39. });
  40. expect(flaglessRouter.replace).toHaveBeenCalledTimes(1);
  41. expect(flaglessRouter.replace).toHaveBeenCalledWith(`/releases/`);
  42. });
  43. it('fetches release thresholds for selected projects', async () => {
  44. const query = {
  45. project: [-1],
  46. };
  47. PageFiltersStore.onInitializeUrlState(
  48. {
  49. projects: [],
  50. environments: [],
  51. datetime: {start: null, end: null, period: '1d', utc: null},
  52. },
  53. new Set()
  54. );
  55. routerContext.context.location.pathname = THRESHOLDS_PATH;
  56. render(<ThresholdsList />, {
  57. context: routerContext,
  58. organization,
  59. });
  60. expect(await screen.findByText('Thresholds')).toBeInTheDocument();
  61. expect(mockThresholdFetch).toHaveBeenCalledWith(
  62. '/organizations/test-thresholds/release-thresholds/',
  63. expect.objectContaining({query})
  64. );
  65. expect(router.replace).not.toHaveBeenCalled();
  66. });
  67. it('filters fetch based on projects/environments selected', async () => {
  68. const expectedQuery = {
  69. project: [1, 2, 3],
  70. environment: ['foo'],
  71. };
  72. PageFiltersStore.onInitializeUrlState(
  73. {
  74. projects: [1, 2, 3],
  75. environments: ['foo'],
  76. datetime: {start: null, end: null, period: '14d', utc: null},
  77. },
  78. new Set()
  79. );
  80. routerContext.context.location.pathname = THRESHOLDS_PATH;
  81. render(<ThresholdsList />, {context: routerContext, organization});
  82. expect(await screen.findByText('Thresholds')).toBeInTheDocument();
  83. expect(mockThresholdFetch).toHaveBeenCalledWith(
  84. '/organizations/test-thresholds/release-thresholds/',
  85. expect.objectContaining({query: expectedQuery})
  86. );
  87. });
  88. });