1- import "@4tw/cypress-drag-drop" ;
1+ const TOTAL_ITEMS = 17 ;
22
33describe ( "Testing the Gmail Demo" , ( ) => {
44 beforeEach ( ( ) => {
@@ -14,11 +14,11 @@ describe("Testing the Gmail Demo", () => {
1414 } ) ;
1515
1616 it ( "Collapses and Expands the Categories" , ( ) => {
17- cy . get ( "@item" ) . should ( "have.length" , "16" ) ;
17+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS ) ;
1818 cy . get ( "@item" ) . contains ( "Categories" ) . click ( ) ;
1919 cy . get ( "@item" ) . should ( "have.length" , "12" ) ;
2020 cy . get ( "@item" ) . contains ( "Categories" ) . click ( ) ;
21- cy . get ( "@item" ) . should ( "have.length" , "16" ) ;
21+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS ) ;
2222 } ) ;
2323
2424 it ( "Up and Down Arrows" , ( ) => {
@@ -32,12 +32,12 @@ describe("Testing the Gmail Demo", () => {
3232 } ) ;
3333
3434 it ( "Left and Right Arrows" , ( ) => {
35- cy . get ( "@item" ) . should ( "have.length" , 16 ) ;
35+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS ) ;
3636 cy . get ( "@item" ) . contains ( "Categories" ) . click ( ) ;
3737 cy . focused ( ) . type ( "{leftArrow}" ) ;
3838 cy . get ( "@item" ) . should ( "have.length" , 12 ) ;
3939 cy . focused ( ) . type ( "{rightArrow}" ) ;
40- cy . get ( "@item" ) . should ( "have.length" , 16 ) ;
40+ cy . get ( "@item" ) . should ( "have.length" , TOTAL_ITEMS ) ;
4141 cy . focused ( ) . should ( "contain.text" , "Categories" ) ;
4242 cy . focused ( ) . type ( "{rightArrow}" ) ;
4343 cy . focused ( ) . should ( "contain.text" , "Social" ) ;
@@ -51,13 +51,13 @@ describe("Testing the Gmail Demo", () => {
5151 cy . get ( "@item" ) . first ( ) . click ( ) ;
5252 cy . focused ( ) . type ( "a" ) ;
5353 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 ) ;
5555
5656 // In a Folder
5757 cy . get ( "@item" ) . contains ( "Social" ) . click ( ) ;
5858 cy . focused ( ) . type ( "a" ) ;
5959 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 ) ;
6161
6262 // On a folder that is closed
6363 cy . get ( "@item" ) . contains ( "Categories" ) . click ( ) ; // closed it
@@ -79,14 +79,14 @@ describe("Testing the Gmail Demo", () => {
7979 cy . get ( "@item" ) . first ( ) . click ( ) ;
8080 cy . focused ( ) . type ( "A" ) ;
8181 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 ) ;
8383 cy . focused ( ) . children ( ) . should ( "have.class" , "isInternal" ) ;
8484
8585 // In a Folder
8686 cy . get ( "@item" ) . contains ( "Social" ) . click ( ) ;
8787 cy . focused ( ) . type ( "A" ) ;
8888 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 ) ;
9090 cy . focused ( ) . children ( ) . should ( "have.class" , "isInternal" ) ;
9191
9292 // On a folder that is closed
@@ -106,24 +106,44 @@ describe("Testing the Gmail Demo", () => {
106106 } ) ;
107107
108108 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+ ) ;
112113
113114 cy . get ( "@item" ) . contains ( "Inbox" ) . click ( ) ;
114- cy . focused ( ) . invoke ( "index" ) . should ( "eq" , 4 ) ;
115+ cy . focused ( ) . invoke ( "index" ) . should ( "eq" , 2 ) ;
115116 } ) ;
116117
117118 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+ ) ;
120123 cy . get ( "@item" ) . contains ( "Starred" ) . click ( ) ;
121124 cy . focused ( ) . invoke ( "index" ) . should ( "eq" , 11 ) ;
122125 } ) ;
123126
124127 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+ ) ;
126132 cy . get ( "@item" ) . contains ( "Inbox" ) . click ( ) ;
127133 cy . focused ( ) . invoke ( "index" ) . should ( "eq" , 0 ) ;
128134 } ) ;
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+ } ) ;
129142} ) ;
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