-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from formio/FIO-8778
FIO-8778: add case for map component model type in filter; add tests
- Loading branch information
Showing
5 changed files
with
177 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
|
@@ -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' }); | ||
}); | ||
|
@@ -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: {} }); | ||
}); | ||
|
@@ -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]' }); | ||
}); | ||
|
@@ -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 }); | ||
}); | ||
|
@@ -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 }); | ||
}); | ||
|
@@ -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 }); | ||
}); | ||
|
@@ -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' }); | ||
}); | ||
|
@@ -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 }); | ||
}); | ||
|
@@ -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 }); | ||
}); | ||
|
@@ -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 }); | ||
}); | ||
|
@@ -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' }), | ||
|
@@ -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 }); | ||
}); | ||
|
@@ -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] }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters