|
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
|
|
|
|