diff --git a/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.spec.data.ts b/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.spec.data.ts index bda99b91398493eb22cb409361fb393112af4c5e..a7e54eaab91b192b1962f1d13079a27043457c9b 100644 --- a/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.spec.data.ts +++ b/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.spec.data.ts @@ -855,5 +855,55 @@ export const Response = { 'visibility': null, 'compatibilityLevel': null } + ], + formWithoutBoard: [ + { + 'code': 'medium', + 'visible': true, + 'displayProperty': 'Editable', + 'editable': true, + 'dataType': 'text', + 'renderingHints': { + 'semanticColumnWidth': 'four' + }, + 'name': 'Medium', + 'description': 'Mediumofinstruction', + 'index': 1, + 'inputType': 'select', + 'label': 'Medium', + 'required': true + }, + { + 'code': 'gradeLevel', + 'visible': true, + 'displayProperty': 'Editable', + 'editable': true, + 'dataType': 'text', + 'renderingHints': { + 'semanticColumnWidth': 'four' + }, + 'name': 'Class', + 'description': 'Grade', + 'index': 2, + 'inputType': 'select', + 'label': 'Class', + 'required': true + }, + { + 'code': 'subject', + 'visible': true, + 'displayProperty': 'Editable', + 'editable': true, + 'dataType': 'text', + 'renderingHints': { + 'semanticColumnWidth': 'four' + }, + 'name': 'Subject', + 'description': 'SubjectoftheContenttousetoteach', + 'index': 3, + 'inputType': 'select', + 'label': 'Subject', + 'required': false + } ] }; diff --git a/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.spec.ts b/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.spec.ts index c5c8031bdd6cbe7c478854ba951fe7e6832f019e..33353569ba8ff763df36a8a55389b069ce3cc6f0 100644 --- a/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.spec.ts +++ b/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.spec.ts @@ -122,5 +122,44 @@ describe('ProfileFrameworkPopupComponent', () => { expect(component.formFieldOptions[3].range).toBeUndefined(); expect(toasterService.warning).not.toHaveBeenCalled(); }); + + describe('enable/disable submit button based on required fields in form API', () => { + + beforeEach(() => { + component['_formFieldProperties'] = Response.formWithoutBoard; + }); + + it('should enable submit button if board value is not there in framework' , () => { + component.selectedOption = { + gradeLevel: ['Class 2'], + medium: ['English'], + subject: [] + }; + component['enableSubmitButton'](); + expect(component.showButton).toBeTruthy(); + }); + it('should disable submit button if any of board, medium or gradeLevel is not present', () => { + component.selectedOption = { + gradeLevel: ['Class 1'], + medium: ['English'], + subject: ['Hindi'], + board: [] + }; + component['enableSubmitButton'](); + expect(component.showButton).toBeFalsy(); + }); + it('should submit board value in form as null when board value is not present in the framework', () => { + const selectedOptions = { + gradeLevel: ['Class 1'], + medium: ['English'], + subject: ['Hindi'] + }; + component.selectedOption = selectedOptions; + component['frameWorkId'] = 'NCFCOPY2'; + const submitEventEmitter = spyOn(component.submit, 'emit'); + component.onSubmitForm(); + expect(submitEventEmitter).toHaveBeenCalledWith({...selectedOptions, ...{board: null, id: 'NCFCOPY2' }}); + }); + }); }); diff --git a/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.ts b/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.ts index e9a51a9ada6abdd668d09d7f6692f6d56e0f9daa..e05f23f678671ca5e1ba65c3f78170883ec9d5ff 100644 --- a/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.ts +++ b/src/app/client/src/app/modules/shared-feature/components/profile-framework-popup/profile-framework-popup.component.ts @@ -205,13 +205,16 @@ export class ProfileFrameworkPopupComponent implements OnInit, OnDestroy { } onSubmitForm() { const selectedOption = _.cloneDeep(this.selectedOption); - selectedOption.board = [this.selectedOption.board]; + selectedOption.board = _.get(this.selectedOption, 'board') ? [this.selectedOption.board] : null; selectedOption.id = this.frameWorkId; this.submit.emit(selectedOption); } private enableSubmitButton() { - if (_.get(this.selectedOption, 'board.length') && _.get(this.selectedOption, 'medium.length') - && _.get(this.selectedOption, 'gradeLevel.length')) { + const optionalFields = _.map(_.filter(this._formFieldProperties, formField => !_.get(formField, 'required')), 'code'); + const enableSubmitButton = _.every(this.selectedOption, (value, index) => { + return _.includes(optionalFields, index) ? true : value.length; + }); + if (enableSubmitButton) { this.showButton = true; } else { this.showButton = false;