From c185b564234b109747ab1f99dbe47413223b9c05 Mon Sep 17 00:00:00 2001 From: Skaiir Date: Thu, 10 Oct 2024 12:41:14 +0200 Subject: [PATCH] chore: adjust create editor tests Closes #1291 --- .../test/spec/core/FieldFactory.spec.js | 54 +++++++++++-------- .../components/form-fields/EditorText.spec.js | 2 +- packages/form-js/test/spec/FormEditor.spec.js | 1 + 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/packages/form-js-editor/test/spec/core/FieldFactory.spec.js b/packages/form-js-editor/test/spec/core/FieldFactory.spec.js index e658e90e4..13acf42f9 100644 --- a/packages/form-js-editor/test/spec/core/FieldFactory.spec.js +++ b/packages/form-js-editor/test/spec/core/FieldFactory.spec.js @@ -13,7 +13,7 @@ describe('core/FieldFactory', function () { testCreate({ type: 'button', label: 'Button', - defaults: { + expected: { action: 'submit', }, }), @@ -34,7 +34,7 @@ describe('core/FieldFactory', function () { type: 'checklist', label: 'Checkbox group', keyed: true, - defaults: { + expected: { values: [ { label: 'Value', @@ -50,7 +50,7 @@ describe('core/FieldFactory', function () { testCreate({ type: 'default', keyed: false, - defaults: { + expected: { components: [], }, }), @@ -71,7 +71,7 @@ describe('core/FieldFactory', function () { type: 'radio', label: 'Radio group', keyed: true, - defaults: { + expected: { values: [ { label: 'Value', @@ -88,7 +88,7 @@ describe('core/FieldFactory', function () { type: 'select', label: 'Select', keyed: true, - defaults: { + expected: { values: [ { label: 'Value', @@ -105,7 +105,7 @@ describe('core/FieldFactory', function () { type: 'taglist', label: 'Tag list', keyed: true, - defaults: { + expected: { values: [ { label: 'Value', @@ -118,14 +118,17 @@ describe('core/FieldFactory', function () { it( 'Date time', - testCreate({ - type: 'datetime', - keyed: true, - defaults: { - subtype: 'date', - dateLabel: 'Date', + testCreate( + { + type: 'datetime', + keyed: true, + expected: { + subtype: 'date', + dateLabel: 'Date', + }, }, - }), + true, + ), ); it( @@ -141,19 +144,24 @@ describe('core/FieldFactory', function () { 'Image view', testCreate({ type: 'image', - label: 'Image view', }), ); }); - describe('#create (no defaults)', function () { + describe('#create (from import)', function () { it( - 'Button', + 'Datetime', testCreate( { - type: 'button', - defaults: { - action: 'submit', + type: 'datetime', + keyed: true, + initial: { + subtype: 'time', + timeLabel: 'Time', + }, + expected: { + subtype: 'time', + timeLabel: 'Time', }, }, false, @@ -302,12 +310,12 @@ describe('core/FieldFactory', function () { // helpers ////////////// -function testCreate(options, applyDefaults = true) { - const { type, label, keyed = false, defaults = {} } = options; +function testCreate(options, isNew = true) { + const { type, label, keyed = false, initial = {}, expected = {} } = options; return inject(function (fieldFactory) { // when - const field = fieldFactory.create({ type }, applyDefaults); + const field = fieldFactory.create({ type, ...initial }, isNew); // then expect(field.id).to.exist; @@ -326,6 +334,6 @@ function testCreate(options, applyDefaults = true) { expect(field.label).not.to.exist; } - expect(field).to.deep.contain(defaults); + expect(field).to.deep.contain(expected); }); } diff --git a/packages/form-js-editor/test/spec/render/components/form-fields/EditorText.spec.js b/packages/form-js-editor/test/spec/render/components/form-fields/EditorText.spec.js index c18ef6ee3..85a36a3b3 100644 --- a/packages/form-js-editor/test/spec/render/components/form-fields/EditorText.spec.js +++ b/packages/form-js-editor/test/spec/render/components/form-fields/EditorText.spec.js @@ -105,7 +105,7 @@ describe('Text', function () { // assume const { config } = EditorText; expect(config.type).to.eql('text'); - expect(config.label).to.eql('Text view'); + expect(config.name).to.eql('Text view'); expect(config.group).to.eql('presentation'); expect(config.keyed).to.be.false; diff --git a/packages/form-js/test/spec/FormEditor.spec.js b/packages/form-js/test/spec/FormEditor.spec.js index 99ef5876f..202f85ad4 100644 --- a/packages/form-js/test/spec/FormEditor.spec.js +++ b/packages/form-js/test/spec/FormEditor.spec.js @@ -94,6 +94,7 @@ describe('editor exports', function () { components: [ { id: 'number', + label: '', type: 'number', key: 'number', },