@@ -4,7 +4,9 @@ export const resultsTitle = 'cx-breadcrumb h1';
4
4
5
5
export function productTypeFlow ( mobile ?: string ) {
6
6
cy . server ( ) ;
7
- cy . route ( 'GET' , '/rest/v2/electronics-spa/products/search*' ) . as ( 'query' ) ;
7
+
8
+ createDefaultQueryRoute ( 'query' ) ;
9
+
8
10
cy . get ( 'cx-searchbox input' ) . type ( 'sony{enter}' ) ;
9
11
10
12
cy . get ( resultsTitle ) . should ( 'contain' , '131 results for "sony"' ) ;
@@ -14,154 +16,90 @@ export function productTypeFlow(mobile?: string) {
14
16
PRODUCT_LISTING . PRODUCTS_PER_PAGE
15
17
) ;
16
18
17
- cy . get ( 'cx-product-list-item' )
18
- . first ( )
19
- . should ( 'contain' , '10.2 Megapixel D-SLR with Standard Zoom Lens' ) ;
19
+ checkFirstItem ( '10.2 Megapixel D-SLR with Standard Zoom Lens' ) ;
20
20
21
21
// Filter by brand
22
- cy . route (
23
- 'GET' ,
24
- '/rest/v2/electronics-spa/products/search?fields=*&query=sony:relevance:brand*'
25
- ) . as ( 'brand_query' ) ;
26
- cy . get ( '.cx-facet-header' )
27
- . contains ( 'Brand' )
28
- . parents ( '.cx-facet-group' )
29
- . within ( ( ) => {
30
- cy . get ( '.cx-facet-checkbox' )
31
- . first ( )
32
- . click ( { force : true } ) ;
33
- } ) ;
22
+ createQueryRoute ( 'brand' , 'brand_query' ) ;
23
+
24
+ clickFacet ( 'Brand' ) ;
34
25
35
26
cy . wait ( '@brand_query' ) ;
36
27
37
28
cy . get ( resultsTitle ) . should ( 'contain' , '86 results for "sony"' ) ;
38
- cy . get ( 'cx-product-list-item' )
39
- . first ( )
40
- . should ( 'contain' , '10.2 Megapixel D-SLR with Standard Zoom Lens' ) ;
41
29
42
- cy . route ( 'GET' , '/rest/v2/electronics-spa/products/search*' ) . as ( 'query1' ) ;
30
+ createDefaultQueryRoute ( 'query1' ) ;
43
31
44
- if ( mobile ) {
45
- cy . get (
46
- `cx-product-facet-navigation ${ mobile } .cx-facet-filter-pill .close:first`
47
- ) . click ( { force : true } ) ;
48
- } else {
49
- cy . get (
50
- 'cx-product-facet-navigation .cx-facet-filter-container .cx-facet-filter-pill .close:first'
51
- ) . click ( { force : true } ) ;
52
- }
32
+ clearSelectedFacet ( mobile ) ;
53
33
54
34
cy . wait ( '@query1' ) ;
55
35
56
36
cy . get ( resultsTitle ) . should ( 'contain' , '131 results for "sony"' ) ;
57
37
58
38
// Filter by price
59
- cy . route (
60
- 'GET' ,
61
- '/rest/v2/electronics-spa/products/search?fields=*&query=sony:relevance:price*'
62
- ) . as ( 'price_query' ) ;
39
+ createQueryRoute ( 'price' , 'price_query' ) ;
63
40
64
- cy . get ( '.cx-facet-header' )
65
- . contains ( 'Price' )
66
- . parents ( '.cx-facet-group' )
67
- . within ( ( ) => {
68
- cy . get ( '.cx-facet-checkbox' )
69
- . first ( )
70
- . click ( { force : true } ) ;
71
- } ) ;
41
+ clickFacet ( 'Price' ) ;
72
42
73
43
cy . wait ( '@price_query' )
74
44
. its ( 'url' )
75
45
. should ( 'include' , 'sony:relevance:price' ) ;
76
46
77
47
cy . get ( resultsTitle ) . should ( 'contain' , '16 results for "sony"' ) ;
78
- cy . get ( 'cx-product-list-item' )
79
- . first ( )
80
- . should ( 'contain' , 'MSHX8A' ) ;
81
48
82
- cy . route ( 'GET' , '/rest/v2/electronics-spa/products/search*' ) . as ( 'query2 ') ;
49
+ checkFirstItem ( 'MSHX8A ') ;
83
50
84
- if ( mobile ) {
85
- cy . get (
86
- `cx-product-facet-navigation ${ mobile } .cx-facet-filter-pill .close:first`
87
- ) . click ( { force : true } ) ;
88
- } else {
89
- cy . get (
90
- 'cx-product-facet-navigation .cx-facet-filter-container .cx-facet-filter-pill .close:first'
91
- ) . click ( { force : true } ) ;
92
- }
51
+ createDefaultQueryRoute ( 'query2' ) ;
52
+
53
+ clearSelectedFacet ( mobile ) ;
93
54
94
55
cy . wait ( '@query2' ) ;
95
56
96
57
cy . get ( resultsTitle ) . should ( 'contain' , '131 results for "sony"' ) ;
97
58
98
59
// Filter by category
99
- cy . route (
100
- 'GET' ,
101
- '/rest/v2/electronics-spa/products/search?fields=*&query=sony:relevance:category*'
102
- ) . as ( 'category_query' ) ;
60
+ createQueryRoute ( 'category' , 'category_query' ) ;
103
61
104
- cy . get ( '.cx-facet-header' )
105
- . contains ( 'Category' )
106
- . parents ( '.cx-facet-group' )
107
- . within ( ( ) => {
108
- cy . get ( '.cx-facet-checkbox' )
109
- . first ( )
110
- . click ( { force : true } ) ;
111
- } ) ;
62
+ clickFacet ( 'Category' ) ;
112
63
113
64
cy . wait ( '@category_query' )
114
65
. its ( 'url' )
115
66
. should ( 'include' , 'sony:relevance:category' ) ;
116
67
117
68
cy . get ( resultsTitle ) . should ( 'contain' , '95 results for "sony"' ) ;
118
69
119
- cy . get ( 'cx-product-list-item' )
120
- . first ( )
121
- . should ( 'contain' , '10.2 Megapixel D-SLR with Standard Zoom Lens' ) ;
70
+ checkFirstItem ( '10.2 Megapixel D-SLR with Standard Zoom Lens' ) ;
122
71
123
- cy . route ( 'GET' , '/rest/v2/electronics-spa/products/search*' ) . as ( 'query3' ) ;
72
+ createDefaultQueryRoute ( 'query3' ) ;
124
73
125
- if ( mobile ) {
126
- cy . get (
127
- `cx-product-facet-navigation ${ mobile } .cx-facet-filter-pill .close:first`
128
- ) . click ( { force : true } ) ;
129
- } else {
130
- cy . get (
131
- 'cx-product-facet-navigation .cx-facet-filter-pill .close:first'
132
- ) . click ( { force : true } ) ;
133
- }
74
+ clearSelectedFacet ( mobile ) ;
134
75
135
76
cy . wait ( '@query3' ) ;
136
77
137
78
cy . get ( resultsTitle ) . should ( 'contain' , '131 results for "sony"' ) ;
138
79
139
80
// Filter by color
140
- cy . route (
141
- 'GET' ,
142
- '/rest/v2/electronics-spa/products/search?fields=*&query=sony:relevance:Colour*'
143
- ) . as ( 'color_query' ) ;
81
+ createQueryRoute ( 'Colour' , 'color_query' ) ;
144
82
145
- cy . get ( '.cx-facet-header' )
146
- . contains ( 'Color' )
147
- . parents ( '.cx-facet-group' )
148
- . within ( ( ) => {
149
- cy . get ( '.cx-facet-checkbox' )
150
- . first ( )
151
- . click ( { force : true } ) ;
152
- } ) ;
83
+ clickFacet ( 'Color' ) ;
153
84
154
85
cy . wait ( '@color_query' )
155
86
. its ( 'url' )
156
87
. should ( 'include' , 'sony:relevance:Colour' ) ;
157
88
158
89
cy . get ( resultsTitle ) . should ( 'contain' , '7 results for "sony"' ) ;
159
- cy . get ( 'cx-product-list-item' )
160
- . first ( )
161
- . should ( 'contain' , 'NP-FV 70' ) ;
162
90
163
- cy . route ( 'GET' , '/rest/v2/electronics-spa/products/search*' ) . as ( 'query4' ) ;
91
+ checkFirstItem ( 'NP-FV 70' ) ;
92
+
93
+ createDefaultQueryRoute ( 'query4' ) ;
164
94
95
+ clearSelectedFacet ( mobile ) ;
96
+
97
+ cy . wait ( '@query4' ) ;
98
+
99
+ cy . get ( resultsTitle ) . should ( 'contain' , '131 results for "sony"' ) ;
100
+ }
101
+
102
+ function clearSelectedFacet ( mobile : string ) {
165
103
if ( mobile ) {
166
104
cy . get (
167
105
`cx-product-facet-navigation ${ mobile } .cx-facet-filter-pill .close:first`
@@ -171,8 +109,32 @@ export function productTypeFlow(mobile?: string) {
171
109
'cx-product-facet-navigation .cx-facet-filter-container .cx-facet-filter-pill .close:first'
172
110
) . click ( { force : true } ) ;
173
111
}
112
+ }
174
113
175
- cy . wait ( '@query4' ) ;
114
+ function clickFacet ( header : string ) {
115
+ cy . get ( '.cx-facet-header' )
116
+ . contains ( header )
117
+ . parents ( '.cx-facet-group' )
118
+ . within ( ( ) => {
119
+ cy . get ( '.cx-facet-checkbox' )
120
+ . first ( )
121
+ . click ( { force : true } ) ;
122
+ } ) ;
123
+ }
176
124
177
- cy . get ( resultsTitle ) . should ( 'contain' , '131 results for "sony"' ) ;
125
+ function checkFirstItem ( title : string ) : void {
126
+ cy . get ( 'cx-product-list-item' )
127
+ . first ( )
128
+ . should ( 'contain' , title ) ;
129
+ }
130
+
131
+ function createDefaultQueryRoute ( alias : string ) : void {
132
+ cy . route ( 'GET' , '/rest/v2/electronics-spa/products/search*' ) . as ( alias ) ;
133
+ }
134
+
135
+ function createQueryRoute ( param : string , alias : string ) : void {
136
+ cy . route (
137
+ 'GET' ,
138
+ `/rest/v2/electronics-spa/products/search?fields=*&query=sony:relevance:${ param } *`
139
+ ) . as ( alias ) ;
178
140
}
0 commit comments