@@ -718,4 +718,181 @@ describe('AssessmentComponent', () => {
718718 document . body . removeChild ( element ) ;
719719 } ) ) ;
720720 } ) ;
721+
722+ describe ( '_compulsoryQuestionsAnswered' , ( ) => {
723+ it ( 'should return empty array when all required questions are answered' , ( ) => {
724+ // Set up mock assessment with required questions
725+ component . assessment = {
726+ id : 1 ,
727+ type : 'default' ,
728+ isForTeam : false ,
729+ groups : [
730+ {
731+ name : 'Group 1' ,
732+ questions : [
733+ {
734+ id : 1 ,
735+ name : 'Question 1' ,
736+ type : 'text' ,
737+ isRequired : true ,
738+ audience : [ 'submitter' ]
739+ } ,
740+ {
741+ id : 2 ,
742+ name : 'Question 2' ,
743+ type : 'multiple' ,
744+ isRequired : true ,
745+ audience : [ 'submitter' ]
746+ }
747+ ]
748+ }
749+ ]
750+ } as any ;
751+
752+ // Set up mock answers
753+ const answers = [
754+ { questionId : 1 , answer : 'Answer to question 1' } ,
755+ { questionId : 2 , answer : [ 'Option 1' , 'Option 2' ] }
756+ ] ;
757+
758+ // Test the function
759+ const missingQuestions = component [ '_compulsoryQuestionsAnswered' ] ( answers ) ;
760+
761+ // Expect no missing questions
762+ expect ( missingQuestions . length ) . toBe ( 0 ) ;
763+ } ) ;
764+
765+ it ( 'should return questions that are required but not answered' , ( ) => {
766+ // Set up mock assessment with required questions
767+ component . assessment = {
768+ id : 1 ,
769+ type : 'default' ,
770+ isForTeam : false ,
771+ groups : [
772+ {
773+ name : 'Group 1' ,
774+ questions : [
775+ {
776+ id : 1 ,
777+ name : 'Question 1' ,
778+ type : 'text' ,
779+ isRequired : true ,
780+ audience : [ 'submitter' ]
781+ } ,
782+ {
783+ id : 2 ,
784+ name : 'Question 2' ,
785+ type : 'text' ,
786+ isRequired : true ,
787+ audience : [ 'submitter' ]
788+ }
789+ ]
790+ }
791+ ]
792+ } as any ;
793+
794+ // Set up mock answers with one missing
795+ const answers = [
796+ { questionId : 1 , answer : 'Answer to question 1' }
797+ // Question 2 is missing
798+ ] ;
799+
800+ // Mock form element
801+ spyOn ( component . form . nativeElement , 'querySelector' ) . and . returnValue ( {
802+ classList : {
803+ add : jasmine . createSpy ( 'add' )
804+ }
805+ } ) ;
806+
807+ // Test the function
808+ const missingQuestions = component [ '_compulsoryQuestionsAnswered' ] ( answers ) ;
809+
810+ // Expect one missing question
811+ expect ( missingQuestions . length ) . toBe ( 1 ) ;
812+ expect ( missingQuestions [ 0 ] . id ) . toBe ( 2 ) ;
813+ expect ( component . form . nativeElement . querySelector ) . toHaveBeenCalledWith ( '#q-2' ) ;
814+ } ) ;
815+
816+ it ( 'should return empty array when either answer or file is provided for required question in review mode' , ( ) => {
817+ // Set action to review
818+ component . action = 'review' ;
819+
820+ // Set up mock assessment with required questions for reviewer
821+ component . assessment = {
822+ id : 1 ,
823+ type : 'default' ,
824+ isForTeam : false ,
825+ groups : [
826+ {
827+ name : 'Group 1' ,
828+ questions : [
829+ {
830+ id : 1 ,
831+ name : 'Question 1' ,
832+ type : 'text' ,
833+ isRequired : true ,
834+ audience : [ 'reviewer' ]
835+ }
836+ ]
837+ }
838+ ]
839+ } as any ;
840+
841+ // Mock answers for review (both answer and file are provided)
842+ const answers = [
843+ { questionId : 1 , answer : 'Some answer' , file : null }
844+ ] ;
845+
846+ // Test the function
847+ const missingQuestions = component [ '_compulsoryQuestionsAnswered' ] ( answers ) ;
848+
849+ // Expect no missing questions
850+ expect ( missingQuestions . length ) . toBe ( 0 ) ;
851+ } ) ;
852+
853+ it ( 'should handle review action properly' , ( ) => {
854+ // Set action to review
855+ component . action = 'review' ;
856+
857+ // Set up mock assessment with required questions for reviewer
858+ component . assessment = {
859+ id : 1 ,
860+ type : 'default' ,
861+ isForTeam : false ,
862+ groups : [
863+ {
864+ name : 'Group 1' ,
865+ questions : [
866+ {
867+ id : 1 ,
868+ name : 'Question 1' ,
869+ type : 'text' ,
870+ isRequired : true ,
871+ audience : [ 'reviewer' ]
872+ }
873+ ]
874+ }
875+ ]
876+ } as any ;
877+
878+ // Mock answers for review (both answer and file are empty)
879+ const answers = [
880+ { questionId : 1 , answer : '' , file : null }
881+ ] ;
882+
883+ // Mock form element
884+ spyOn ( component . form . nativeElement , 'querySelector' ) . and . returnValue ( {
885+ classList : {
886+ add : jasmine . createSpy ( 'add' )
887+ }
888+ } ) ;
889+
890+ // Test the function
891+ const missingQuestions = component [ '_compulsoryQuestionsAnswered' ] ( answers ) ;
892+
893+ // Expect one missing question
894+ expect ( missingQuestions . length ) . toBe ( 1 ) ;
895+ expect ( missingQuestions [ 0 ] . id ) . toBe ( 1 ) ;
896+ } ) ;
897+ } ) ;
721898} ) ;
0 commit comments