utils.spec.tsx 2.4 KB

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