Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-8778: add case for map component model type in filter; add tests #129

Merged
merged 6 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/process/__tests__/fixtures/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { get } from 'lodash';
import { ProcessorContext, ProcessorScope, Component } from 'types';
export const generateProcessorContext = (component: Component, data: any): ProcessorContext<ProcessorScope> => {
import { ProcessorContext, Component } from 'types';
export const generateProcessorContext = <ProcessorScope>(component: Component, data: any): ProcessorContext<ProcessorScope> => {
return {
component,
path: component.key,
Expand Down
52 changes: 52 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2780,6 +2780,57 @@ describe('Process Tests', () => {
});
});

it('Should not filter a simple datamap compoennt', async () => {
const form = {
display: 'form',
components: [
{
label: "Data Map",
tableView: false,
validateWhenHidden: false,
key: "dataMap",
type: "datamap",
path: "dataMap",
input: true,
valueComponent: {
type: "textfield",
key: "value",
label: "Value",
input: true,
hideLabel: true,
tableView: true,
},
}
]
};
const submission = {
data: {
dataMap: {
key1: "value1",
key2: "value2"
}
}
};
const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.evaluator,
scope: {},
config: {
server: true,
},
};
processSync(context);
expect(context.data).to.deep.equal({
dataMap: {
key1: "value1",
key2: "value2"
}
});
})

