useTruncatedRelease.spec.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {renderHook} from 'sentry-test/reactTestingLibrary';
  2. import {useReleaseSelection} from 'sentry/views/insights/common/queries/useReleases';
  3. import {ELLIPSIS} from 'sentry/views/insights/common/utils/centerTruncate';
  4. import useTruncatedReleaseNames from 'sentry/views/insights/mobile/common/queries/useTruncatedRelease';
  5. jest.mock('sentry/views/insights/common/queries/useReleases');
  6. jest.mocked(useReleaseSelection).mockReturnValue({
  7. primaryRelease: 'com.example.vu.android@2.10.5-alpha.1+42',
  8. isLoading: false,
  9. secondaryRelease: 'com.example.vu.android@2.10.3+42',
  10. });
  11. describe('useTruncatedRelease', () => {
  12. it('truncates long release names to 12 characters by default', () => {
  13. const {result} = renderHook(useTruncatedReleaseNames);
  14. expect(
  15. [...result.current.truncatedPrimaryRelease].filter(char => char !== ELLIPSIS)
  16. ).toHaveLength(12);
  17. expect(result.current.truncatedPrimaryRelease).toBe('2.10.5…1 (42)');
  18. expect(result.current.truncatedSecondaryRelease).toBe('2.10.3 (42)');
  19. });
  20. it('truncates long release names to provided length limit', () => {
  21. const {result} = renderHook(useTruncatedReleaseNames, {
  22. initialProps: 5,
  23. });
  24. expect(
  25. [...result.current.truncatedPrimaryRelease].filter(char => char !== ELLIPSIS).length
  26. ).toBeLessThanOrEqual(5);
  27. expect(result.current.truncatedPrimaryRelease).toBe('2.…2)');
  28. expect(result.current.truncatedSecondaryRelease).toBe('2.…2)');
  29. });
  30. });