@@ -5,7 +5,10 @@ import FlowForm from '@/src/components/FlowForm.vue'
55import FlowFormQuestion from '@/src/components/Question.vue'
66import FlowFormMultipleChoiceType from '@/src/components/QuestionTypes/MultipleChoiceType.vue'
77
8- const factory = ( values = { } ) => {
8+
9+ describe ( 'Example' , ( ) => {
10+
11+ const factory = ( values = { } ) => {
912 return shallowMount ( Example , {
1013 data ( ) {
1114 return {
@@ -39,8 +42,6 @@ const wrapper = deepFactory({
3942 ]
4043 } )
4144
42- describe ( 'Example' , ( ) => {
43-
4445 let form
4546 let question
4647 let multipleChoice
@@ -53,26 +54,27 @@ describe('Example', () => {
5354 } ) ( )
5455
5556
56- it ( 'Example is a component' , ( ) => {
57+ it ( " is a component" , ( ) => {
5758
5859 const wrapper = factory ( )
5960
6061 expect ( wrapper . findComponent ( Example ) . vm )
6162 } )
6263
63- it ( ' contains a FlowForm component' , ( ) => {
64+ it ( " contains a FlowForm component" , ( ) => {
6465
6566 const wrapper = factory ( )
6667
6768 expect ( wrapper . findComponent ( FlowForm ) . exists ( ) ) . toBe ( true )
6869 } )
6970
7071
71- it ( ' renders a submit button on the final screen' , ( ) => {
72+ it ( " renders a submit button on the final screen" , ( ) => {
7273
7374 const wrapper = deepFactory ( )
74-
75- expect ( wrapper . find ( ".o-btn-action" ) . text ( ) ) . toBe ( "Submit" )
75+
76+ expect ( wrapper . find ( '.f-submit button' ) . exists ( ) ) . toBe ( true )
77+ expect ( wrapper . find ( '.f-submit button' ) . text ( ) ) . toBe ( "Submit" )
7678 } )
7779
7880
@@ -86,27 +88,45 @@ describe('Example', () => {
8688 setTimeout ( ( ) => {
8789 expect ( form . find ( '.text-success' ) . exists ( ) ) . toBe ( true )
8890 expect ( form . classes ( '.f-submit' ) ) . toBe ( false )
89- } , 100 )
91+ } , 10 )
9092 } )
9193
9294
93- it ( "renders a MultipleChoice question type with one option " , ( ) => {
95+ it ( "renders one MultipleChoice type question " , ( ) => {
9496
9597 wrapper . vm . $nextTick ( ( ) => {
9698 expect ( question . exists ( ) ) . toBe ( true )
9799 expect ( form . findAllComponents ( FlowFormQuestion ) ) . toHaveLength ( 1 )
98- expect ( question . find ( '.f-text' ) . text ( ) ) . toEqual ( "Question" )
99- expect ( question . find ( '.f-enter' ) . exists ( ) ) . toBe ( false )
100100 expect ( multipleChoice . exists ( ) ) . toBe ( true )
101+ expect ( multipleChoice . classes ( '.f-multiple' ) ) . toBe ( false )
102+ } )
103+ } )
104+
105+ it ( "renders one option" , ( ) => {
106+
107+ wrapper . vm . $nextTick ( ( ) => {
101108 expect ( multipleChoice . find ( '.f-radios' ) . findAll ( 'li' ) ) . toHaveLength ( 1 )
109+ } )
110+ } )
111+
112+ it ( "renders question strings correctly" , ( ) => {
113+
114+ wrapper . vm . $nextTick ( ( ) => {
115+ expect ( question . find ( '.f-text' ) . text ( ) ) . toEqual ( "Question" )
102116 expect ( multipleChoice . find ( '.f-key' ) . exists ( ) ) . toBe ( true )
103117 expect ( multipleChoice . find ( '.f-key' ) . text ( ) ) . toEqual ( "A" )
104118 expect ( multipleChoice . find ( '.f-label' ) . exists ( ) ) . toBe ( true )
105119 expect ( multipleChoice . find ( '.f-label' ) . text ( ) ) . toEqual ( "Answer" )
106- expect ( multipleChoice . classes ( '.f-multiple' ) ) . toBe ( false )
107- expect ( multipleChoice . classes ( '.f-selected' ) ) . toBe ( false )
108120 } )
121+ } )
122+
123+
124+ it ( "doesn't render Enter button if not selected" , ( ) => {
109125
126+ wrapper . vm . $nextTick ( ( ) => {
127+ expect ( multipleChoice . classes ( '.f-selected' ) ) . toBe ( false )
128+ expect ( question . find ( '.f-enter' ) . exists ( ) ) . toBe ( false )
129+ } )
110130 } )
111131
112132 it ( "allows to select an answer and click OK" , ( ) => {
@@ -123,7 +143,6 @@ describe('Example', () => {
123143
124144 expect ( question . emitted ( ) . answer ) . toBeTruthy ( )
125145 } )
126-
127146 } )
128147
129148} )
0 commit comments