This commit is contained in:
39
website/tests/unit/editor-utils.test.js
Normal file
39
website/tests/unit/editor-utils.test.js
Normal file
@ -0,0 +1,39 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import {
|
||||
parseConfig,
|
||||
questionLocalIds,
|
||||
layoutLabel,
|
||||
readConfigFromForm,
|
||||
} from '../../js/editor-utils.js';
|
||||
|
||||
describe('editor-utils', () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
it('parseConfig parses JSON', () => {
|
||||
expect(parseConfig({ configJson: '{"textKey":"a"}' })).toEqual({ textKey: 'a' });
|
||||
expect(parseConfig({ configJson: 'not-json' })).toEqual({});
|
||||
});
|
||||
|
||||
it('questionLocalIds extracts short ids', () => {
|
||||
const ids = questionLocalIds([
|
||||
{ questionID: 'qn__q1', defaultText: 'Q1' },
|
||||
{ questionID: 'qn__q2', defaultText: 'Q2' },
|
||||
]);
|
||||
expect(ids.map(i => i.localId)).toEqual(['q1', 'q2']);
|
||||
});
|
||||
|
||||
it('layoutLabel resolves known layouts', () => {
|
||||
expect(layoutLabel('radio_question')).toContain('Radio');
|
||||
});
|
||||
|
||||
it('readConfigFromForm round-trips value_spinner', () => {
|
||||
document.body.innerHTML = `
|
||||
<input id="pfx_rangeMin" value="1" />
|
||||
<input id="pfx_rangeMax" value="10" />
|
||||
`;
|
||||
const json = readConfigFromForm('value_spinner', 'pfx');
|
||||
expect(JSON.parse(json)).toEqual({ range: { min: 1, max: 10 } });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user