github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/components/Heatmap/useHeatmapSelection.hook.spec.tsx (about)

     1  import React, { RefObject } from 'react';
     2  import { renderHook } from '@testing-library/react-hooks';
     3  import { Provider } from 'react-redux';
     4  import { configureStore } from '@reduxjs/toolkit';
     5  import continuousReducer from '@webapp/redux/reducers/continuous';
     6  import tracingReducer from '@webapp/redux/reducers/tracing';
     7  
     8  import { useHeatmapSelection } from './useHeatmapSelection.hook';
     9  import { heatmapMockData } from '../../services/exemplarsTestData';
    10  
    11  const canvasEl = document.createElement('canvas');
    12  const divEl = document.createElement('div');
    13  const canvasRef = { current: canvasEl } as RefObject<HTMLCanvasElement>;
    14  const resizedSelectedAreaRef = { current: divEl } as RefObject<HTMLDivElement>;
    15  
    16  function createStore(preloadedState: any) {
    17    const store = configureStore({
    18      reducer: {
    19        continuous: continuousReducer,
    20        tracing: tracingReducer,
    21      },
    22      preloadedState,
    23    });
    24  
    25    return store;
    26  }
    27  
    28  describe('Hook: useHeatmapSelection', () => {
    29    const render = () =>
    30      renderHook(
    31        () =>
    32          useHeatmapSelection({
    33            canvasRef,
    34            resizedSelectedAreaRef,
    35            heatmapW: 1234,
    36            heatmap: heatmapMockData,
    37            onSelection: () => ({}),
    38          }),
    39        {
    40          wrapper: ({ children }) => (
    41            <Provider
    42              store={createStore({
    43                continuous: {},
    44                tracing: {
    45                  exemplarsSingleView: {},
    46                },
    47              })}
    48            >
    49              {children}
    50            </Provider>
    51          ),
    52        }
    53      ).result;
    54  
    55    it('should return initial selection values', () => {
    56      const { current } = render();
    57  
    58      expect(current).toMatchObject({
    59        selectedCoordinates: { start: null, end: null },
    60        selectedAreaToHeatmapRatio: 1,
    61        resetSelection: expect.any(Function),
    62      });
    63    });
    64  });