@@ -6,16 +6,34 @@ import {
66 CREATE_QUESTION_SELECT_TYPE_CY ,
77 CREATE_QUESTION_TITLE_CY ,
88 CREATE_VIEW_DELETE_BUTTON_CY ,
9+ QUESTION_BAR_ADD_NEW_BUTTON_CLASSNAME ,
10+ QUESTION_STEP_CLASSNAME ,
911 QUESTION_BAR_CY ,
1012 QUESTION_BAR_NEXT_CY ,
1113 QUESTION_BAR_PREV_CY ,
1214 buildQuestionStepCy ,
1315 dataCyWrapper ,
1416} from '../../../../src/config/selectors' ;
1517import { APP_SETTINGS } from '../../../fixtures/appSettings' ;
18+ import { fillMultipleChoiceQuestion } from './multipleChoices.cy' ;
19+
20+ const newMultipleChoiceData = {
21+ question : 'new question text' ,
22+ choices : [
23+ {
24+ value : 'new choice 1' ,
25+ isCorrect : true ,
26+ } ,
27+ {
28+ value : 'new choice 2' ,
29+ isCorrect : true ,
30+ } ,
31+ ] ,
32+ explanation : 'my new explanation' ,
33+ } ;
1634
1735describe ( 'Create View' , ( ) => {
18- it ( 'Empty data' , ( ) => {
36+ beforeEach ( ( ) => {
1937 cy . setUpApi ( {
2038 database : {
2139 appSettings : [ ] ,
@@ -26,6 +44,9 @@ describe('Create View', () => {
2644 } ,
2745 } ) ;
2846 cy . visit ( '/' ) ;
47+ } ) ;
48+
49+ it ( 'Empty data' , ( ) => {
2950 cy . get ( dataCyWrapper ( ADD_NEW_QUESTION_TITLE_CY ) ) . should ( 'be.visible' ) ;
3051 cy . get ( dataCyWrapper ( CREATE_QUESTION_TITLE_CY ) )
3152 . should ( 'be.visible' )
@@ -39,6 +60,28 @@ describe('Create View', () => {
3960 cy . get ( dataCyWrapper ( QUESTION_BAR_PREV_CY ) ) . should ( 'be.disabled' ) ;
4061 } ) ;
4162
63+ it ( 'Add questions from empty quiz' , ( ) => {
64+ // Add three questions and make sure they are added to the QuestionTopBar
65+ cy . get ( dataCyWrapper ( ADD_NEW_QUESTION_TITLE_CY ) ) . should ( 'be.visible' ) ;
66+ fillMultipleChoiceQuestion ( newMultipleChoiceData ) ;
67+ cy . wait ( 2000 ) ; // Wait for the new question to appear
68+ cy . get ( `.${ QUESTION_BAR_ADD_NEW_BUTTON_CLASSNAME } ` ) . click ( ) ;
69+ cy . get ( dataCyWrapper ( CREATE_QUESTION_TITLE_CY ) )
70+ . should ( 'be.visible' )
71+ . should ( 'have.value' , '' ) ;
72+ fillMultipleChoiceQuestion ( newMultipleChoiceData ) ;
73+ cy . wait ( 2000 ) ;
74+ cy . get ( `.${ QUESTION_BAR_ADD_NEW_BUTTON_CLASSNAME } ` ) . click ( ) ;
75+ cy . get ( dataCyWrapper ( CREATE_QUESTION_TITLE_CY ) )
76+ . should ( 'be.visible' )
77+ . should ( 'have.value' , '' ) ;
78+ fillMultipleChoiceQuestion ( newMultipleChoiceData ) ;
79+ // Verify the questions are added to the order list by checking the number of
80+ // question nodes in the QuestionTopBar, as we cannot check the app settings directly
81+ cy . get ( 'html' ) . find ( `.${ QUESTION_STEP_CLASSNAME } ` ) . should ( 'have.length' , 3 ) ;
82+ } ) ;
83+
84+
4285 describe ( 'Create View' , ( ) => {
4386 beforeEach ( ( ) => {
4487 cy . setUpApi ( {
@@ -107,5 +150,25 @@ describe('Create View', () => {
107150 cy . get ( dataCyWrapper ( CREATE_VIEW_DELETE_BUTTON_CY ) ) . should ( 'be.disabled' ) ;
108151 cy . get ( dataCyWrapper ( ADD_NEW_QUESTION_TITLE_CY ) ) . should ( 'be.visible' ) ;
109152 } ) ;
153+
154+ it ( 'Add question from existing quiz' , ( ) => {
155+ const currentQuestion = APP_SETTINGS [ 1 ] ;
156+ cy . get ( dataCyWrapper ( buildQuestionStepCy ( currentQuestion . id ) ) ) . click ( ) ;
157+ // click new question and come back
158+ cy . get ( `.${ QUESTION_BAR_ADD_NEW_BUTTON_CLASSNAME } ` ) . click ( ) ;
159+
160+ // New question title should be visible
161+ cy . get ( dataCyWrapper ( ADD_NEW_QUESTION_TITLE_CY ) ) . should ( 'be.visible' ) ;
162+ cy . get ( dataCyWrapper ( CREATE_QUESTION_TITLE_CY ) )
163+ . should ( 'be.visible' )
164+ . should ( 'have.value' , '' ) ;
165+ cy . get ( `${ dataCyWrapper ( CREATE_QUESTION_SELECT_TYPE_CY ) } input` ) . should (
166+ 'have.value' ,
167+ DEFAULT_QUESTION_TYPE
168+ ) ;
169+ cy . get ( dataCyWrapper ( QUESTION_BAR_CY ) ) . should ( 'be.visible' ) ;
170+ fillMultipleChoiceQuestion ( newMultipleChoiceData ) ;
171+ cy . get ( 'html' ) . find ( `.${ QUESTION_STEP_CLASSNAME } ` ) . should ( 'have.length' , 5 ) ;
172+ } ) ;
110173 } ) ;
111174} ) ;
0 commit comments