-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathconflict.spec.js
More file actions
169 lines (142 loc) Β· 4.61 KB
/
Copy pathconflict.spec.js
File metadata and controls
169 lines (142 loc) Β· 4.61 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
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { randUser } from '../utils/index.js'
const variants = [
{ fixture: 'lines.txt', mime: 'text/plain' },
{ fixture: 'test.md', mime: 'text/markdown' },
]
const getWrapper = () => cy.get('.text-editor__wrapper.has-conflicts')
variants.forEach(function({ fixture, mime }) {
const user = randUser()
const fileName = fixture
const prefix = mime.replaceAll('/', '-')
describe(`${mime} (${fileName})`, function() {
before(() => {
cy.createUser(user)
})
beforeEach(function() {
cy.login(user)
cy.createTestFolder()
})
it(prefix + ': no actual conflict - just reload', function() {
cy.testName().then(testName => {
// start with different content
cy.uploadFile('frontmatter.md', mime, `${testName}/${fileName}`)
// just a read only session opened
cy.shareFile(`${testName}/${fileName}`)
.then((token) => {
cy.visit(`/s/${token}`)
})
cy.getContent().should('contain', 'Heading')
cy.uploadFile(fileName, mime, testName + '/' + fileName)
cy.get('#editor-container .document-status', { timeout: 40000 })
.should('contain', 'session has expired')
// Reload button works
cy.get('#editor-container .document-status a.button')
.contains('Reload')
.click()
getWrapper().should('not.exist')
cy.getContent().should('contain', 'Hello world')
cy.getContent().should('not.contain', 'Heading')
})
})
it(prefix + ': displays conflicts', function() {
createConflict(fileName, mime)
cy.openFile(fileName)
cy.get('.text-editor .document-status')
.should('contain', 'The file was overwritten.')
getWrapper()
.find('#read-only-editor')
.should('contain', 'Hello world')
getWrapper()
.find('.text-editor__main')
.should('contain', 'Hello world')
getWrapper()
.find('.text-editor__main')
.should('contain', 'cruel conflicting')
})
it(prefix + ': resolves conflict using current editing session', function() {
createConflict(fileName, mime)
cy.openFile(fileName)
cy.intercept({ method: 'POST', url: '**/session/*/push' })
.as('push')
cy.wait('@push')
cy.get('[data-cy="resolveThisVersion"]').click()
getWrapper().should('not.exist')
cy.get('[data-cy="resolveThisVersion"]')
.should('not.exist')
cy.getContent().should('contain', 'Hello world')
cy.getContent().should('contain', 'cruel conflicting')
})
it(prefix + ': resolves conflict using server version', function() {
createConflict(fileName, mime)
cy.openFile(fileName)
cy.get('[data-cy="resolveServerVersion"]')
.click()
getWrapper().should('not.exist')
cy.get('[data-cy="resolveThisVersion"]')
.should('not.exist')
cy.get('[data-cy="resolveServerVersion"]')
.should('not.exist')
cy.getContent().should('contain', 'Hello world')
cy.getContent().should('not.contain', 'cruel conflicting')
})
it(prefix + ': hides conflict in read only session', function() {
createConflict(fileName, mime)
cy.testName().then(testName => {
cy.shareFile(`/${testName}/${fileName}`)
.then((token) => {
cy.logout()
cy.visit(`/s/${token}`)
})
})
cy.getContent().should('contain', 'cruel conflicting')
getWrapper().should('not.exist')
})
})
})
describe('conflict dialog scroll behaviour', function() {
const user = randUser()
const fileName = 'long.md'
before(() => {
cy.createUser(user)
})
it('document status and collision resolution dialog elements are sticky', function() {
cy.login(user)
cy.createTestFolder()
createConflict(fileName, 'text/markdown')
cy.openFile(fileName)
cy.get('.text-editor .document-status')
.should('contain', 'The file was overwritten.')
getWrapper()
.find('.text-editor__main h2')
.contains('Third subheading')
.scrollIntoView()
cy.get('.text-editor #resolve-conflicts')
.should('be.visible')
cy.get('.text-editor .document-status')
.should('be.visible')
})
})
/**
* @param {string} fileName - filename
* @param {string} mime - mimetype
*/
function createConflict(fileName, mime) {
cy.testName().then(testName => {
cy.uploadFile(fileName, mime, `${testName}/${fileName}`)
})
cy.visitTestFolder()
cy.openFile(fileName)
cy.log('Inspect editor')
cy.getEditor().find('.ProseMirror').should('have.attr', 'contenteditable', 'true')
cy.getContent()
.type('Hello you cruel conflicting world')
cy.testName().then(testName => {
cy.uploadFile(fileName, mime, testName + '/' + fileName)
})
cy.get('#viewer .modal-header button.header-close').click()
cy.get('#viewer').should('not.exist')
}