Skip to content

Commit

Permalink
chore: fix field instance tests
Browse files Browse the repository at this point in the history
Related to #1147
  • Loading branch information
Skaiir committed Apr 17, 2024
1 parent 9fa0e4b commit e6e30ee
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 145 deletions.
10 changes: 5 additions & 5 deletions packages/form-js-viewer/test/spec/Form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ describe('Form', function () {

// update programmatically
form._update({
field,
fieldInstance: { id: field.id, valuePath: ['creditor'] },
value: 'Jane Doe Company',
});

Expand Down Expand Up @@ -1182,17 +1182,17 @@ describe('Form', function () {

// update programmatically
form._update({
field: getFormField(form, 'creditor'),
fieldInstance: { id: getFormField(form, 'creditor').id, valuePath: ['creditor'] },
value: 'Jane Doe Company',
});

form._update({
field: getFormField(form, 'amount'),
fieldInstance: { id: getFormField(form, 'amount').id, valuePath: ['amount'] },
value: '123',
});

form._update({
field: getFormField(form, 'approved'),
fieldInstance: { id: getFormField(form, 'approved').id, valuePath: ['approved'] },
value: true,
});

Expand Down Expand Up @@ -1264,7 +1264,7 @@ describe('Form', function () {
const field = getFormField(form, 'creditor');

form._update({
field,
fieldInstance: { id: field.id, valuePath: ['creditor'] },
value: 'Jane Doe Company',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FormField } from 'src/render/components/FormField';

import { Textfield } from 'src/render/components/form-fields/Textfield';

import { UpdateFieldValidationHandler } from 'src/features/viewerCommands/cmd/UpdateFieldValidationHandler';
import { UpdateFieldInstanceValidationHandler } from 'src/features/viewerCommands/cmd/UpdateFieldInstanceValidationHandler';

import { MockFormContext } from './helper';

Expand Down Expand Up @@ -518,10 +518,10 @@ function createFormField(options = {}) {
};

const validatorMock = {
validateField: (field, value) => validationErrors,
validateFieldInstance: (fieldInstance, value) => validationErrors,
};

const updateFieldValidationHandler = new UpdateFieldValidationHandler(formMock, validatorMock);
const updateFieldInstanceValidationHandler = new UpdateFieldInstanceValidationHandler(formMock, validatorMock);

const conditionCheckerMock =
checkCondition !== false
Expand Down Expand Up @@ -567,8 +567,8 @@ function createFormField(options = {}) {
templating: templatingMock,
validator: validatorMock,
viewerCommands: {
updateFieldValidation(field, value) {
return updateFieldValidationHandler.execute({ field, value });
updateFieldInstanceValidation(fieldInstance, value) {
return updateFieldInstanceValidationHandler.execute({ fieldInstance, value });
},
},
pathRegistry: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ describe('Checkbox', function () {
fireEvent.change(input, { target: { checked: false } });

// then
expect(onChangeSpy).to.have.been.calledWith({
field: defaultField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: false,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ describe('Checklist', function () {
fireEvent.click(input);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: defaultField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: ['approver', 'manager'],
});
});
Expand All @@ -269,8 +268,7 @@ describe('Checklist', function () {
fireEvent.click(input, { target: { checked: false } });

// then
expect(onChangeSpy).to.have.been.calledWith({
field: defaultField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: [],
});
});
Expand All @@ -294,8 +292,7 @@ describe('Checklist', function () {
fireEvent.click(input);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dynamicField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: ['dynamicValue1', 'dynamicValue2'],
});
});
Expand All @@ -317,8 +314,7 @@ describe('Checklist', function () {
fireEvent.click(input);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dynamicField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: ['dynamicValue1', 'dynamicValue2'],
});
});
Expand Down Expand Up @@ -346,8 +342,7 @@ describe('Checklist', function () {
fireEvent.click(input);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dynamicField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: [
{
id: 'user3',
Expand Down Expand Up @@ -380,8 +375,7 @@ describe('Checklist', function () {
fireEvent.click(input, { target: { checked: false } });

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dynamicField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: [],
});
});
Expand Down Expand Up @@ -409,8 +403,7 @@ describe('Checklist', function () {
fireEvent.click(input, { target: { checked: false } });

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dynamicField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: [],
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ describe('Datetime', function () {
fireEvent.blur(dateInput);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dateField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: '2000-01-01',
});
});
Expand All @@ -152,8 +151,7 @@ describe('Datetime', function () {
fireEvent.click(firstDayNode);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dateField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: '1996-10-27',
});
});
Expand All @@ -174,8 +172,7 @@ describe('Datetime', function () {
fireEvent.blur(dateInput);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dateField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: null,
});
});
Expand All @@ -202,8 +199,7 @@ describe('Datetime', function () {
fireEvent.click(firstDayNode);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dateField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: '1996-12-01',
});
});
Expand All @@ -228,8 +224,7 @@ describe('Datetime', function () {
fireEvent.click(firstDayNode);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dateField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: '1996-09-29',
});
});
Expand All @@ -254,8 +249,7 @@ describe('Datetime', function () {
fireEvent.click(firstDayNode);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: dateField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: '1995-12-31',
});
});
Expand Down Expand Up @@ -582,8 +576,7 @@ describe('Datetime', function () {
fireEvent.blur(dateInput);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: timeField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: '13:00',
});
});
Expand All @@ -605,8 +598,7 @@ describe('Datetime', function () {
fireEvent.blur(dateInput);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: timeField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: '13:00',
});
});
Expand All @@ -628,8 +620,7 @@ describe('Datetime', function () {
fireEvent.blur(dateInput);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: timeField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: null,
});
});
Expand Down Expand Up @@ -818,8 +809,7 @@ describe('Datetime', function () {
fireEvent.blur(dateInput);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: datetimeField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: '2000-01-01T11:00',
});
});
Expand All @@ -841,8 +831,7 @@ describe('Datetime', function () {
fireEvent.blur(timeInput);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: { ...datetimeField, use24h: true },
expect(onChangeSpy).to.have.been.calledWithMatch({
value: '1996-11-13T12:00',
});
});
Expand All @@ -864,8 +853,7 @@ describe('Datetime', function () {
fireEvent.blur(dateInput);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: datetimeField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: null,
});
});
Expand All @@ -887,8 +875,7 @@ describe('Datetime', function () {
fireEvent.blur(dateInput);

// then
expect(onChangeSpy).to.have.been.calledWith({
field: datetimeField,
expect(onChangeSpy).to.have.been.calledWithMatch({
value: null,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ describe('Dynamic List', () => {

// then
expect(onChangeSpy).to.have.been.calledWithMatch({
field,
value: [
{
creditor: 'John Doe',
Expand Down
Loading

0 comments on commit e6e30ee

Please sign in to comment.