utils.spec.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {UserFixture} from 'sentry-fixture/user';
  3. import {act, renderHook} from 'sentry-test/reactTestingLibrary';
  4. import ConfigStore from 'sentry/stores/configStore';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import {useHasStreamlinedUI} from 'sentry/views/issueDetails/utils';
  7. jest.mock('sentry/utils/useLocation');
  8. describe('useHasStreamlinedUI', () => {
  9. it("respects the 'streamline' query param", () => {
  10. const location = LocationFixture({query: {streamline: '1'}});
  11. jest.mocked(useLocation).mockReturnValue(location);
  12. const {result: queryParamEnabled} = renderHook(useHasStreamlinedUI);
  13. expect(queryParamEnabled.current).toBe(true);
  14. location.query.streamline = '0';
  15. jest.mocked(useLocation).mockReturnValue(location);
  16. const {result: queryParamDisabled} = renderHook(useHasStreamlinedUI);
  17. expect(queryParamDisabled.current).toBe(false);
  18. });
  19. it('respects the user preferences', () => {
  20. ConfigStore.init();
  21. const user = UserFixture();
  22. user.options.prefersIssueDetailsStreamlinedUI = true;
  23. act(() => ConfigStore.set('user', user));
  24. const location = LocationFixture();
  25. jest.mocked(useLocation).mockReturnValue(location);
  26. const {result: userPrefersStreamline} = renderHook(useHasStreamlinedUI);
  27. expect(userPrefersStreamline.current).toBe(true);
  28. user.options.prefersIssueDetailsStreamlinedUI = false;
  29. act(() => ConfigStore.set('user', user));
  30. const {result: userPrefersLegacy} = renderHook(useHasStreamlinedUI);
  31. expect(userPrefersLegacy.current).toBe(false);
  32. });
  33. it('values query param above user preferences', () => {
  34. ConfigStore.init();
  35. const user = UserFixture();
  36. user.options.prefersIssueDetailsStreamlinedUI = false;
  37. act(() => ConfigStore.set('user', user));
  38. const location = LocationFixture({query: {streamline: '1'}});
  39. jest.mocked(useLocation).mockReturnValue(location);
  40. const {result: prefersLegacyButQueryParamEnabled} = renderHook(useHasStreamlinedUI);
  41. expect(prefersLegacyButQueryParamEnabled.current).toBe(true);
  42. user.options.prefersIssueDetailsStreamlinedUI = true;
  43. act(() => ConfigStore.set('user', user));
  44. location.query.streamline = '0';
  45. const {result: prefersStreamlineButQueryParamDisabled} =
  46. renderHook(useHasStreamlinedUI);
  47. expect(prefersStreamlineButQueryParamDisabled.current).toBe(false);
  48. });
  49. });