environmentPageFilter.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. it('can pick environment', function () {
  42. render(<EnvironmentPageFilter />, {
  43. context: routerContext,
  44. organization,
  45. });
  46. // Open the environment dropdown
  47. expect(screen.getByText('All Envs')).toBeInTheDocument();
  48. userEvent.click(screen.getByText('All Envs'));
  49. // Click the first environment's checkbox
  50. const envOptions = screen.getAllByTestId('checkbox-fancy');
  51. userEvent.click(envOptions[0]);
  52. // Close the dropdown
  53. userEvent.click(screen.getAllByText('prod')[0]);
  54. // Verify we were redirected
  55. expect(router.push).toHaveBeenCalledWith(
  56. expect.objectContaining({query: {environment: ['prod']}})
  57. );
  58. });
  59. it('can pin environment', async function () {
  60. render(<EnvironmentPageFilter />, {
  61. context: routerContext,
  62. organization,
  63. });
  64. // Confirm no filters are pinned
  65. expect(PageFiltersStore.getState()).toEqual(
  66. expect.objectContaining({
  67. pinnedFilters: new Set(),
  68. })
  69. );
  70. // Open the environment dropdown
  71. expect(screen.getByText('All Envs')).toBeInTheDocument();
  72. userEvent.click(screen.getByText('All Envs'));
  73. // Click the pin button
  74. const pinButton = screen.getByRole('button', {name: 'Lock filter'});
  75. userEvent.click(pinButton, undefined, {skipHover: true});
  76. await screen.findByRole('button', {name: 'Lock filter', pressed: true});
  77. // Check if the pin indicator has been added
  78. expect(screen.getByLabelText('Filter applied across pages')).toBeInTheDocument();
  79. expect(PageFiltersStore.getState()).toEqual(
  80. expect.objectContaining({
  81. pinnedFilters: new Set(['environments']),
  82. })
  83. );
  84. });
  85. it('can quick select', async function () {
  86. render(<EnvironmentPageFilter />, {
  87. context: routerContext,
  88. organization,
  89. });
  90. // Open the environment dropdown
  91. expect(screen.getByText('All Envs')).toBeInTheDocument();
  92. userEvent.click(screen.getByText('All Envs'));
  93. // Click the first environment directly
  94. userEvent.click(screen.getByText('prod'));
  95. // Verify we were redirected
  96. expect(router.push).toHaveBeenCalledWith(
  97. expect.objectContaining({query: {environment: ['prod']}})
  98. );
  99. await screen.findByText('prod');
  100. expect(PageFiltersStore.getState()).toEqual(
  101. expect.objectContaining({
  102. isReady: true,
  103. selection: {
  104. datetime: {
  105. end: null,
  106. period: '14d',
  107. start: null,
  108. utc: null,
  109. },
  110. environments: ['prod'],
  111. projects: [2],
  112. },
  113. })
  114. );
  115. });
  116. });