diff --git a/src/services/smart-action-form-layout-service.js b/src/services/smart-action-form-layout-service.js index e62b31f7..5658e12f 100644 --- a/src/services/smart-action-form-layout-service.js +++ b/src/services/smart-action-form-layout-service.js @@ -7,8 +7,13 @@ const validLayoutComponents = ['Row', 'Page', 'Separator', 'HtmlBlock']; class SmartActionFormLayoutService { static validateLayoutElement(element) { if (!validLayoutComponents.includes(element.component)) throw new Error(`${element.component} is not a valid component. Valid components are ${validLayoutComponents.join(' or ')}`); - if (element.component === 'Page' && !Array.isArray(element.elements)) { - throw new Error('Page components must contain an array of fields or layout elements in property \'elements\''); + if (element.component === 'Page') { + if (!Array.isArray(element.elements)) { + throw new Error('Page components must contain an array of fields or layout elements in property \'elements\''); + } + if (element.elements.some((innerElement) => innerElement.component === 'Page')) { + throw new Error('Pages cannot contain other pages'); + } } if (element.component === 'Row') { if (!Array.isArray(element.fields)) { diff --git a/test/services/smart-action-form-layout-service.test.js b/test/services/smart-action-form-layout-service.test.js index 5ede32c7..4aeedf47 100644 --- a/test/services/smart-action-form-layout-service.test.js +++ b/test/services/smart-action-form-layout-service.test.js @@ -18,6 +18,9 @@ describe('services > smart-action-form-layout', () => { it('should throw with message when Page does not contain elements', async () => { expect(() => SmartActionFormLayoutService.validateLayoutElement({ component: 'Page' })).toThrow('Page components must contain an array of fields or layout elements in property \'elements\''); }); + it('should throw with message when Page contains pages', async () => { + expect(() => SmartActionFormLayoutService.validateLayoutElement({ component: 'Page', elements: [{ type: 'Layout', component: 'Page', elements: [] }] })).toThrow('Pages cannot contain other pages'); + }); it('should throw with message when Row does not contain fields', async () => { expect(() => SmartActionFormLayoutService.validateLayoutElement({ component: 'Row' })).toThrow('Row components must contain an array of fields in property \'fields\'');