@@ -22,123 +22,110 @@ describe('Test state loading of documents', function() {
2222
2323 it ( 'Initial content can not be undone' , function ( ) {
2424 cy . shareFile ( '/test.md' , { edit : true } )
25- . then ( ( token ) => {
26- cy . visit ( `/s/${ token } ` )
27- } )
28- . then ( ( ) => {
29- cy . getEditor ( ) . should ( 'be.visible' )
30- cy . getContent ( )
31- . should ( 'contain' , 'Hello world' )
32- . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
33-
34- cy . getMenu ( ) . should ( 'be.visible' )
35- cy . getActionEntry ( 'undo' ) . should ( 'be.disabled' )
36-
37- cy . getContent ( )
38- . type ( 'New content' )
39- cy . getActionEntry ( 'undo' ) . should ( 'not.be.disabled' )
40- } )
25+ . then ( token => cy . visit ( `/s/${ token } ` ) )
26+ cy . getEditor ( ) . should ( 'be.visible' )
27+ cy . getContent ( )
28+ . should ( 'contain' , 'Hello world' )
29+ . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
30+
31+ cy . getMenu ( ) . should ( 'be.visible' )
32+ cy . getActionEntry ( 'undo' ) . should ( 'be.disabled' )
33+
34+ cy . getContent ( )
35+ . type ( 'New content' )
36+ cy . getActionEntry ( 'undo' ) . should ( 'not.be.disabled' )
4137 } )
4238
4339 it ( 'Consecutive sessions work properly' , function ( ) {
44- let readToken = null
45- let writeToken = null
4640 cy . interceptCreate ( )
4741 cy . shareFile ( '/test2.md' )
48- . then ( ( token ) => {
49- readToken = token
50- cy . logout ( )
51- cy . visit ( `/s/${ readToken } ` )
52- cy . wait ( '@create' )
53- } )
54- . then ( ( ) => {
55- // Open read only for the first time
56- cy . getEditor ( ) . should ( 'be.visible' )
57- cy . getContent ( )
58- . should ( 'contain' , 'Hello world' )
59- . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
60- cy . closeInterceptedSession ( readToken )
61-
62- // Open read only for the second time
63- cy . reload ( )
64- cy . getEditor ( ) . should ( 'be.visible' )
65- cy . getContent ( )
66- . should ( 'contain' , 'Hello world' )
67- . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
68- cy . closeInterceptedSession ( readToken )
69-
70- cy . login ( user )
71- cy . shareFile ( '/test2.md' , { edit : true } )
72- . then ( ( token ) => {
73- writeToken = token
74- // Open write link and edit something
75- cy . visit ( `/s/${ writeToken } ` )
76- cy . getEditor ( ) . should ( 'be.visible' )
77- cy . getContent ( )
78- . should ( 'contain' , 'Hello world' )
79- . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
80- cy . getContent ( )
81- . type ( 'Something new {end}' )
82- cy . intercept ( { method : 'POST' , url : '**/session/*/push' } ) . as ( 'push' )
83- cy . intercept ( { method : 'POST' , url : '**/session/*/sync' } ) . as ( 'sync' )
84- cy . wait ( '@push' )
85- cy . wait ( '@sync' )
86- cy . closeInterceptedSession ( writeToken )
87-
88- // Reopen read only link and check if changes are there
89- cy . visit ( `/s/${ readToken } ` )
90- cy . getEditor ( ) . should ( 'be.visible' )
91- cy . getContent ( )
92- . find ( 'h2' ) . should ( 'contain' , 'Something new Hello world' )
93- } )
94- } )
42+ . as ( 'readToken' )
43+ cy . logout ( )
44+ cy . get ( '@readToken' )
45+ . then ( token => cy . visit ( `/s/${ token } ` ) )
46+ cy . wait ( '@create' )
47+ // Open read only for the first time
48+ cy . getEditor ( ) . should ( 'be.visible' )
49+ cy . getContent ( )
50+ . should ( 'contain' , 'Hello world' )
51+ . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
52+ cy . get ( '@readToken' )
53+ . then ( cy . closeInterceptedSession )
54+
55+ // Open read only for the second time
56+ cy . reload ( )
57+ cy . getEditor ( ) . should ( 'be.visible' )
58+ cy . getContent ( )
59+ . should ( 'contain' , 'Hello world' )
60+ . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
61+ cy . get ( '@readToken' )
62+ . then ( cy . closeInterceptedSession )
63+
64+ cy . login ( user )
65+ cy . shareFile ( '/test2.md' , { edit : true } )
66+ . as ( 'writeToken' )
67+ // Open write link and edit something
68+ cy . get ( '@writeToken' )
69+ . then ( token => cy . visit ( `/s/${ token } ` ) )
70+ cy . getEditor ( ) . should ( 'be.visible' )
71+ cy . getContent ( )
72+ . should ( 'contain' , 'Hello world' )
73+ . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
74+ cy . getContent ( )
75+ . type ( 'Something new {end}' )
76+ cy . intercept ( { method : 'POST' , url : '**/session/*/sync' } ) . as ( 'sync' )
77+ cy . wait ( '@sync' )
78+ cy . get ( '@writeToken' )
79+ . then ( cy . closeInterceptedSession )
80+
81+ // Reopen read only link and check if changes are there
82+ cy . get ( '@readToken' )
83+ . then ( token => cy . visit ( `/s/${ token } ` ) )
84+ cy . getEditor ( ) . should ( 'be.visible' )
85+ cy . getContent ( )
86+ . find ( 'h2' ) . should ( 'contain' , 'Something new Hello world' )
9587 } )
9688
9789 it ( 'Load after state has been saved' , function ( ) {
98- let readToken = null
99- let writeToken = null
10090 cy . interceptCreate ( )
10191 cy . shareFile ( '/test3.md' , { edit : true } )
102- . then ( ( token ) => {
103- writeToken = token
104- cy . logout ( )
105- cy . visit ( `/s/${ writeToken } ` )
106- } )
107- . then ( ( ) => {
108- // Open a file, write and save
109- cy . getEditor ( ) . should ( 'be.visible' )
110- cy . getContent ( )
111- . should ( 'contain' , 'Hello world' )
112- . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
113- cy . getContent ( )
114- . type ( 'Something new {end}' )
115- cy . intercept ( { method : 'POST' , url : '**/session/*/save' } ) . as ( 'save' )
116- cy . get ( '.save-status button' ) . click ( )
117- cy . wait ( '@save' , { timeout : 10000 } )
118- cy . closeInterceptedSession ( writeToken )
119-
120- // Open writable file again and assert the content
121- cy . reload ( )
122- cy . getEditor ( ) . should ( 'be.visible' )
123- cy . getContent ( )
124- . should ( 'contain' , 'Hello world' )
125- . find ( 'h2' ) . should ( 'contain' , 'Something new Hello world' )
126-
127- cy . login ( user )
128- cy . shareFile ( '/test3.md' )
129- . then ( ( token ) => {
130- readToken = token
131- cy . logout ( )
132- cy . visit ( `/s/${ readToken } ` )
133- } )
134- . then ( ( ) => {
135- // Open read only file again and assert the content
136- cy . getEditor ( ) . should ( 'be.visible' )
137- cy . getContent ( )
138- . should ( 'contain' , 'Hello world' )
139- . find ( 'h2' ) . should ( 'contain' , 'Something new Hello world' )
140- } )
141- } )
92+ . as ( 'writeToken' )
93+ cy . logout ( )
94+ cy . get ( '@writeToken' )
95+ . then ( token => cy . visit ( `/s/${ token } ` ) )
96+
97+ // Open a file, write and save
98+ cy . getEditor ( ) . should ( 'be.visible' )
99+ cy . getContent ( )
100+ . should ( 'contain' , 'Hello world' )
101+ . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
102+ cy . getContent ( )
103+ . type ( 'Something new {end}' )
104+ cy . intercept ( { method : 'POST' , url : '**/session/*/save' } ) . as ( 'save' )
105+ cy . get ( '.save-status button' ) . click ( )
106+ cy . wait ( '@save' , { timeout : 10000 } )
107+ cy . get ( '@writeToken' )
108+ . then ( cy . closeInterceptedSession )
109+
110+ // Open writable file again and assert the content
111+ cy . reload ( )
112+ cy . getEditor ( ) . should ( 'be.visible' )
113+ cy . getContent ( )
114+ . should ( 'contain' , 'Hello world' )
115+ . find ( 'h2' ) . should ( 'contain' , 'Something new Hello world' )
116+
117+ cy . login ( user )
118+ cy . shareFile ( '/test3.md' )
119+ . as ( 'readToken' )
120+ cy . logout ( )
121+ cy . get ( '@readToken' )
122+ . then ( token => cy . visit ( `/s/${ token } ` ) )
123+
124+ // Open read only file again and assert the content
125+ cy . getEditor ( ) . should ( 'be.visible' )
126+ cy . getContent ( )
127+ . should ( 'contain' , 'Hello world' )
128+ . find ( 'h2' ) . should ( 'contain' , 'Something new Hello world' )
142129 } )
143130
144131} )
0 commit comments