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-9649: update componentMatches fn to not omit layout components; add tests #218

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 17 additions & 11 deletions src/process/normalize/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,33 +366,39 @@ describe('Normalize processor', function () {
{
label: 'Agree',
value: 'agree',
tooltip: ''
}
tooltip: '',
},
],
values: [
{
label: 'Yes',
value: 'yes',
tooltip: ''
tooltip: '',
},
{
label: "No",
value: "no",
tooltip: ''
}
label: 'No',
value: 'no',
tooltip: '',
},
],
validateWhenHidden: false,
key: 'survey',
type: 'survey',
input: true
input: true,
};
const context1: ProcessorContext<ProcessorScope> = generateProcessorContext(surveyComponent, {survey: null});
const context1: ProcessorContext<ProcessorScope> = generateProcessorContext(surveyComponent, {
survey: null,
});
normalizeProcessSync(context1);
expect(context1.data).to.deep.equal({});
const context2: ProcessorContext<ProcessorScope> = generateProcessorContext(surveyComponent, {survey: 0});
const context2: ProcessorContext<ProcessorScope> = generateProcessorContext(surveyComponent, {
survey: 0,
});
normalizeProcessSync(context2);
expect(context2.data).to.deep.equal({});
const context3: ProcessorContext<ProcessorScope> = generateProcessorContext(surveyComponent, {survey: ''});
const context3: ProcessorContext<ProcessorScope> = generateProcessorContext(surveyComponent, {
survey: '',
});
normalizeProcessSync(context3);
expect(context3.data).to.deep.equal({});
});
Expand Down
3 changes: 2 additions & 1 deletion src/process/normalize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const isTextFieldComponent = (component: any): component is TextFieldComponent =
const isTimeComponent = (component: any): component is TimeComponent => component.type === 'time';
const isNumberComponent = (component: any): component is NumberComponent =>
component.type === 'number';
const isSurveyComponent = (component: any): component is SurveyComponent => component.type === 'survey';
const isSurveyComponent = (component: any): component is SurveyComponent =>
component.type === 'survey';

const normalizeAddressComponentValue = (component: AddressComponent, value: any) => {
if (!component.multiple && Boolean(component.enableManualMode) && value && !value.mode) {
Expand Down
26 changes: 26 additions & 0 deletions src/utils/__tests__/formUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ describe('formUtil', function () {
expect(component?.key).to.equal(writtenNumber(n));
}
});

it('should get layout components using only their key', function () {
const form = {
display: 'form',
components: [
{
legend: 'Field Set',
key: 'fieldSet',
type: 'fieldset',
input: false,
components: [
{
type: 'panel',
key: 'myPanel',
input: false,
components: [],
},
],
},
],
};
const component = getComponent(form.components, 'myPanel');
expect(component, 'Component should be found');
expect(component!.key).to.equal('myPanel');
expect(component!.type).to.equal('panel');
});
});

describe('flattenComponents', function () {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/formUtil/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export function componentMatches(
}
}
});
if (!matches.key && component.input !== false && component.key === path) {
if (!matches.key && component.key === path) {
matches.key = addMatch('key', { component, paths });
}
}
Expand Down Expand Up @@ -695,7 +695,7 @@ export function matchComponent(component: Component, query: any, paths?: Compone
export function getComponent(
components: Component[],
path: any,
includeAll: any = false,
includeAll: any = true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is evidence (described in the PR description) that we should expect getComponent to include layout components, I've changed this default parameter.

dataIndex?: number, // The preferred last data index of the component to find.
): Component | undefined {
return getComponentFromPath(components, path, undefined, dataIndex, includeAll)?.component;
Expand Down
Loading