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 = `
`;
const json = readConfigFromForm('value_spinner', 'pfx');
expect(JSON.parse(json)).toEqual({ range: { min: 1, max: 10 } });
});
});