Skip to content

Commit f79c508

Browse files
akolsonclaude
andcommitted
test(exercises): assert autofocus prop on open answer/hint editor
Adds tests to AnswersEditor and HintsEditor specs verifying that the editor at the open index receives autofocus=true and all other editors receive autofocus=false. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f8bc773 commit f79c508

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

contentcuration/contentcuration/frontend/channelEdit/components/AnswersEditor/AnswersEditor.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,31 @@ describe('AnswersEditor', () => {
245245
});
246246
});
247247

248+
describe('autofocus on the open answer editor', () => {
249+
beforeEach(() => {
250+
wrapper = mount(AnswersEditor, {
251+
propsData: {
252+
questionKind: AssessmentItemTypes.SINGLE_SELECTION,
253+
answers: [
254+
{ answer: 'Mayonnaise (I mean you can, but...)', correct: true, order: 1 },
255+
{ answer: 'Peanut butter', correct: false, order: 2 },
256+
],
257+
openAnswerIdx: 1,
258+
},
259+
});
260+
});
261+
262+
it('passes autofocus=true to the open answer editor', () => {
263+
const editors = wrapper.findAllComponents({ name: 'RichTextEditor' });
264+
expect(editors.at(1).props('autofocus')).toBe(true);
265+
});
266+
267+
it('passes autofocus=false to closed answer editors', () => {
268+
const editors = wrapper.findAllComponents({ name: 'RichTextEditor' });
269+
expect(editors.at(0).props('autofocus')).toBe(false);
270+
});
271+
});
272+
248273
describe('on an answer click', () => {
249274
beforeEach(async () => {
250275
wrapper = mount(AnswersEditor, {

contentcuration/contentcuration/frontend/channelEdit/components/HintsEditor/HintsEditor.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ describe('HintsEditor', () => {
131131
});
132132
});
133133

134+
describe('autofocus on the open hint editor', () => {
135+
beforeEach(() => {
136+
wrapper = mount(HintsEditor, {
137+
propsData: {
138+
hints: [
139+
{ hint: 'First hint', order: 1 },
140+
{ hint: 'Second hint', order: 2 },
141+
],
142+
openHintIdx: 0,
143+
},
144+
});
145+
});
146+
147+
it('passes autofocus=true to the open hint editor', () => {
148+
const editors = wrapper.findAllComponents({ name: 'RichTextEditor' });
149+
expect(editors.at(0).props('autofocus')).toBe(true);
150+
});
151+
152+
it('passes autofocus=false to closed hint editors', () => {
153+
const editors = wrapper.findAllComponents({ name: 'RichTextEditor' });
154+
expect(editors.at(1).props('autofocus')).toBe(false);
155+
});
156+
});
157+
134158
describe('on hint click', () => {
135159
beforeEach(async () => {
136160
wrapper = mount(HintsEditor, {

0 commit comments

Comments
 (0)