-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathsync.spec.js
More file actions
184 lines (163 loc) Β· 6.4 KB
/
Copy pathsync.spec.js
File metadata and controls
184 lines (163 loc) Β· 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { randUser } from '../utils/index.js'
const user = randUser()
describe('Sync', () => {
before(() => {
cy.createUser(user)
})
beforeEach(() => {
cy.login(user)
cy.uploadTestFile('test.md')
cy.visit('/apps/files')
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/sync' }).as('sync')
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/save' }).as('save')
cy.openTestFile()
cy.wait('@sync', { timeout: 10000 })
cy.getContent().find('h2').should('contain', 'Hello world')
cy.insertLine('{moveToEnd}* Saving the doc saves the doc state')
cy.wait('@sync', { timeout: 10000 })
})
it('saves the actual file and document state', () => {
cy.getContent().type('{ctrl+s}')
cy.wait('@save').its('request.body')
.should('have.property', 'documentState')
.should('not.be.empty')
cy.testName()
.then(name => cy.downloadFile(`/${name}.md`))
.its('data')
.should('include', 'saves the doc state')
cy.closeFile()
})
it('saves on close', () => {
cy.closeFile()
cy.wait('@save')
cy.testName()
.then(name => cy.downloadFile(`/${name}.md`))
.its('data')
.should('include', 'saves the doc state')
})
it('recovers from a short lost connection', () => {
cy.intercept('**/apps/text/session/*/*', req => req.destroy()).as('dead')
cy.wait('@dead', { timeout: 30000 })
cy.get('#editor-container .document-status', { timeout: 30000 })
.should('contain', 'The document could not be loaded.')
cy.intercept('**/apps/text/session/*/*', req => req.continue()).as('alive')
cy.wait('@alive', { timeout: 30000 })
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/sync' })
.as('syncAfterRecovery')
cy.wait('@syncAfterRecovery', { timeout: 30000 })
cy.get('#editor-container .document-status', { timeout: 30000 })
.should('not.contain', 'The document could not be loaded.')
// FIXME: There seems to be a bug where typed words maybe lost if not waiting for the new session
cy.wait('@syncAfterRecovery', { timeout: 10000 })
cy.insertLine('* more content added after the lost connection')
cy.wait('@syncAfterRecovery', { timeout: 10000 })
cy.closeFile()
cy.testName()
.then(name => cy.downloadFile(`/${name}.md`))
.its('data')
.should('include', 'after the lost connection')
})
it('handles brief network outages', () => {
cy.intercept('**/apps/text/session/*/*', req => req.destroy()).as('dead')
cy.wait('@dead', { timeout: 30000 })
// bring back the network connection
cy.intercept('**/apps/text/session/*/*', req => { req.continue() }).as('alive')
cy.wait('@alive', { timeout: 30000 })
cy.getContent().type('staying alive')
cy.getContent().should('contain', 'staying alive')
})
it('reconnects via button after a short lost connection', () => {
cy.intercept('**/apps/text/session/*/*', req => req.destroy()).as('dead')
cy.wait('@dead', { timeout: 30000 })
cy.get('#editor-container .document-status', { timeout: 30000 })
.should('contain', 'The document could not be loaded.')
cy.get('#editor-container .document-status')
.find('.button.primary').click()
cy.get('#editor-container .document-status', { timeout: 30000 })
.should('contain', 'The document could not be loaded.')
// bring back the network connection
cy.intercept('**/apps/text/session/*/*', req => { req.continue() }).as('alive')
cy.intercept('**/apps/text/session/*/create').as('create')
cy.get('#editor-container .document-status')
.find('.button.primary').click()
cy.wait('@alive', { timeout: 30000 })
cy.wait('@create', { timeout: 10000 })
.its('request.body')
.should('have.property', 'baseVersionEtag')
.should('not.be.empty')
})
it('recovers from a lost and closed connection', () => {
let reconnect = false
// block all requests until the session is closed and reopened
cy.intercept('**/apps/text/session/*/*', (req) => {
if (req.url.includes('close') || req.url.includes('create') || reconnect) {
req.continue()
req.alias = 'syncAfterRecovery'
reconnect = true
} else {
req.destroy()
}
}).as('sessionRequests')
cy.wait('@sessionRequests', { timeout: 30000 })
cy.get('#editor-container .document-status', { timeout: 30000 })
.should('contain', 'The document could not be loaded.')
// Reconnect button works - it closes and reopens the session
cy.get('#editor-container .document-status a.button')
.contains('Reconnect')
.click()
cy.wait('@syncAfterRecovery', { timeout: 60000 })
cy.get('#editor-container .document-status', { timeout: 30000 })
.should('not.contain', 'The document could not be loaded.')
// FIXME: There seems to be a bug where typed words maybe lost if not waiting for the new session
cy.wait('@syncAfterRecovery', { timeout: 10000 })
cy.insertLine('* more content added after the lost connection')
cy.wait('@syncAfterRecovery', { timeout: 10000 })
cy.closeFile()
cy.testName()
.then(name => cy.downloadFile(`/${name}.md`))
.its('data')
.should('include', 'after the lost connection')
})
it('asks to reload page when document session got cleaned up', () => {
cy.get('.save-status button')
.click()
cy.wait('@save')
cy.uploadTestFile('test.md')
cy.get('#editor-container .document-status', { timeout: 30000 })
.should('contain', 'Editing session has expired.')
// Reload button works
cy.get('#editor-container .document-status a.button')
.contains('Reload')
.click()
cy.getContent()
cy.get('#editor-container .document-status .notecard')
.should('not.exist')
})
it('passes the doc content from one session to the next', () => {
cy.closeFile()
cy.intercept({ method: 'PUT', url: '**/apps/text/session/*/create' })
.as('create')
cy.openTestFile()
cy.wait('@create', { timeout: 10000 })
.its('response.body')
.should('have.property', 'documentState')
.should('not.be.empty')
cy.getContent().find('h2').should('contain', 'Hello world')
cy.getContent().find('li').should('contain', 'Saving the doc saves the doc state')
cy.getContent().type('recovered')
cy.closeFile()
})
// regression test #3834
it('close triggers one close request', () => {
cy.closeFile()
// Wait to make sure there is enough time for all close requests to run
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(100)
// reuse @close intercepted in closeFile()
cy.get('@close.all').should('have.length', 1)
})
})