samplingModal.spec.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {initializeData as _initializeData} from 'sentry-test/performance/initializePerformanceData';
  2. import {act, render, screen} from 'sentry-test/reactTestingLibrary';
  3. import TeamStore from 'sentry/stores/teamStore';
  4. import EventView from 'sentry/utils/discover/eventView';
  5. import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  6. import {OrganizationContext} from 'sentry/views/organizationContext';
  7. import SamplingModal from 'sentry/views/performance/landing/samplingModal';
  8. const initializeData = () => {
  9. const data = _initializeData({
  10. query: {statsPeriod: '7d', environment: ['prod'], project: [-42]},
  11. });
  12. data.eventView.additionalConditions.addFilterValues('transaction.op', ['pageload']);
  13. return data;
  14. };
  15. const stubEl: any = props => <div>{props.children}</div>;
  16. function WrappedComponent({data}) {
  17. const eventView = EventView.fromLocation(data.router.location);
  18. return (
  19. <OrganizationContext.Provider value={data.organization}>
  20. <MEPSettingProvider>
  21. <SamplingModal
  22. Header={stubEl}
  23. Footer={stubEl}
  24. Body={stubEl}
  25. CloseButton={stubEl}
  26. eventView={eventView}
  27. organization={data.organization}
  28. onApply={() => {}}
  29. closeModal={() => void 0}
  30. projects={data.projects}
  31. isMEPEnabled={data.isMEPEnabled}
  32. />
  33. </MEPSettingProvider>
  34. </OrganizationContext.Provider>
  35. );
  36. }
  37. describe('Performance > Landing > SamplingModal', function () {
  38. let wrapper: any;
  39. act(() => void TeamStore.loadInitialData([], false, null));
  40. afterEach(function () {
  41. if (wrapper) {
  42. wrapper.unmount();
  43. wrapper = undefined;
  44. }
  45. });
  46. it('renders sampling modal', async function () {
  47. const data = initializeData();
  48. wrapper = render(<WrappedComponent data={data} />);
  49. expect(await screen.findByLabelText('Always show sampled data')).toBeInTheDocument();
  50. expect(
  51. await screen.findByLabelText('Automatically switch to sampled data when required')
  52. ).toBeInTheDocument();
  53. });
  54. });