describe('editors', () => { beforeEach(() => { mumuki.CustomEditor.clearSources(); }); it('has initially no sources', () => { expect(mumuki.CustomEditor.hasSources).toBe(false); }); it('can add a custom source', () => { mumuki.editors.addCustomSource({ getContent() { return { name: "solution[content]", value: 'the value' } ; } }); expect(mumuki.CustomEditor.hasSources).toBe(true); expect(mumuki.CustomEditor.getContents()[0].value).toEqual('the value'); expect(mumuki.CustomEditor.getContents()[0].name).toEqual('solution[content]'); }); it('reads the custom sources if present, ignoring the form', () => { $('body').html(`
`); mumuki.editors.addCustomSource({ getContent() { return { name: "solution[content]", value: 'the custom solution' } ; } }); expect(mumuki.editors.getSubmission()).toEqual({"solution[content]":"the custom solution"}); }); it('reads the form if no sources', () => { $('body').html(` `); expect(mumuki.editors.getSubmission()).toEqual({"solution[content]":"the solution"}); }); it('reads the form if no sources and exercise is multifile', () => { $('body').html(` `); expect(mumuki.editors.getSubmission()).toEqual({ "solution[content[index.html]]": "some html", "solution[content[receta.css]]": "some css" }); }); it('produces empty submission if no form nor sources', () => { $('body').html(``); expect(mumuki.editors.getSubmission()).toEqual({}); }); });