summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/Stats.test.tsx
blob: 27c7d64eacc2cd92d164156f55acea12104ea9a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { render } from 'ink-testing-library';
import { describe, it, expect } from 'vitest';
import {
  StatRow,
  StatsColumn,
  DurationColumn,
  FormattedStats,
} from './Stats.js';
import { Colors } from '../colors.js';

describe('<StatRow />', () => {
  it('renders a label and value', () => {
    const { lastFrame } = render(
      <StatRow label="Test Label" value="Test Value" />,
    );
    expect(lastFrame()).toMatchSnapshot();
  });

  it('renders with a specific value color', () => {
    const { lastFrame } = render(
      <StatRow
        label="Test Label"
        value="Test Value"
        valueColor={Colors.AccentGreen}
      />,
    );
    expect(lastFrame()).toMatchSnapshot();
  });
});

describe('<StatsColumn />', () => {
  const mockStats: FormattedStats = {
    inputTokens: 100,
    outputTokens: 200,
    toolUseTokens: 50,
    thoughtsTokens: 25,
    cachedTokens: 10,
    totalTokens: 385,
  };

  it('renders a stats column with children', () => {
    const { lastFrame } = render(
      <StatsColumn title="Test Stats" stats={mockStats}>
        <StatRow label="Child Prop" value="Child Value" />
      </StatsColumn>,
    );
    expect(lastFrame()).toMatchSnapshot();
  });

  it('renders a stats column with a specific width', () => {
    const { lastFrame } = render(
      <StatsColumn title="Test Stats" stats={mockStats} width="50%" />,
    );
    expect(lastFrame()).toMatchSnapshot();
  });

  it('renders a cumulative stats column with percentages', () => {
    const { lastFrame } = render(
      <StatsColumn title="Cumulative Stats" stats={mockStats} isCumulative />,
    );
    expect(lastFrame()).toMatchSnapshot();
  });

  it('hides the tool use row when there are no tool use tokens', () => {
    const statsWithNoToolUse: FormattedStats = {
      ...mockStats,
      toolUseTokens: 0,
    };
    const { lastFrame } = render(
      <StatsColumn title="Test Stats" stats={statsWithNoToolUse} />,
    );
    expect(lastFrame()).not.toContain('Tool Use Tokens');
  });
});

describe('<DurationColumn />', () => {
  it('renders a duration column', () => {
    const { lastFrame } = render(
      <DurationColumn apiTime="5s" wallTime="10s" />,
    );
    expect(lastFrame()).toMatchSnapshot();
  });
});