Skip to content

Commit 89997d8

Browse files
max-nextcloudmejo-
authored andcommitted
test(cypress): conflict handling with plain text files
Signed-off-by: Max <[email protected]>
1 parent 037bf89 commit 89997d8

File tree

4 files changed

+107
-114
lines changed

4 files changed

+107
-114
lines changed

cypress/e2e/conflict.spec.js

Lines changed: 98 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -23,118 +23,104 @@
2323
import { initUserAndFiles, randUser } from '../utils/index.js'
2424

2525
const user = randUser()
26-
const fileName = 'test.md'
2726

28-
describe('Open test.md in viewer', function() {
29-
const getWrapper = () => cy.get('.text-editor__wrapper.has-conflicts.is-rich-editor')
30-
31-
before(() => {
32-
initUserAndFiles(user, fileName)
33-
})
34-
35-
beforeEach(function() {
36-
cy.login(user)
37-
cy.visit('/apps/files')
38-
})
39-
40-
it('displays conflicts', function() {
41-
cy.openFile(fileName)
42-
43-
cy.log('Inspect editor')
44-
cy.getContent()
45-
.type('Hello you cruel conflicting world')
46-
cy.uploadFile('test.md', 'text/markdown')
47-
48-
cy.get('#viewer .modal-header button.header-close').click()
49-
cy.get('#viewer').should('not.exist')
50-
cy.openFile('test.md')
51-
cy.get('.text-editor .document-status .icon-error')
52-
getWrapper()
53-
.get('#read-only-editor h2')
54-
.should('contain', 'Hello world')
55-
getWrapper()
56-
.get('.text-editor__main h2')
57-
.should('contain', 'Hello world')
58-
getWrapper()
59-
.get('.text-editor__main')
60-
.should('contain', 'cruel conflicting')
61-
cy.screenshot()
62-
})
63-
64-
it('resolves conflict using current editing session', function() {
65-
cy.openFile(fileName)
66-
67-
cy.log('Inspect editor')
68-
cy.getContent()
69-
.type('Hello you cruel conflicting world')
70-
cy.uploadFile('test.md', 'text/markdown')
71-
72-
cy.get('#viewer .modal-header button.header-close').click()
73-
cy.get('#viewer').should('not.exist')
74-
cy.openFile('test.md')
75-
cy.get('.text-editor .document-status .icon-error')
76-
getWrapper()
77-
.get('#read-only-editor h2')
78-
.should('contain', 'Hello world')
79-
getWrapper()
80-
.get('.text-editor__main h2')
81-
.should('contain', 'Hello world')
82-
getWrapper()
83-
.get('.text-editor__main')
84-
.should('contain', 'cruel conflicting')
85-
86-
cy.get('[data-cy="resolveThisVersion"]').click()
87-
88-
getWrapper()
89-
.get('#read-only-editor')
90-
.should('not.exist')
91-
92-
cy.get('[data-cy="resolveThisVersion"]')
93-
.should('not.exist')
94-
95-
cy.get('.text-editor__main h2')
96-
.should('contain', 'Hello world')
97-
cy.get('.text-editor__main')
98-
.should('contain', 'cruel conflicting')
99-
})
100-
101-
it('resolves conflict using server version', function() {
102-
cy.openFile(fileName)
103-
104-
cy.log('Inspect editor')
105-
cy.getContent()
106-
.type('Hello you cruel conflicting world')
107-
cy.uploadFile('test.md', 'text/markdown')
108-
109-
cy.get('#viewer .modal-header button.header-close').click()
110-
cy.get('#viewer').should('not.exist')
111-
cy.openFile('test.md')
112-
cy.get('.text-editor .document-status .icon-error')
113-
getWrapper()
114-
.get('#read-only-editor h2')
115-
.should('contain', 'Hello world')
116-
getWrapper()
117-
.get('.text-editor__main h2')
118-
.should('contain', 'Hello world')
119-
getWrapper()
120-
.get('.text-editor__main')
121-
.should('contain', 'cruel conflicting')
122-
123-
getWrapper()
124-
.get('[data-cy="resolveServerVersion"]')
125-
.click()
126-
127-
getWrapper()
128-
.get('#read-only-editor')
129-
.should('not.exist')
130-
cy.get('[data-cy="resolveThisVersion"]')
131-
.should('not.exist')
132-
cy.get('[data-cy="resolveServerVersion"]')
133-
.should('not.exist')
134-
135-
cy.get('.text-editor__main h2')
136-
.should('contain', 'Hello world')
137-
cy.get('.text-editor__main')
138-
.should('not.contain', 'cruel conflicting')
27+
const variants = [
28+
{ fixture: 'lines.txt', mime: 'text/plain' },
29+
{ fixture: 'test.md', mime: 'text/markdown' },
30+
]
31+
32+
variants.forEach(function({ fixture, mime }) {
33+
const fileName = fixture
34+
describe(`${mime} (${fileName})`, function() {
35+
const getWrapper = () => cy.get('.text-editor__wrapper.has-conflicts')
36+
37+
before(() => {
38+
initUserAndFiles(user, fileName)
39+
})
40+
41+
beforeEach(function() {
42+
cy.login(user)
43+
cy.visit('/apps/files')
44+
})
45+
46+
it('displays conflicts', function() {
47+
cy.openFile(fileName)
48+
49+
cy.log('Inspect editor')
50+
cy.getContent()
51+
.type('Hello you cruel conflicting world')
52+
cy.uploadFile(fileName, mime)
53+
54+
cy.get('#viewer .modal-header button.header-close').click()
55+
cy.get('#viewer').should('not.exist')
56+
cy.openFile(fileName)
57+
cy.get('.text-editor .document-status .icon-error')
58+
getWrapper()
59+
.get('#read-only-editor')
60+
.should('contain', 'Hello world')
61+
getWrapper()
62+
.get('.text-editor__main')
63+
.should('contain', 'Hello world')
64+
getWrapper()
65+
.get('.text-editor__main')
66+
.should('contain', 'cruel conflicting')
67+
})
68+
69+
it('resolves conflict using current editing session', function() {
70+
cy.openFile(fileName)
71+
72+
cy.log('Inspect editor')
73+
cy.getContent()
74+
.type('Hello you cruel conflicting world')
75+
cy.uploadFile(fileName, mime)
76+
77+
cy.get('#viewer .modal-header button.header-close').click()
78+
cy.get('#viewer').should('not.exist')
79+
cy.openFile(fileName)
80+
81+
cy.get('[data-cy="resolveThisVersion"]').click()
82+
83+
getWrapper()
84+
.get('#read-only-editor')
85+
.should('not.exist')
86+
87+
cy.get('[data-cy="resolveThisVersion"]')
88+
.should('not.exist')
89+
90+
cy.get('.text-editor__main')
91+
.should('contain', 'Hello world')
92+
cy.get('.text-editor__main')
93+
.should('contain', 'cruel conflicting')
94+
})
95+
96+
it('resolves conflict using server version', function() {
97+
cy.openFile(fileName)
98+
99+
cy.log('Inspect editor')
100+
cy.getContent()
101+
.type('Hello you cruel conflicting world')
102+
cy.uploadFile(fileName, mime)
103+
104+
cy.get('#viewer .modal-header button.header-close').click()
105+
cy.get('#viewer').should('not.exist')
106+
cy.openFile(fileName)
107+
108+
getWrapper()
109+
.get('[data-cy="resolveServerVersion"]')
110+
.click()
111+
112+
getWrapper()
113+
.get('#read-only-editor')
114+
.should('not.exist')
115+
cy.get('[data-cy="resolveThisVersion"]')
116+
.should('not.exist')
117+
cy.get('[data-cy="resolveServerVersion"]')
118+
.should('not.exist')
119+
120+
cy.get('.text-editor__main')
121+
.should('contain', 'Hello world')
122+
cy.get('.text-editor__main')
123+
.should('not.contain', 'cruel conflicting')
124+
})
139125
})
140126
})

cypress/fixtures/lines.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This file contains multiple lines
2+
3+
Hello world
4+
5+
It's a text file so it should not be parsed as markdown
6+
7+
But when it is these would turn into paragraphs.

src/components/CollisionResolveDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import {
3636
useEditorMixin,
3737
useIsRichEditorMixin,
38-
useSyncServiceMixin
38+
useSyncServiceMixin,
3939
} from './Editor.provider.js'
4040
import { NcButton } from '@nextcloud/vue'
4141
import setContent from './../mixins/setContent.js'

src/components/Editor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ export default {
526526
if (!documentState && documentSource) {
527527
this.setContent(documentSource, {
528528
isRich: this.isRichEditor,
529-
addToHistory: false
529+
addToHistory: false,
530530
})
531531
}
532532
this.listenEditorEvents()

0 commit comments

Comments
 (0)