github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/packages/pyroscope-flamegraph/src/fitMode/fitMode.spec.ts (about)

     1  import { fitToCanvasRect } from './fitMode';
     2  
     3  describe('fitToCanvasRect', () => {
     4    describe('HEAD', () => {
     5      it('always returns fullText', () => {
     6        const mode = 'HEAD';
     7        const charSize = 1;
     8        const rectWidth = 10;
     9        const fullText = 'full_long_text';
    10        const shortText = 'short_text';
    11  
    12        expect(
    13          fitToCanvasRect({
    14            mode,
    15            charSize,
    16            rectWidth,
    17            fullText,
    18            shortText,
    19          })
    20        ).toMatchObject({
    21          mode,
    22          text: fullText,
    23          marginLeft: 3,
    24        });
    25      });
    26    });
    27  
    28    describe('TAIL', () => {
    29      const mode = 'TAIL';
    30      it('returns full text if it CAN fit', () => {
    31        const charSize = 1;
    32        const rectWidth = 99;
    33        const fullText = 'full_long_text';
    34        const shortText = 'short_text';
    35  
    36        expect(
    37          fitToCanvasRect({
    38            mode,
    39            charSize,
    40            rectWidth,
    41            fullText,
    42            shortText,
    43          })
    44        ).toMatchObject({
    45          mode,
    46          text: fullText,
    47          marginLeft: 3,
    48        });
    49      });
    50  
    51      it('returns short text with if it CAN fit short text', () => {
    52        const charSize = 1;
    53        const rectWidth = 10;
    54        const fullText = 'full_long_text';
    55        const shortText = 'short_text';
    56  
    57        expect(
    58          fitToCanvasRect({
    59            mode,
    60            charSize,
    61            rectWidth,
    62            fullText,
    63            shortText,
    64          })
    65        ).toMatchObject({
    66          mode,
    67          text: shortText,
    68          marginLeft: 3,
    69        });
    70      });
    71  
    72      it('returns short text with negative margin BOTH short and long CAN NOT fit', () => {
    73        const charSize = 1;
    74        const rectWidth = 10;
    75        const fullText = 'full_long_text'; // 14
    76        const shortText = 'short_text_'; // 11
    77  
    78        expect(
    79          fitToCanvasRect({
    80            mode,
    81            charSize,
    82            rectWidth,
    83            fullText,
    84            shortText,
    85          })
    86        ).toMatchObject({
    87          mode,
    88          text: shortText,
    89          marginLeft: -4,
    90        });
    91      });
    92    });
    93  });