1
- describe ( `collection-routing` , ( ) => {
2
- beforeEach ( ( ) => {
3
- cy . visit ( `/collection-routing` ) . waitForRouteChange ( )
1
+ const prefixes = [ `` , `child-` , `computed-` , `child-computed-` ]
2
+
3
+ function assert404 ( slug ) {
4
+ for ( const prefix of prefixes ) {
5
+ cy . visit ( `/collection-routing/mutations/${ prefix } ${ slug } /` , {
6
+ failOnStatusCode : false ,
7
+ } ) . waitForRouteChange ( )
8
+
9
+ // page doesn't exist yet
10
+ cy . get ( `h1` ) . invoke ( `text` ) . should ( `eq` , `Gatsby.js development 404 page` )
11
+ }
12
+ }
13
+
14
+ function assertPageExist ( slug , content ) {
15
+ for ( const prefix of prefixes ) {
16
+ cy . visit (
17
+ `/collection-routing/mutations/${ prefix } ${ slug } /`
18
+ ) . waitForRouteChange ( )
19
+ cy . contains ( content )
20
+ }
21
+ }
22
+
23
+ function refresh ( setup ) {
24
+ cy . then ( ( ) => {
25
+ return fetch (
26
+ `http://localhost:8000/__refresh/gatsby-source-fs-route-mutations` ,
27
+ {
28
+ method : `POST` ,
29
+ headers : {
30
+ "Content-Type" : "application/json" ,
31
+ } ,
32
+ body : JSON . stringify ( { setup } ) ,
33
+ }
34
+ )
4
35
} )
5
36
37
+ cy . wait ( 5000 )
38
+ }
39
+
40
+ describe ( `collection-routing` , ( ) => {
6
41
it ( `can create simplest collection route that also has a number as an identifier` , ( ) => {
7
42
cy . visit ( `/collection-routing/1/` ) . waitForRouteChange ( )
8
43
cy . findByTestId ( `slug` ) . should ( `have.text` , `/preview/1` )
9
44
cy . findByTestId ( `pagecontext` ) . should ( `have.text` , `1` )
10
45
} )
11
46
12
47
it ( `can navigate to a collection route and see its content rendered` , ( ) => {
48
+ cy . visit ( `/collection-routing` ) . waitForRouteChange ( )
13
49
// this test depends on the alphabetical sorting of markdown files
14
50
cy . findByTestId ( `collection-routing-blog-0` )
15
51
. should ( `have.attr` , `data-testslug` , `/2018-12-14-hello-world/` )
@@ -24,6 +60,7 @@ describe(`collection-routing`, () => {
24
60
} )
25
61
26
62
it ( `can navigate to a collection route that uses unions and see its content rendered` , ( ) => {
63
+ cy . visit ( `/collection-routing` ) . waitForRouteChange ( )
27
64
// this test depends on the alphabetical sorting of image files
28
65
cy . findByTestId ( `collection-routing-image-0` )
29
66
. should ( `have.attr` , `data-testimagename` , `citrus-fruits` )
@@ -61,4 +98,49 @@ describe(`collection-routing`, () => {
61
98
cy . findByTestId ( `title` )
62
99
cy . should ( `have.text` , `Named SPLAT Nested with Collection Route!` )
63
100
} )
101
+
102
+ describe ( `data updates` , ( ) => {
103
+ before ( ( ) => {
104
+ refresh ( `reset` )
105
+ } )
106
+ after ( ( ) => {
107
+ refresh ( `reset` )
108
+ } )
109
+
110
+ it ( `creates a page when new node is created` , ( ) => {
111
+ assert404 ( `new-node` )
112
+ assert404 ( `updated-node` )
113
+
114
+ refresh ( `create` )
115
+
116
+ assertPageExist ( `new-node` , `This is node that was just created` )
117
+ assert404 ( `updated-node` )
118
+ } )
119
+
120
+ it ( `remove previous page and add a new one when slug changes` , ( ) => {
121
+ assertPageExist ( `new-node` , `This is node that was just created` )
122
+ assert404 ( `updated-node` )
123
+
124
+ refresh ( `update` )
125
+
126
+ assertPageExist (
127
+ `updated-node` ,
128
+ `This is node that had slug and content updated`
129
+ )
130
+ assert404 ( `new-node` )
131
+ } )
132
+
133
+ it ( `remove a page when node is deleted` , ( ) => {
134
+ assertPageExist (
135
+ `updated-node` ,
136
+ `This is node that had slug and content updated`
137
+ )
138
+ assert404 ( `new-node` )
139
+
140
+ refresh ( `delete` )
141
+
142
+ assert404 ( `new-node` )
143
+ assert404 ( `updated-node` )
144
+ } )
145
+ } )
64
146
} )
0 commit comments