environmentPageFilter.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  4. import OrganizationStore from 'sentry/stores/organizationStore';
  5. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  6. import ProjectsStore from 'sentry/stores/projectsStore';
  7. const {organization, router, routerContext} = initializeOrg({
  8. organization: {features: ['global-views']},
  9. project: undefined,
  10. projects: [
  11. {
  12. id: 2,
  13. slug: 'project-2',
  14. environments: ['prod', 'staging'],
  15. },
  16. ],
  17. router: {
  18. location: {
  19. pathname: '/organizations/org-slug/issues/',
  20. query: {},
  21. },
  22. params: {orgId: 'org-slug'},
  23. },
  24. });
  25. describe('EnvironmentPageFilter', function () {
  26. beforeEach(() => {
  27. OrganizationStore.init();
  28. OrganizationStore.onUpdate(organization, {replace: true});
  29. ProjectsStore.init();
  30. ProjectsStore.loadInitialData(organization.projects);
  31. PageFiltersStore.reset();
  32. PageFiltersStore.onInitializeUrlState(
  33. {
  34. projects: [2],
  35. environments: [],
  36. datetime: {start: null, end: null, period: '14d', utc: null},
  37. },
  38. new Set()
  39. );
  40. });
  41. afterEach(() => {
  42. OrganizationStore.teardown();
  43. ProjectsStore.teardown();
  44. });
  45. it('can pick environment', function () {
  46. render(<EnvironmentPageFilter />, {
  47. context: routerContext,
  48. organization,
  49. });
  50. // Open the environment dropdown
  51. expect(screen.getByText('All Envs')).toBeInTheDocument();
  52. userEvent.click(screen.getByText('All Envs'));
  53. // Click the first environment's checkbox
  54. const envOptions = screen.getAllByTestId('checkbox-fancy');
  55. userEvent.click(envOptions[0]);
  56. // Close the dropdown
  57. userEvent.click(screen.getAllByText('prod')[0]);
  58. // Verify we were redirected
  59. expect(router.push).toHaveBeenCalledWith(
  60. expect.objectContaining({query: {environment: ['prod']}})
  61. );
  62. });
  63. it('can pin environment', async function () {
  64. render(<EnvironmentPageFilter />, {
  65. context: routerContext,
  66. organization,
  67. });
  68. // Confirm no filters are pinned
  69. expect(PageFiltersStore.getState()).toEqual(
  70. expect.objectContaining({
  71. pinnedFilters: new Set(),
  72. })
  73. );
  74. // Open the environment dropdown
  75. expect(screen.getByText('All Envs')).toBeInTheDocument();
  76. userEvent.click(screen.getByText('All Envs'));
  77. // Click the pin button
  78. const pinButton = screen.getByRole('button', {name: 'Lock filter'});
  79. userEvent.click(pinButton, undefined, {skipHover: true});
  80. await screen.findByRole('button', {name: 'Lock filter', pressed: true});
  81. // Check if the pin indicator has been added
  82. expect(screen.getByLabelText('Filter applied across pages')).toBeInTheDocument();
  83. expect(PageFiltersStore.getState()).toEqual(
  84. expect.objectContaining({
  85. pinnedFilters: new Set(['environments']),
  86. })
  87. );
  88. });
  89. it('can quick select', async function () {
  90. render(<EnvironmentPageFilter />, {
  91. context: routerContext,
  92. organization,
  93. });
  94. // Open the environment dropdown
  95. expect(screen.getByText('All Envs')).toBeInTheDocument();
  96. userEvent.click(screen.getByText('All Envs'));
  97. // Click the first environment directly
  98. userEvent.click(screen.getByText('prod'));
  99. // Verify we were redirected
  100. expect(router.push).toHaveBeenCalledWith(
  101. expect.objectContaining({query: {environment: ['prod']}})
  102. );
  103. await screen.findByText('prod');
  104. expect(PageFiltersStore.getState()).toEqual(
  105. expect.objectContaining({
  106. isReady: true,
  107. selection: {
  108. datetime: {
  109. end: null,
  110. period: '14d',
  111. start: null,
  112. utc: null,
  113. },
  114. environments: ['prod'],
  115. projects: [2],
  116. },
  117. })
  118. );
  119. });
  120. });