github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/components/TimelineChart/markings.spec.ts (about)

     1  import Color from 'color';
     2  import { markingsFromSelection } from './markings';
     3  
     4  // Tests are definitely confusing, but that's due to the nature of the implementation
     5  // TODO: refactor implementatino
     6  describe('markingsFromSelection', () => {
     7    it('returns nothing when theres no selection', () => {
     8      expect(markingsFromSelection('single')).toStrictEqual([]);
     9    });
    10  
    11    const from = 1663000000;
    12    const to = 1665000000;
    13    const color = Color('red');
    14  
    15    it('ignores color when selection is single', () => {
    16      expect(
    17        markingsFromSelection('single', {
    18          from: `${from}`,
    19          to: `${to}`,
    20          color,
    21          overlayColor: color,
    22        })
    23      ).toStrictEqual([
    24        {
    25          color: Color('transparent'),
    26          xaxis: {
    27            from: from * 1000,
    28            to: to * 1000,
    29          },
    30        },
    31        {
    32          color: Color('transparent'),
    33          lineWidth: 1,
    34          xaxis: {
    35            from: from * 1000,
    36            to: from * 1000,
    37          },
    38        },
    39        {
    40          color: Color('transparent'),
    41          lineWidth: 1,
    42          xaxis: {
    43            from: to * 1000,
    44            to: to * 1000,
    45          },
    46        },
    47      ]);
    48    });
    49  
    50    it('uses color when selection is double', () => {
    51      expect(
    52        markingsFromSelection('double', {
    53          from: `${from}`,
    54          to: `${to}`,
    55          color: color,
    56          overlayColor: color,
    57        })
    58      ).toStrictEqual([
    59        {
    60          color: color,
    61          xaxis: {
    62            from: from * 1000,
    63            to: to * 1000,
    64          },
    65        },
    66        {
    67          color: color,
    68          lineWidth: 1,
    69          xaxis: {
    70            from: from * 1000,
    71            to: from * 1000,
    72          },
    73        },
    74        {
    75          color: color,
    76          lineWidth: 1,
    77          xaxis: {
    78            from: to * 1000,
    79            to: to * 1000,
    80          },
    81        },
    82      ]);
    83    });
    84  });