1
- import "@4tw/cypress-drag-drop" ;
1
+ const TOTAL_ITEMS = 17 ;
2
2
3
3
describe ( "Testing the Gmail Demo" , ( ) => {
4
4
beforeEach ( ( ) => {
@@ -14,11 +14,11 @@ describe("Testing the Gmail Demo", () => {
14
14
} ) ;
15
15
16
16
it ( "Collapses and Expands the Categories" , ( ) => {
17
- cy . get ( "@item" ) . should ( "have.length" , "16" ) ;
17
+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS ) ;
18
18
cy . get ( "@item" ) . contains ( "Categories" ) . click ( ) ;
19
19
cy . get ( "@item" ) . should ( "have.length" , "12" ) ;
20
20
cy . get ( "@item" ) . contains ( "Categories" ) . click ( ) ;
21
- cy . get ( "@item" ) . should ( "have.length" , "16" ) ;
21
+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS ) ;
22
22
} ) ;
23
23
24
24
it ( "Up and Down Arrows" , ( ) => {
@@ -32,12 +32,12 @@ describe("Testing the Gmail Demo", () => {
32
32
} ) ;
33
33
34
34
it ( "Left and Right Arrows" , ( ) => {
35
- cy . get ( "@item" ) . should ( "have.length" , 16 ) ;
35
+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS ) ;
36
36
cy . get ( "@item" ) . contains ( "Categories" ) . click ( ) ;
37
37
cy . focused ( ) . type ( "{leftArrow}" ) ;
38
38
cy . get ( "@item" ) . should ( "have.length" , 12 ) ;
39
39
cy . focused ( ) . type ( "{rightArrow}" ) ;
40
- cy . get ( "@item" ) . should ( "have.length" , 16 ) ;
40
+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS ) ;
41
41
cy . focused ( ) . should ( "contain.text" , "Categories" ) ;
42
42
cy . focused ( ) . type ( "{rightArrow}" ) ;
43
43
cy . focused ( ) . should ( "contain.text" , "Social" ) ;
@@ -51,13 +51,13 @@ describe("Testing the Gmail Demo", () => {
51
51
cy . get ( "@item" ) . first ( ) . click ( ) ;
52
52
cy . focused ( ) . type ( "a" ) ;
53
53
cy . focused ( ) . type ( "Turn A New Leaf{enter}" ) ;
54
- cy . get ( "@item" ) . should ( "have.length" , 17 ) ;
54
+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS + 1 ) ;
55
55
56
56
// In a Folder
57
57
cy . get ( "@item" ) . contains ( "Social" ) . click ( ) ;
58
58
cy . focused ( ) . type ( "a" ) ;
59
59
cy . focused ( ) . type ( "Turn More Leaves{enter}" ) ;
60
- cy . get ( "@item" ) . should ( "have.length" , 18 ) ;
60
+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS + 2 ) ;
61
61
62
62
// On a folder that is closed
63
63
cy . get ( "@item" ) . contains ( "Categories" ) . click ( ) ; // closed it
@@ -79,14 +79,14 @@ describe("Testing the Gmail Demo", () => {
79
79
cy . get ( "@item" ) . first ( ) . click ( ) ;
80
80
cy . focused ( ) . type ( "A" ) ;
81
81
cy . focused ( ) . type ( "Turn A New Internal{enter}" ) ;
82
- cy . get ( "@item" ) . should ( "have.length" , 17 ) ;
82
+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS + 1 ) ;
83
83
cy . focused ( ) . children ( ) . should ( "have.class" , "isInternal" ) ;
84
84
85
85
// In a Folder
86
86
cy . get ( "@item" ) . contains ( "Social" ) . click ( ) ;
87
87
cy . focused ( ) . type ( "A" ) ;
88
88
cy . focused ( ) . type ( "Turn More Inernals{enter}" ) ;
89
- cy . get ( "@item" ) . should ( "have.length" , 18 ) ;
89
+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS + 2 ) ;
90
90
cy . focused ( ) . children ( ) . should ( "have.class" , "isInternal" ) ;
91
91
92
92
// On a folder that is closed
@@ -106,24 +106,44 @@ describe("Testing the Gmail Demo", () => {
106
106
} ) ;
107
107
108
108
it ( "drags and drops in its list" , ( ) => {
109
- cy . get ( "@item" )
110
- . contains ( "Inbox" )
111
- . drag ( "[role=treeitem]:nth-child(5)" , "bottom" ) ;
109
+ dragAndDrop (
110
+ cy . get ( "@item" ) . contains ( "Inbox" ) . first ( ) ,
111
+ cy . get ( "@item" ) . contains ( "Sent" ) . first ( )
112
+ ) ;
112
113
113
114
cy . get ( "@item" ) . contains ( "Inbox" ) . click ( ) ;
114
- cy . focused ( ) . invoke ( "index" ) . should ( "eq" , 4 ) ;
115
+ cy . focused ( ) . invoke ( "index" ) . should ( "eq" , 2 ) ;
115
116
} ) ;
116
117
117
118
it ( "drags and drops into folder" , ( ) => {
118
- cy . get ( "@item" ) . contains ( "Starred" ) . drag ( "[role=treeitem]:nth-child(12)" ) ;
119
-
119
+ dragAndDrop (
120
+ cy . get ( "@item" ) . contains ( "Starred" ) . first ( ) ,
121
+ cy . get ( "@item" ) . contains ( "Social" ) . first ( )
122
+ ) ;
120
123
cy . get ( "@item" ) . contains ( "Starred" ) . click ( ) ;
121
124
cy . focused ( ) . invoke ( "index" ) . should ( "eq" , 11 ) ;
122
125
} ) ;
123
126
124
127
it ( "prevents Inbox from Dragging into Categories" , ( ) => {
125
- cy . get ( "@item" ) . contains ( "Inbox" ) . drag ( "[role=treeitem]:nth-child(12)" ) ;
128
+ dragAndDrop (
129
+ cy . get ( "@item" ) . contains ( "Inbox" ) . first ( ) ,
130
+ cy . get ( "@item" ) . contains ( "Social" ) . first ( )
131
+ ) ;
126
132
cy . get ( "@item" ) . contains ( "Inbox" ) . click ( ) ;
127
133
cy . focused ( ) . invoke ( "index" ) . should ( "eq" , 0 ) ;
128
134
} ) ;
135
+
136
+ it ( "filters to github, then checks expanding and collapsing" , ( ) => {
137
+ cy . get ( "input" ) . type ( "Git" ) ;
138
+ cy . get ( "@item" ) . should ( "have.length" , 3 ) ;
139
+ cy . get ( "@item" ) . contains ( "Categories" ) . click ( ) ; // collapses
140
+ cy . get ( "@item" ) . should ( "have.length" , 1 ) ;
141
+ } ) ;
129
142
} ) ;
143
+
144
+ function dragAndDrop ( src : any , dst : any ) {
145
+ const dataTransfer = new DataTransfer ( ) ;
146
+ src . trigger ( "dragstart" , { dataTransfer } ) ;
147
+ dst . trigger ( "drop" , { dataTransfer } ) ;
148
+ dst . trigger ( "dragend" , { dataTransfer } ) ;
149
+ }
0 commit comments