Test Failed
Push — master ( 207748...5f3e3e )
by Jesús
03:19
created

test/unit/components/grid.test.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 52
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 37
mnd 1
bc 1
fnc 0
dl 0
loc 52
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import { describe, it, expect, beforeEach, vi } from 'vitest';
2
3
vi.mock('../../../src/components/display', () => ({
4
  updateDisplay: vi.fn(),
5
}));
6
7
vi.mock('../../../src/core/state', () => ({
8
  toggleBox: vi.fn(),
9
}));
10
11
vi.mock('../../../src/core/dom', () => ({
12
  elements: {
13
    grid: {
14
      innerHTML: '',
15
      appendChild: vi.fn(),
16
      querySelectorAll: vi.fn(() => []),
17
    },
18
  },
19
}));
20
21
describe('Grid Component', () => {
22
  beforeEach(() => {
23
    vi.clearAllMocks();
24
  });
25
26
  describe('Grid Logic', () => {
27
    it('should calculate correct bit values for labels', () => {
28
      // Test the bit calculation logic that would be used in createGrid
29
      const expectedValues = [
30
        2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1
31
      ];
32
33
      for (let i = 0; i < 12; i++) {
34
        const bitValue = Math.pow(2, 11 - i);
35
        expect(bitValue).toBe(expectedValues[i]);
36
      }
37
    });
38
39
    it('should create correct number of boxes', () => {
40
      // Test that we would create exactly 12 boxes
41
      const boxCount = 12;
42
      expect(boxCount).toBe(12);
43
    });
44
45
    it('should have correct box indices', () => {
46
      // Test that box indices are 0-11
47
      const indices = Array.from({ length: 12 }, (_, i) => i);
48
      expect(indices).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
49
    });
50
  });
51
});
52