File size: 2,193 Bytes
9332ccf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { render } from '../../test-utils/render.js';
import { describe, it, expect } from 'vitest';
import { Checklist } from './Checklist.js';
import type { ChecklistItemData } from './ChecklistItem.js';

describe('<Checklist />', () => {
  const items: ChecklistItemData[] = [
    { status: 'completed', label: 'Task 1' },
    { status: 'in_progress', label: 'Task 2' },
    { status: 'pending', label: 'Task 3' },
    { status: 'cancelled', label: 'Task 4' },
  ];

  it('renders nothing when list is empty', async () => {
    const { lastFrame } = await render(
      <Checklist title="Test List" items={[]} isExpanded={true} />,
    );
    expect(lastFrame({ allowEmpty: true })).toBe('');
  });

  it('renders nothing when collapsed and no active items', async () => {
    const inactiveItems: ChecklistItemData[] = [
      { status: 'completed', label: 'Task 1' },
      { status: 'cancelled', label: 'Task 2' },
    ];
    const { lastFrame } = await render(
      <Checklist title="Test List" items={inactiveItems} isExpanded={false} />,
    );
    expect(lastFrame({ allowEmpty: true })).toBe('');
  });

  it('renders summary view correctly (collapsed)', async () => {
    const { lastFrame } = await render(
      <Checklist
        title="Test List"
        items={items}
        isExpanded={false}
        toggleHint="toggle me"
      />,
    );
    expect(lastFrame()).toMatchSnapshot();
  });

  it('renders expanded view correctly', async () => {
    const { lastFrame } = await render(
      <Checklist
        title="Test List"
        items={items}
        isExpanded={true}
        toggleHint="toggle me"
      />,
    );
    expect(lastFrame()).toMatchSnapshot();
  });

  it('renders summary view without in-progress item if none exists', async () => {
    const pendingItems: ChecklistItemData[] = [
      { status: 'completed', label: 'Task 1' },
      { status: 'pending', label: 'Task 2' },
    ];
    const { lastFrame } = await render(
      <Checklist title="Test List" items={pendingItems} isExpanded={false} />,
    );
    expect(lastFrame()).toMatchSnapshot();
  });
});