From 7aeca3f54ef5df351ed7a86844f7e53bd55dc3c9 Mon Sep 17 00:00:00 2001 From: Niklas Kiefer Date: Fri, 4 Nov 2022 13:58:12 +0100 Subject: [PATCH] feat(playground): emit `formPlayground.inputDataError` Related to https://github.com/camunda/form-playground/issues/20 --- .../src/components/PlaygroundRoot.js | 6 ++--- .../test/spec/Playground.spec.js | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/form-js-playground/src/components/PlaygroundRoot.js b/packages/form-js-playground/src/components/PlaygroundRoot.js index a997aa258..10f537d71 100644 --- a/packages/form-js-playground/src/components/PlaygroundRoot.js +++ b/packages/form-js-playground/src/components/PlaygroundRoot.js @@ -128,12 +128,12 @@ export function PlaygroundRoot(props) { }); dataEditor.on('changed', event => { - try { setData(JSON.parse(event.value)); - } catch (err) { + } catch (error) { - // TODO(nikku): indicate JSON parse error + // notify interested about input data error + emit('formPlayground.inputDataError', error); } }); diff --git a/packages/form-js-playground/test/spec/Playground.spec.js b/packages/form-js-playground/test/spec/Playground.spec.js index 8a4b464b9..c254354c5 100644 --- a/packages/form-js-playground/test/spec/Playground.spec.js +++ b/packages/form-js-playground/test/spec/Playground.spec.js @@ -545,6 +545,32 @@ describe('playground', function() { expect(spy).to.have.been.called; }); + + it('should emit ', async function() { + + // given + await act(() => { + playground = new Playground({ + container, + schema + }); + }); + + let trackedError; + + playground.on('formPlayground.inputDataError', e => trackedError = e); + + // when + await act(() => { + const dataEditor = playground.getDataEditor(); + dataEditor.emit('changed', { value: 'foo' }); + }); + + // then + expect(trackedError).to.exist; + expect(trackedError.toString()).to.eql('SyntaxError: Unexpected token o in JSON at position 1'); + }); + });