Skip to content

Commit bb3eb00

Browse files
committed
claude refactoring
1 parent 79c3020 commit bb3eb00

20 files changed

+2587
-1
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/**
2+
* Unit tests for focus-helpers.ts
3+
* Testing focus utility functions
4+
*/
5+
6+
import { describe, it, expect } from 'bun:test'
7+
import {
8+
isFocusEqual,
9+
isFocusOnQuestion,
10+
isFocusOnSpecificOption,
11+
isFocusOnSpecificTextInput,
12+
focusToString,
13+
} from '../utils/focus-helpers'
14+
import {
15+
createOptionFocus,
16+
createTextInputFocus,
17+
createSkipFocus,
18+
} from '../types'
19+
20+
describe('isFocusEqual', () => {
21+
it('returns true for identical skip focus', () => {
22+
const a = createSkipFocus()
23+
const b = createSkipFocus()
24+
expect(isFocusEqual(a, b)).toBe(true)
25+
})
26+
27+
it('returns true for identical text input focus', () => {
28+
const a = createTextInputFocus(2)
29+
const b = createTextInputFocus(2)
30+
expect(isFocusEqual(a, b)).toBe(true)
31+
})
32+
33+
it('returns false for text input with different question index', () => {
34+
const a = createTextInputFocus(0)
35+
const b = createTextInputFocus(1)
36+
expect(isFocusEqual(a, b)).toBe(false)
37+
})
38+
39+
it('returns true for identical option focus', () => {
40+
const a = createOptionFocus(1, 2)
41+
const b = createOptionFocus(1, 2)
42+
expect(isFocusEqual(a, b)).toBe(true)
43+
})
44+
45+
it('returns false for option with different question index', () => {
46+
const a = createOptionFocus(0, 1)
47+
const b = createOptionFocus(1, 1)
48+
expect(isFocusEqual(a, b)).toBe(false)
49+
})
50+
51+
it('returns false for option with different option index', () => {
52+
const a = createOptionFocus(1, 0)
53+
const b = createOptionFocus(1, 1)
54+
expect(isFocusEqual(a, b)).toBe(false)
55+
})
56+
57+
it('returns false for different focus types', () => {
58+
const option = createOptionFocus(0, 0)
59+
const textInput = createTextInputFocus(0)
60+
const skip = createSkipFocus()
61+
62+
expect(isFocusEqual(option, textInput)).toBe(false)
63+
expect(isFocusEqual(option, skip)).toBe(false)
64+
expect(isFocusEqual(textInput, skip)).toBe(false)
65+
})
66+
})
67+
68+
describe('isFocusOnQuestion', () => {
69+
it('returns true for option focus on specified question', () => {
70+
const focus = createOptionFocus(2, 1)
71+
expect(isFocusOnQuestion(focus, 2)).toBe(true)
72+
})
73+
74+
it('returns false for option focus on different question', () => {
75+
const focus = createOptionFocus(2, 1)
76+
expect(isFocusOnQuestion(focus, 1)).toBe(false)
77+
})
78+
79+
it('returns true for text input focus on specified question', () => {
80+
const focus = createTextInputFocus(3)
81+
expect(isFocusOnQuestion(focus, 3)).toBe(true)
82+
})
83+
84+
it('returns false for text input focus on different question', () => {
85+
const focus = createTextInputFocus(3)
86+
expect(isFocusOnQuestion(focus, 2)).toBe(false)
87+
})
88+
89+
it('returns false for skip focus (not on any question)', () => {
90+
const focus = createSkipFocus()
91+
expect(isFocusOnQuestion(focus, 0)).toBe(false)
92+
expect(isFocusOnQuestion(focus, 5)).toBe(false)
93+
})
94+
})
95+
96+
describe('isFocusOnSpecificOption', () => {
97+
it('returns true for exact match', () => {
98+
const focus = createOptionFocus(1, 2)
99+
expect(isFocusOnSpecificOption(focus, 1, 2)).toBe(true)
100+
})
101+
102+
it('returns false for different question index', () => {
103+
const focus = createOptionFocus(1, 2)
104+
expect(isFocusOnSpecificOption(focus, 0, 2)).toBe(false)
105+
})
106+
107+
it('returns false for different option index', () => {
108+
const focus = createOptionFocus(1, 2)
109+
expect(isFocusOnSpecificOption(focus, 1, 1)).toBe(false)
110+
})
111+
112+
it('returns false for text input focus', () => {
113+
const focus = createTextInputFocus(1)
114+
expect(isFocusOnSpecificOption(focus, 1, 0)).toBe(false)
115+
})
116+
117+
it('returns false for skip focus', () => {
118+
const focus = createSkipFocus()
119+
expect(isFocusOnSpecificOption(focus, 0, 0)).toBe(false)
120+
})
121+
})
122+
123+
describe('isFocusOnSpecificTextInput', () => {
124+
it('returns true for exact match', () => {
125+
const focus = createTextInputFocus(3)
126+
expect(isFocusOnSpecificTextInput(focus, 3)).toBe(true)
127+
})
128+
129+
it('returns false for different question index', () => {
130+
const focus = createTextInputFocus(3)
131+
expect(isFocusOnSpecificTextInput(focus, 2)).toBe(false)
132+
})
133+
134+
it('returns false for option focus', () => {
135+
const focus = createOptionFocus(3, 0)
136+
expect(isFocusOnSpecificTextInput(focus, 3)).toBe(false)
137+
})
138+
139+
it('returns false for skip focus', () => {
140+
const focus = createSkipFocus()
141+
expect(isFocusOnSpecificTextInput(focus, 0)).toBe(false)
142+
})
143+
})
144+
145+
describe('focusToString', () => {
146+
it('formats skip focus', () => {
147+
const focus = createSkipFocus()
148+
expect(focusToString(focus)).toBe('skip')
149+
})
150+
151+
it('formats text input focus', () => {
152+
const focus = createTextInputFocus(2)
153+
expect(focusToString(focus)).toBe('textInput:Q2')
154+
})
155+
156+
it('formats option focus', () => {
157+
const focus = createOptionFocus(1, 3)
158+
expect(focusToString(focus)).toBe('option:Q1:O3')
159+
})
160+
161+
it('formats various question and option indices', () => {
162+
expect(focusToString(createOptionFocus(0, 0))).toBe('option:Q0:O0')
163+
expect(focusToString(createOptionFocus(5, 2))).toBe('option:Q5:O2')
164+
expect(focusToString(createTextInputFocus(0))).toBe('textInput:Q0')
165+
expect(focusToString(createTextInputFocus(10))).toBe('textInput:Q10')
166+
})
167+
})

0 commit comments

Comments
 (0)