1
- import { frameworks , url , initSurvey , getSurveyResult } from "../helper" ;
1
+ import { frameworks , url_test , initSurvey } from "../helper" ;
2
+ import { QuestionRadiogroup } from "../questionHelper" ;
2
3
import { test , expect } from "@playwright/test" ;
4
+ import { Survey } from "../surveyHelper" ;
3
5
4
6
const title = "completeTrigger" ;
7
+ const themeName = "default" ;
5
8
6
- const json = {
7
- triggers : [
8
- { type : "complete" , name : "exit1" , operator : "equal" , value : "Yes" } ,
9
- { type : "complete" , name : "exit2" , operator : "equal" , value : "Yes" }
10
- ] ,
11
- pages : [
12
- {
13
- title : "What operating system do you use?" ,
14
- questions : [
15
- {
16
- type : "checkbox" ,
17
- name : "opSystem" ,
18
- title : "OS" ,
19
- hasOther : true ,
20
- choices : [ "Windows" , "Linux" , "Macintosh OSX" ]
21
- } ,
22
- {
23
- type : "radiogroup" ,
24
- name : "exit1" ,
25
- title : "Do you want to finish the survey?" ,
26
- choices : [ "Yes" , "No" ] ,
27
- colCount : 0
28
- }
29
- ]
30
- } ,
31
- {
32
- title : "What language(s) are you currently using?" ,
33
- questions : [
34
- {
35
- type : "checkbox" ,
36
- name : "langs" ,
37
- title : "Plese select from the list" ,
38
- colCount : 4 ,
39
- choices : [
40
- "Javascript" ,
41
- "Java" ,
42
- "Python" ,
43
- "CSS" ,
44
- "PHP" ,
45
- "Ruby" ,
46
- "C++" ,
47
- "C" ,
48
- "Shell" ,
49
- "C#" ,
50
- "Objective-C" ,
51
- "R" ,
52
- "VimL" ,
53
- "Go" ,
54
- "Perl" ,
55
- "CoffeeScript" ,
56
- "TeX" ,
57
- "Swift" ,
58
- "Scala" ,
59
- "Emacs List" ,
60
- "Haskell" ,
61
- "Lua" ,
62
- "Clojure" ,
63
- "Matlab" ,
64
- "Arduino" ,
65
- "Makefile" ,
66
- "Groovy" ,
67
- "Puppet" ,
68
- "Rust" ,
69
- "PowerShell"
70
- ]
71
- } ,
72
- {
73
- type : "radiogroup" ,
74
- name : "exit2" ,
75
- title : "Do you want to finish the survey?" ,
76
- choices : [ "Yes" , "No" ] ,
77
- colCount : 0
78
- }
79
- ]
80
- } ,
81
- {
82
- title : "Please enter your name and e-mail" ,
83
- questions : [
84
- { type : "text" , name : "name" , title : "Name:" } ,
85
- { type : "text" , name : "email" , title : "Your e-mail" }
86
- ]
87
- }
88
- ]
89
- } ;
90
-
91
- frameworks . forEach ( framework => {
92
- test . describe ( `${ title } - ${ framework } ` , ( ) => {
9
+ frameworks . forEach ( ( framework ) => {
10
+ test . describe ( `${ framework } ${ title } ` , ( ) => {
93
11
test . beforeEach ( async ( { page } ) => {
94
- await page . goto ( `${ url } ${ framework } ` ) ;
12
+ const json = {
13
+ triggers : [
14
+ { type : "complete" , name : "exit1" , operator : "equal" , value : "Yes" } ,
15
+ { type : "complete" , name : "exit2" , operator : "equal" , value : "Yes" }
16
+ ] ,
17
+ pages : [
18
+ {
19
+ title : "What operating system do you use?" ,
20
+ questions : [
21
+ {
22
+ type : "checkbox" ,
23
+ name : "opSystem" ,
24
+ title : "OS" ,
25
+ hasOther : true ,
26
+ choices : [ "Windows" , "Linux" , "Macintosh OSX" ]
27
+ } ,
28
+ {
29
+ type : "radiogroup" ,
30
+ name : "exit1" ,
31
+ title : "Do you want to finish the survey?" ,
32
+ choices : [ "Yes" , "No" ] ,
33
+ colCount : 0
34
+ }
35
+ ]
36
+ } ,
37
+ {
38
+ title : "What language(s) are you currently using?" ,
39
+ questions : [
40
+ {
41
+ type : "checkbox" ,
42
+ name : "langs" ,
43
+ title : "Plese select from the list" ,
44
+ colCount : 4 ,
45
+ choices : [
46
+ "Javascript" ,
47
+ "Java" ,
48
+ "Python" ,
49
+ "CSS" ,
50
+ "PHP" ,
51
+ "Ruby" ,
52
+ "C++" ,
53
+ "C" ,
54
+ "Shell" ,
55
+ "C#" ,
56
+ "Objective-C" ,
57
+ "R" ,
58
+ "VimL" ,
59
+ "Go" ,
60
+ "Perl" ,
61
+ "CoffeeScript" ,
62
+ "TeX" ,
63
+ "Swift" ,
64
+ "Scala" ,
65
+ "Emacs List" ,
66
+ "Haskell" ,
67
+ "Lua" ,
68
+ "Clojure" ,
69
+ "Matlab" ,
70
+ "Arduino" ,
71
+ "Makefile" ,
72
+ "Groovy" ,
73
+ "Puppet" ,
74
+ "Rust" ,
75
+ "PowerShell"
76
+ ]
77
+ } ,
78
+ {
79
+ type : "radiogroup" ,
80
+ name : "exit2" ,
81
+ title : "Do you want to finish the survey?" ,
82
+ choices : [ "Yes" , "No" ] ,
83
+ colCount : 0
84
+ }
85
+ ]
86
+ } ,
87
+ {
88
+ title : "Please enter your name and e-mail" ,
89
+ questions : [
90
+ { type : "text" , name : "name" , title : "Name:" } ,
91
+ { type : "text" , name : "email" , title : "Your e-mail" }
92
+ ]
93
+ }
94
+ ]
95
+ } ;
96
+ await page . goto ( `${ url_test } ${ themeName } /${ framework } ` ) ;
95
97
await initSurvey ( page , framework , json ) ;
96
98
} ) ;
97
-
98
99
test ( "check visibility" , async ( { page } ) => {
99
- const nextSelector = page . locator ( "input[value=\"Next\"]" ) . filter ( { visible : true } ) ;
100
- const completeSelector = page . locator ( "input[value=\"Complete\"]" ) . filter ( { visible : true } ) ;
101
- const yesSelector = page . locator ( "label" ) . filter ( { hasText : "Yes" } ) . locator ( "span" ) . first ( ) ;
102
- const noSelector = page . locator ( "label" ) . filter ( { hasText : "No" } ) . locator ( "span" ) . first ( ) ;
100
+ const survey = new Survey ( page ) ;
101
+ const exit1 = new QuestionRadiogroup ( page , "exit1" ) ;
102
+ await exit1 . clickByValue ( "No" ) ;
103
+ await survey . nextPage ( ) ;
104
+ const exit2 = new QuestionRadiogroup ( page , "exit2" ) ;
105
+ await exit2 . clickByValue ( "Yes" ) ;
106
+ await survey . complete ( ) ;
103
107
104
- await expect ( page . locator ( ".sv-string-viewer" ) . filter ( { hasText : "4. Do you want to finish the survey?" } ) ) . toHaveCount ( 0 ) ;
105
- await noSelector . click ( ) ;
106
- await nextSelector . click ( ) ;
107
- await yesSelector . click ( ) ;
108
- await completeSelector . click ( ) ;
109
-
110
- const surveyResult = await getSurveyResult ( page ) ;
111
- expect ( surveyResult ) . toEqual ( { exit1 : "No" , exit2 : "Yes" } ) ;
108
+ await survey . checkData ( { exit1 : "No" , exit2 : "Yes" } ) ;
112
109
} ) ;
113
-
114
110
test ( "check complete and next buttons visibility" , async ( { page } ) => {
115
- const nextSelector = page . locator ( "input[value=\"Next\"]" ) . filter ( { visible : true } ) ;
116
- const completeSelector = page . locator ( "input[value=\"Complete\"]" ) . filter ( { visible : true } ) ;
117
- const yesSelector = page . locator ( "label" ) . filter ( { hasText : "Yes" } ) . locator ( "span" ) . first ( ) ;
118
- const noSelector = page . locator ( "label" ) . filter ( { hasText : "No" } ) . locator ( "span" ) . first ( ) ;
119
-
120
- await expect ( nextSelector ) . toHaveCount ( 1 ) ;
121
- await expect ( completeSelector ) . toHaveCount ( 0 ) ;
122
-
123
- await yesSelector . click ( ) ;
124
- await expect ( nextSelector ) . toHaveCount ( 0 ) ;
125
- await expect ( completeSelector ) . toHaveCount ( 1 ) ;
126
-
127
- await noSelector . click ( ) ;
128
- await expect ( nextSelector ) . toHaveCount ( 1 ) ;
129
- await expect ( completeSelector ) . toHaveCount ( 0 ) ;
130
-
131
- await yesSelector . click ( ) ;
132
- await completeSelector . click ( ) ;
111
+ const survey = new Survey ( page ) ;
112
+ const exit1 = new QuestionRadiogroup ( page , "exit1" ) ;
113
+ await exit1 . clickByValue ( "Yes" ) ;
114
+ await survey . checkNextButtonVisibility ( false ) ;
115
+ await survey . checkCompleteButtonVisibility ( true ) ;
116
+ await survey . checkNextButtonVisibility ( true ) ;
117
+ await survey . checkCompleteButtonVisibility ( false ) ;
118
+ await exit1 . clickByValue ( "No" ) ;
119
+ await exit1 . clickByValue ( "Yes" ) ;
120
+ await survey . checkNextButtonVisibility ( false ) ;
121
+ await survey . checkCompleteButtonVisibility ( true ) ;
122
+ await survey . complete ( ) ;
133
123
134
- const surveyResult = await getSurveyResult ( page ) ;
135
- expect ( surveyResult ) . toEqual ( { exit1 : "Yes" } ) ;
124
+ await survey . checkData ( { exit1 : "Yes" } ) ;
136
125
} ) ;
137
126
} ) ;
138
127
} ) ;
0 commit comments