Skip to content

Commit 7203c31

Browse files
committed
test(cypress): conflict handling with plain text files
Signed-off-by: Max <max@nextcloud.com>
1 parent 8d877ba commit 7203c31

2 files changed

Lines changed: 106 additions & 112 deletions

File tree

cypress/e2e/conflict.spec.js

Lines changed: 99 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -23,118 +23,105 @@
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+
33+
variants.forEach(function({ fixture, mime }) {
34+
const fileName = fixture
35+
describe(`${mime} (${fileName})`, function() {
36+
const getWrapper = () => cy.get('.text-editor__wrapper.has-conflicts')
37+
38+
before(() => {
39+
initUserAndFiles(user, fileName)
40+
})
41+
42+
beforeEach(function() {
43+
cy.login(user)
44+
cy.visit('/apps/files')
45+
})
46+
47+
it('displays conflicts', function() {
48+
cy.openFile(fileName)
49+
50+
cy.log('Inspect editor')
51+
cy.getContent()
52+
.type('Hello you cruel conflicting world')
53+
cy.uploadFile(fileName, mime)
54+
55+
cy.get('#viewer .modal-header button.header-close').click()
56+
cy.get('#viewer').should('not.exist')
57+
cy.openFile(fileName)
58+
cy.get('.text-editor .document-status .icon-error')
59+
getWrapper()
60+
.get('#read-only-editor')
61+
.should('contain', 'Hello world')
62+
getWrapper()
63+
.get('.text-editor__main')
64+
.should('contain', 'Hello world')
65+
getWrapper()
66+
.get('.text-editor__main')
67+
.should('contain', 'cruel conflicting')
68+
})
69+
70+
it('resolves conflict using current editing session', function() {
71+
cy.openFile(fileName)
72+
73+
cy.log('Inspect editor')
74+
cy.getContent()
75+
.type('Hello you cruel conflicting world')
76+
cy.uploadFile(fileName, mime)
77+
78+
cy.get('#viewer .modal-header button.header-close').click()
79+
cy.get('#viewer').should('not.exist')
80+
cy.openFile(fileName)
81+
82+
cy.get('[data-cy="resolveThisVersion"]').click()
83+
84+
getWrapper()
85+
.get('#read-only-editor')
86+
.should('not.exist')
87+
88+
cy.get('[data-cy="resolveThisVersion"]')
89+
.should('not.exist')
90+
91+
cy.get('.text-editor__main')
92+
.should('contain', 'Hello world')
93+
cy.get('.text-editor__main')
94+
.should('contain', 'cruel conflicting')
95+
})
96+
97+
it('resolves conflict using server version', function() {
98+
cy.openFile(fileName)
99+
100+
cy.log('Inspect editor')
101+
cy.getContent()
102+
.type('Hello you cruel conflicting world')
103+
cy.uploadFile(fileName, mime)
104+
105+
cy.get('#viewer .modal-header button.header-close').click()
106+
cy.get('#viewer').should('not.exist')
107+
cy.openFile(fileName)
108+
109+
getWrapper()
110+
.get('[data-cy="resolveServerVersion"]')
111+
.click()
112+
113+
getWrapper()
114+
.get('#read-only-editor')
115+
.should('not.exist')
116+
cy.get('[data-cy="resolveThisVersion"]')
117+
.should('not.exist')
118+
cy.get('[data-cy="resolveServerVersion"]')
119+
.should('not.exist')
120+
121+
cy.get('.text-editor__main')
122+
.should('contain', 'Hello world')
123+
cy.get('.text-editor__main')
124+
.should('not.contain', 'cruel conflicting')
125+
})
139126
})
140127
})

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.

0 commit comments

Comments
 (0)