Skip to content

Commit

Permalink
Merge pull request #86 from formio/FIO-8218-add-tests-for-FIO-8210
Browse files Browse the repository at this point in the history
FIO-8218: add tests for FIO-8210
  • Loading branch information
brendanbond authored Apr 19, 2024
2 parents fa7ae08 + 1169f28 commit c934c3f
Showing 1 changed file with 166 additions and 0 deletions.
166 changes: 166 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from "chai";
import { processSync, ProcessTargets } from "../index";
import { ValidationScope } from 'types';
const assert = require('assert');
const form1 = require('./fixtures/form1.json');
const data1a = require('./fixtures/data1a.json');
Expand Down Expand Up @@ -2767,6 +2768,171 @@ describe('Process Tests', () => {
]
});
});

describe('Required component validation in nested form in DataGrid/EditGrid', () => {
const nestedForm = [
{
key: 'form',
type: 'form',
input: true,
components: [
{
key: 'textField',
type: 'textfield',
validate: {
required: true
},
input: true
}
]
},
]

describe('For DataGrid:', () => {
const components = [
{
key: 'dataGrid',
type: 'datagrid',
input: true,
components: nestedForm,
}
];
it('Should validate required component when it is filled out', async () => {
const submission = {
data: {
dataGrid: [
{
form: {
data: {
textField: 'test'
}
}
}
]
}
};

const context = {
form: { components },
submission,
data: submission.data,
components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true
}
};
processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);
expect((context.scope as ValidationScope).errors).to.have.length(0);
});
it('Should not validate required component when it is not filled out', async () => {
const submission = {
data: {
dataGrid: [
{
form: {
data: {
textField: ''
}
}
}
]
}
};

const context = {
form: { components },
submission,
data: submission.data,
components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true
}
};
processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);
expect((context.scope as ValidationScope).errors).to.have.length(1);
});
});
describe('For EditGrid:', () => {
const components = [
{
key: 'editGrid',
type: 'editgrid',
input: true,
components: nestedForm,
}
];
it('Should validate required component when it is filled out', async () => {
const submission = {
data: {
editGrid: [
{
form: {
data: {
textField: 'test'
}
}
}
]
}
};

const context = {
form: { components },
submission,
data: submission.data,
components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true
}
};
processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);
expect((context.scope as ValidationScope).errors).to.have.length(0);
});
it('Should not validate required component when it is not filled out', async () => {
const submission = {
data: {
editGrid: [
{
form: {
data: {
textField: ''
}
}
}
]
}
};

const context = {
form: { components },
submission,
data: submission.data,
components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true
}
};
processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);
expect((context.scope as ValidationScope).errors).to.have.length(1);
});
});
})
/*
it('Should not clearOnHide when set to false', async () => {
var components = [
Expand Down

0 comments on commit c934c3f

Please sign in to comment.