-
Notifications
You must be signed in to change notification settings - Fork 8
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 #212 from formio/FIO-9508
FIO-9508: includeAll flag now works with nested components
- Loading branch information
Showing
5 changed files
with
109 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { eachComponentData } from '../eachComponentData'; | ||
|
||
describe('eachComponentData', function () { | ||
it('Should not iterate over each component in a nested component if includeAll=false and there is no data associated with the component', function () { | ||
const components = [ | ||
{ | ||
type: 'datagrid', | ||
key: 'dataGrid', | ||
label: 'Data Grid', | ||
input: true, | ||
components: [ | ||
{ | ||
key: 'textField', | ||
type: 'textfield', | ||
label: 'Text Field', | ||
input: true, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const data = {}; | ||
|
||
const rowResults: Map<string, any> = new Map(); | ||
eachComponentData( | ||
components, | ||
data, | ||
(component, data, row, path) => { | ||
rowResults.set(path, component.key); | ||
}, | ||
false, | ||
); | ||
expect(rowResults.size).to.equal(1); | ||
expect(rowResults.get('dataGrid')).to.deep.equal('dataGrid'); | ||
}); | ||
|
||
it('Should iterate over each component in a nested component if includeAll=true and there is no data associated with the component', function () { | ||
const components = [ | ||
{ | ||
type: 'datagrid', | ||
key: 'dataGrid', | ||
label: 'Data Grid', | ||
input: true, | ||
components: [ | ||
{ | ||
key: 'textField', | ||
type: 'textfield', | ||
label: 'Text Field', | ||
input: true, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const data = {}; | ||
|
||
const rowResults: Map<string, any> = new Map(); | ||
eachComponentData( | ||
components, | ||
data, | ||
(component, data, row, path) => { | ||
rowResults.set(path, component.key); | ||
}, | ||
true, | ||
); | ||
expect(rowResults.size).to.equal(2); | ||
expect(rowResults.get('dataGrid')).to.deep.equal('dataGrid'); | ||
expect(rowResults.get('dataGrid[0].textField')).to.deep.equal('textField'); | ||
}); | ||
}); |
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