Skip to content

Commit

Permalink
chore: adjust create editor tests
Browse files Browse the repository at this point in the history
Closes #1291
  • Loading branch information
Skaiir committed Oct 14, 2024
1 parent 9ca3465 commit faf25ff
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
54 changes: 31 additions & 23 deletions packages/form-js-editor/test/spec/core/FieldFactory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('core/FieldFactory', function () {
testCreate({
type: 'button',
label: 'Button',
defaults: {
expected: {
action: 'submit',
},
}),
Expand All @@ -34,7 +34,7 @@ describe('core/FieldFactory', function () {
type: 'checklist',
label: 'Checkbox group',
keyed: true,
defaults: {
expected: {
values: [
{
label: 'Value',
Expand All @@ -50,7 +50,7 @@ describe('core/FieldFactory', function () {
testCreate({
type: 'default',
keyed: false,
defaults: {
expected: {
components: [],
},
}),
Expand All @@ -71,7 +71,7 @@ describe('core/FieldFactory', function () {
type: 'radio',
label: 'Radio group',
keyed: true,
defaults: {
expected: {
values: [
{
label: 'Value',
Expand All @@ -88,7 +88,7 @@ describe('core/FieldFactory', function () {
type: 'select',
label: 'Select',
keyed: true,
defaults: {
expected: {
values: [
{
label: 'Value',
Expand All @@ -105,7 +105,7 @@ describe('core/FieldFactory', function () {
type: 'taglist',
label: 'Tag list',
keyed: true,
defaults: {
expected: {
values: [
{
label: 'Value',
Expand All @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions packages/form-js/test/spec/FormEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe('editor exports', function () {
components: [
{
id: 'number',
label: '',
type: 'number',
key: 'number',
},
Expand Down

0 comments on commit faf25ff

Please sign in to comment.