usePageParams.spec.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {renderHook} from 'sentry-test/reactTestingLibrary';
  2. import {usePageParams} from 'sentry/views/traces/hooks/usePageParams';
  3. describe('usePageParams', function () {
  4. it('decodes no queries on page', function () {
  5. const location = {query: {}};
  6. const {result} = renderHook(() => usePageParams(location), {
  7. initialProps: {location},
  8. });
  9. expect(result.current.queries).toEqual([]);
  10. });
  11. it('decodes single query on page', function () {
  12. const location = {query: {query: 'query1'}};
  13. const {result} = renderHook(() => usePageParams(location), {
  14. initialProps: {location},
  15. });
  16. expect(result.current.queries).toEqual(['query1']);
  17. });
  18. it('decodes multiple queries on page', function () {
  19. const location = {query: {query: ['query1', 'query2', 'query3']}};
  20. const {result} = renderHook(() => usePageParams(location), {
  21. initialProps: {location},
  22. });
  23. expect(result.current.queries).toEqual(['query1', 'query2', 'query3']);
  24. });
  25. it('decodes metrics related params', function () {
  26. const location = {
  27. query: {
  28. metricsMax: '456',
  29. metricsMin: '123',
  30. metricsOp: 'sum',
  31. metricsQuery: 'foo:bar',
  32. mri: 'd:transactions/duration@millisecond',
  33. },
  34. };
  35. const {result} = renderHook(() => usePageParams(location), {
  36. initialProps: {location},
  37. });
  38. expect(result.current).toEqual({
  39. queries: [],
  40. metricsMax: '456',
  41. metricsMin: '123',
  42. metricsOp: 'sum',
  43. metricsQuery: 'foo:bar',
  44. mri: 'd:transactions/duration@millisecond',
  45. });
  46. });
  47. });