@@ -24,7 +24,7 @@ import { randUser } from '../utils/index.js'
2424
2525const user = randUser ( )
2626
27- describe ( 'yjs document state ' , ( ) => {
27+ describe ( 'Save ' , ( ) => {
2828 before ( ( ) => {
2929 cy . createUser ( user )
3030 } )
@@ -33,31 +33,38 @@ describe('yjs document state', () => {
3333 cy . login ( user )
3434 cy . uploadTestFile ( 'test.md' )
3535 cy . visit ( '/apps/files' )
36- cy . intercept ( { method : 'POST' , url : '**/apps/text/session/sync' } ) . as ( 'sync' )
36+ cy . intercept ( { method : 'POST' , url : '**/apps/text/session/sync' } , ( req ) => {
37+ if ( req . body . autosaveContent ) {
38+ req . alias = 'save'
39+ }
40+ } ) . as ( 'sync' )
3741 cy . openTestFile ( )
3842 cy . getContent ( ) . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
39- cy . wait ( '@sync' , { timeout : 7000 } )
4043 cy . getContent ( ) . type ( '* Saving the doc saves the doc state{enter}' )
41- cy . wait ( '@sync' , { timeout : 7000 } )
4244 } )
4345
4446 it ( 'saves the actual file and document state' , ( ) => {
4547 cy . getContent ( ) . type ( '{ctrl+s}' )
46- cy . wait ( '@sync ' ) . its ( 'request.body' )
47- . should ( 'have.property' , 'autosaveContent ' )
48+ cy . wait ( '@save ' ) . its ( 'request.body' )
49+ . should ( 'have.property' , 'documentState ' )
4850 . should ( 'not.be.empty' )
51+ cy . testName ( )
52+ . then ( name => cy . downloadFile ( `/${ name } .md` ) )
53+ . its ( 'data' )
54+ . should ( 'include' , 'saves the doc state' )
55+ cy . closeFile ( )
56+ } )
57+
58+ it ( 'saves on close' , ( ) => {
4959 cy . closeFile ( )
60+ cy . wait ( '@save' )
5061 cy . testName ( )
5162 . then ( name => cy . downloadFile ( `/${ name } .md` ) )
5263 . its ( 'data' )
5364 . should ( 'include' , 'saves the doc state' )
5465 } )
5566
5667 it ( 'passes the doc content from one session to the next' , ( ) => {
57- cy . getContent ( ) . type ( '{ctrl+s}' )
58- cy . wait ( '@sync' ) . its ( 'request.body' )
59- . should ( 'have.property' , 'documentState' )
60- . should ( 'not.be.empty' )
6168 cy . closeFile ( )
6269 cy . intercept ( { method : 'PUT' , url : '**/apps/text/session/create' } )
6370 . as ( 'create' )
@@ -66,10 +73,20 @@ describe('yjs document state', () => {
6673 . its ( 'response.body' )
6774 . should ( 'have.property' , 'content' )
6875 . should ( 'not.be.empty' )
69- cy . wait ( '@sync' ) . its ( 'request.body' ) . should ( 'have.property' , 'version' )
7076 cy . getContent ( ) . find ( 'h2' ) . should ( 'contain' , 'Hello world' )
7177 cy . getContent ( ) . find ( 'li' ) . should ( 'contain' , 'Saving the doc saves the doc state' )
7278 cy . getContent ( ) . type ( 'recovered' )
7379 cy . closeFile ( )
7480 } )
81+
82+ // regression test #3834
83+ it ( 'close triggers one close request' , ( ) => {
84+ cy . closeFile ( )
85+ // Wait to make sure there is enough time for all close requests to run
86+ // eslint-disable-next-line cypress/no-unnecessary-waiting
87+ cy . wait ( 100 )
88+ // reuse @close intercepted in closeFile()
89+ cy . get ( '@close.all' ) . should ( 'have.length' , 1 )
90+ } )
91+
7592} )
0 commit comments