Skip to content

Commit

Permalink
feat: add nodeeditor mergeForm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobernardoaf committed Nov 29, 2024
1 parent 4a9c8ae commit 9b3d1f2
Showing 1 changed file with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions src/store/nodeEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import reducer, {
updateTypeConfig,
updateUserAddingAction,
userAddingAction as userAddingActionReducer,
mergeForm,
} from 'store/nodeEditor';

const definition = require('test/flows/boring.json');
Expand Down Expand Up @@ -68,3 +69,143 @@ describe('nodeEditor reducers', () => {
});
});
});

describe('nodeEditor mergeForm', () => {
it('should merge form data', () => {
const initialFormState: any = {
valid: true,
validationFailures: [],
name: {
value: 'test name',
},
description: {
value: 'test description',
},
array: {
value: [1, 2, 3],
},
object: {
value: { foo: 'bar' },
},
array_object_value: [
{
value: {
uuid: '1234',
name: 'baz',
},
},
],
array_object_uuid: [
{
uuid: '1234',
name: 'not baz',
},
],
string_array__invalid: ['first'],
};

const updates: any = {
valid: true,
validationFailures: [],
name: {
value: 'updated name',
validationFailures: [{ message: 'invalid' }],
},
array: {
value: [4, 5, 6],
},
object: {
value: { baz: 'qux' },
},
array_object_value: [
{
value: {
uuid: '1234',
name: 'baq',
},
validationFailures: [{ message: 'invalid' }],
},
],
array_object_uuid: [
{
uuid: '1234',
name: 'not baq',
},
],
string_array__invalid: ['first', 'second'],
};

let updated = mergeForm(initialFormState, updates, ['description']);

expect(updated).toEqual({
valid: false,
validationFailures: [],
name: {
value: 'updated name',
validationFailures: [{ message: 'invalid' }],
},
array: {
value: [4, 5, 6],
},
object: {
value: { baz: 'qux' },
},
array_object_value: [
{
value: {
uuid: '1234',
name: 'baq',
},
validationFailures: [{ message: 'invalid' }],
},
],
array_object_uuid: [
{
uuid: '1234',
name: 'not baq',
},
],
string_array__invalid: ['first'], // not a valid entry for merge form, so it should not be updated
});

updated = mergeForm(updated, {}, [
{
array_object_uuid: [
{
uuid: '1234',
},
],
},
{
array_object_value: [
{
value: {
uuid: '1234',
},
},
],
},
{
string_array__invalid: 'invalid',
},
]);

expect(updated).toEqual({
valid: false,
validationFailures: [],
name: {
value: 'updated name',
validationFailures: [{ message: 'invalid' }],
},
array: {
value: [4, 5, 6],
},
object: {
value: { baz: 'qux' },
},
array_object_value: [],
array_object_uuid: [],
string_array__invalid: ['first'],
});
});
});

0 comments on commit 9b3d1f2

Please sign in to comment.