releasesSelectControl.spec.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {ReleasesContext} from 'sentry/utils/releases/releasesProvider';
  3. import ReleasesSelectControl from 'sentry/views/dashboardsV2/releasesSelectControl';
  4. function renderReleasesSelect() {
  5. render(
  6. <ReleasesContext.Provider
  7. value={{
  8. releases: [
  9. TestStubs.Release({
  10. shortVersion: 'sentry-android-shop@1.2.0',
  11. version: 'sentry-android-shop@1.2.0',
  12. }),
  13. TestStubs.Release({
  14. shortVersion: 'sentry-android-shop@1.3.0',
  15. version: 'sentry-android-shop@1.3.0',
  16. }),
  17. TestStubs.Release({
  18. shortVersion: 'sentry-android-shop@1.4.0',
  19. version: 'sentry-android-shop@1.4.0',
  20. }),
  21. ],
  22. loading: false,
  23. }}
  24. >
  25. <ReleasesSelectControl selectedReleases={[]} />
  26. </ReleasesContext.Provider>
  27. );
  28. }
  29. describe('Dashboards > ReleasesSelectControl', function () {
  30. it('updates menu title with selection', function () {
  31. renderReleasesSelect();
  32. expect(screen.getByText('All Releases')).toBeInTheDocument();
  33. userEvent.click(screen.getByText('All Releases'));
  34. userEvent.click(screen.getByText('sentry-android-shop@1.2.0'));
  35. userEvent.click(document.body);
  36. expect(screen.getByText('sentry-android-shop@1.2.0')).toBeInTheDocument();
  37. expect(screen.queryByText('+1')).not.toBeInTheDocument();
  38. });
  39. it('updates menu title with multiple selections', function () {
  40. renderReleasesSelect();
  41. expect(screen.getByText('All Releases')).toBeInTheDocument();
  42. userEvent.click(screen.getByText('All Releases'));
  43. userEvent.click(screen.getByText('sentry-android-shop@1.2.0'));
  44. userEvent.click(screen.getByText('sentry-android-shop@1.4.0'));
  45. userEvent.click(document.body);
  46. expect(screen.getByText('sentry-android-shop@1.2.0')).toBeInTheDocument();
  47. expect(screen.getByText('+1')).toBeInTheDocument();
  48. });
  49. });