describe('Required component validation in nested form in DataGrid/EditGrid', () => {
const nestedForm = {
key: 'form',
Expand Down Expand Up @@ -3147,6 +3198,7 @@ describe('Process Tests', () => {

});
});

/*
it('Should not clearOnHide when set to false', async () => {
var components = [
Expand Down
169 changes: 106 additions & 63 deletions src/process/filter/__tests__/filter.test.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,116 @@
import { expect } from 'chai';
import { expect } from "chai";

import { filterProcessSync } from '../';
import { generateProcessorContext } from '../../__tests__/fixtures/util';
import { filterProcessSync } from "../";
import { generateProcessorContext } from "../../__tests__/fixtures/util";
import { FilterScope, ProcessorContext } from "types";

it('Should not filter empty array value for dataGrid component', async () => {
const dataGridComp = {
type: 'datagrid',
key: 'dataGrid',
it("Should not filter empty array value for dataGrid component", async () => {
const dataGridComp = {
type: "datagrid",
key: "dataGrid",
input: true,
path: "dataGrid",
components: [
{
type: "textfield",
key: "textField",
input: true,
path: 'dataGrid',
components: [
{
type: 'textfield',
key: 'textField',
input: true,
label: 'Text Field'
}
]
};
const data = {
dataGrid: []
};
const context: any = generateProcessorContext(dataGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataGrid': {'compModelType': 'array', 'include': true, value: []}});
label: "Text Field",
},
],
};
const data = {
dataGrid: [],
};
const context: any = generateProcessorContext(dataGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({
dataGrid: { compModelType: "array", include: true, value: [] },
});
});

it('Should not filter empty array value for editGrid component', async () => {
const editGridComp = {
type: 'editgrid',
key: 'editGrid',
it("Should not filter empty array value for editGrid component", async () => {
const editGridComp = {
type: "editgrid",
key: "editGrid",
input: true,
path: "editGrid",
components: [
{
type: "textfield",
key: "textField",
input: true,
path: 'editGrid',
components: [
{
type: 'textfield',
key: 'textField',
input: true,
label: 'Text Field'
}
]
};
const data = {
editGrid: []
};
const context: any = generateProcessorContext(editGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'editGrid': {'compModelType': 'array', 'include': true, value: []}});
label: "Text Field",
},
],
};
const data = {
editGrid: [],
};
const context: any = generateProcessorContext(editGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({
editGrid: { compModelType: "array", include: true, value: [] },
});
});

it('Should not filter empty array value for datTable component', async () => {
const dataTableComp = {
type: 'datatable',
key: 'dataTable',
it("Should not filter empty array value for dataTable component", async () => {
const dataTableComp = {
type: "datatable",
key: "dataTable",
input: true,
path: "dataTable",
components: [
{
type: "textfield",
key: "textField",
input: true,
path: 'dataTable',
components: [
{
type: 'textfield',
key: 'textField',
input: true,
label: 'Text Field'
}
]
};
const data = {
dataTable: []
};
const context: any = generateProcessorContext(dataTableComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataTable': {'compModelType': 'array', 'include': true, value: []}});
label: "Text Field",
},
],
};
const data = {
dataTable: [],
};
const context: any = generateProcessorContext(dataTableComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({
dataTable: { compModelType: "array", include: true, value: [] },
});
});

it("Should not filter the datamap component", async () => {
const dataMapComp = {
label: "Data Map",
tableView: false,
validateWhenHidden: false,
key: "dataMap",
type: "datamap",
path: "dataMap",
input: true,
valueComponent: {
type: "textfield",
key: "value",
label: "Value",
input: true,
hideLabel: true,
tableView: true,
},
};

const data = {
dataMap: {
foo: "bar",
baz: "biz"
},
};

const context: ProcessorContext<FilterScope> = generateProcessorContext(dataMapComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({
dataMap: {
compModelType: "map",
include: true,
}
});
});
28 changes: 14 additions & 14 deletions src/process/normalize/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';

import { TimeComponent, SelectBoxesComponent } from 'types';
import { TimeComponent, SelectBoxesComponent, ProcessorContext, ProcessorScope } from 'types';
import { normalizeProcessSync } from '../';
import { generateProcessorContext } from '../../__tests__/fixtures/util';

Expand All @@ -13,7 +13,7 @@ it('Should normalize a time component with a valid time value that doees not mat
dataFormat: 'HH:mm:ss',
};
const data = { time: '12:00' };
const context = generateProcessorContext(timeComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(timeComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ time: '12:00:00' });
});
Expand All @@ -33,7 +33,7 @@ it('Should normalize a select boxes component with an incorrect data model', ()
const data = {
selectBoxes: '',
};
const context = generateProcessorContext(selectBoxesComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(selectBoxesComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ selectBoxes: {} });
});
Expand All @@ -48,7 +48,7 @@ it('Should normalize an email component value', () => {
const data = {
email: '[email protected]',
};
const context = generateProcessorContext(emailComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(emailComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ email: '[email protected]' });
});
Expand All @@ -73,7 +73,7 @@ it('Should normalize a radio component with a string value', () => {
const data = {
radio: 'true',
};
const context = generateProcessorContext(radioComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(radioComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ radio: true });
});
Expand All @@ -97,7 +97,7 @@ it('Should normalize a radio component with a string value of false', () => {
const data = {
radio: 'false',
};
const context = generateProcessorContext(radioComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(radioComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ radio: false });
});
Expand All @@ -122,7 +122,7 @@ it('Should normalize a radio component value with a number', () => {
const data = {
radio: '0',
};
const context = generateProcessorContext(radioComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(radioComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ radio: 0 });
});
Expand All @@ -148,7 +148,7 @@ it('Should normalize a radio component value with a string if storage type is se
const data = {
radio: 0,
};
const context = generateProcessorContext(radioComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(radioComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ radio: '0' });
});
Expand All @@ -173,7 +173,7 @@ it('Should normalize a radio component value with a number if storage type is se
const data = {
radio: 1,
};
const context = generateProcessorContext(radioComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(radioComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ radio: 1 });
});
Expand All @@ -198,7 +198,7 @@ it('Should normalize a radio component value with a boolean if storage type is s
const data = {
radio: true,
};
const context = generateProcessorContext(radioComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(radioComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ radio: true });
});
Expand All @@ -223,7 +223,7 @@ it('Should normalize a radio component value with a false boolean if storage typ
const data = {
radio: 'false',
};
const context = generateProcessorContext(radioComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(radioComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ radio: false });
});
Expand All @@ -249,7 +249,7 @@ it('Should normalize a radio component value with an object if storage type is
const data = {
radio: { test: 'test' },
};
const context = generateProcessorContext(radioComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(radioComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({
radio: JSON.stringify({ test: 'test' }),
Expand All @@ -266,7 +266,7 @@ it('Should normalize a number component value with a string value', () => {
const data = {
number: '000123',
};
const context = generateProcessorContext(numberComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(numberComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ number: 123 });
});
Expand All @@ -282,7 +282,7 @@ it('Should normalize a number component value with a multiple values allowed', (
const data = {
number: ['000.0123', '123'],
};
const context = generateProcessorContext(numberComp, data);
const context: ProcessorContext<ProcessorScope> = generateProcessorContext(numberComp, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({ number: [0.0123, 123] });
});
3 changes: 3 additions & 0 deletions src/utils/formUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ export function getModelType(component: Component) {
if (isComponentModelType(component, 'array')) {
return 'array';
}
if (isComponentModelType(component, 'map')) {
return 'map';
}
return 'object';
}
if ((component.input === false) || isComponentModelType(component, 'layout')) {
Expand Down
Loading