Skip to content

Commit

Permalink
test(cypress): conflict handling with plain text files
Browse files Browse the repository at this point in the history
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud authored and juliushaertl committed Jun 22, 2023
1 parent 5a37236 commit f0efbc2
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 114 deletions.
210 changes: 98 additions & 112 deletions cypress/e2e/conflict.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,118 +23,104 @@
import { initUserAndFiles, randUser } from '../utils/index.js'

const user = randUser()
const fileName = 'test.md'

describe('Open test.md in viewer', function() {
const getWrapper = () => cy.get('.text-editor__wrapper.has-conflicts.is-rich-editor')

before(() => {
initUserAndFiles(user, fileName)
})

beforeEach(function() {
cy.login(user)
cy.visit('/apps/files')
})

it('displays conflicts', function() {
cy.openFile(fileName)

cy.log('Inspect editor')
cy.getContent()
.type('Hello you cruel conflicting world')
cy.uploadFile('test.md', 'text/markdown')

cy.get('#viewer .modal-header button.header-close').click()
cy.get('#viewer').should('not.exist')
cy.openFile('test.md')
cy.get('.text-editor .document-status .icon-error')
getWrapper()
.get('#read-only-editor h2')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main h2')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main')
.should('contain', 'cruel conflicting')
cy.screenshot()
})

it('resolves conflict using current editing session', function() {
cy.openFile(fileName)

cy.log('Inspect editor')
cy.getContent()
.type('Hello you cruel conflicting world')
cy.uploadFile('test.md', 'text/markdown')

cy.get('#viewer .modal-header button.header-close').click()
cy.get('#viewer').should('not.exist')
cy.openFile('test.md')
cy.get('.text-editor .document-status .icon-error')
getWrapper()
.get('#read-only-editor h2')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main h2')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main')
.should('contain', 'cruel conflicting')

cy.get('[data-cy="resolveThisVersion"]').click()

getWrapper()
.get('#read-only-editor')
.should('not.exist')

cy.get('[data-cy="resolveThisVersion"]')
.should('not.exist')

cy.get('.text-editor__main h2')
.should('contain', 'Hello world')
cy.get('.text-editor__main')
.should('contain', 'cruel conflicting')
})

it('resolves conflict using server version', function() {
cy.openFile(fileName)

cy.log('Inspect editor')
cy.getContent()
.type('Hello you cruel conflicting world')
cy.uploadFile('test.md', 'text/markdown')

cy.get('#viewer .modal-header button.header-close').click()
cy.get('#viewer').should('not.exist')
cy.openFile('test.md')
cy.get('.text-editor .document-status .icon-error')
getWrapper()
.get('#read-only-editor h2')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main h2')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main')
.should('contain', 'cruel conflicting')

getWrapper()
.get('[data-cy="resolveServerVersion"]')
.click()

getWrapper()
.get('#read-only-editor')
.should('not.exist')
cy.get('[data-cy="resolveThisVersion"]')
.should('not.exist')
cy.get('[data-cy="resolveServerVersion"]')
.should('not.exist')

cy.get('.text-editor__main h2')
.should('contain', 'Hello world')
cy.get('.text-editor__main')
.should('not.contain', 'cruel conflicting')
const variants = [
{ fixture: 'lines.txt', mime: 'text/plain' },
{ fixture: 'test.md', mime: 'text/markdown' },
]

variants.forEach(function({ fixture, mime }) {
const fileName = fixture
describe(`${mime} (${fileName})`, function() {
const getWrapper = () => cy.get('.text-editor__wrapper.has-conflicts')

before(() => {
initUserAndFiles(user, fileName)
})

beforeEach(function() {
cy.login(user)
cy.visit('/apps/files')
})

it('displays conflicts', function() {
cy.openFile(fileName)

cy.log('Inspect editor')
cy.getContent()
.type('Hello you cruel conflicting world')
cy.uploadFile(fileName, mime)

cy.get('#viewer .modal-header button.header-close').click()
cy.get('#viewer').should('not.exist')
cy.openFile(fileName)
cy.get('.text-editor .document-status .icon-error')
getWrapper()
.get('#read-only-editor')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main')
.should('contain', 'cruel conflicting')
})

it('resolves conflict using current editing session', function() {
cy.openFile(fileName)

cy.log('Inspect editor')
cy.getContent()
.type('Hello you cruel conflicting world')
cy.uploadFile(fileName, mime)

cy.get('#viewer .modal-header button.header-close').click()
cy.get('#viewer').should('not.exist')
cy.openFile(fileName)

cy.get('[data-cy="resolveThisVersion"]').click()

getWrapper()
.get('#read-only-editor')
.should('not.exist')

cy.get('[data-cy="resolveThisVersion"]')
.should('not.exist')

cy.get('.text-editor__main')
.should('contain', 'Hello world')
cy.get('.text-editor__main')
.should('contain', 'cruel conflicting')
})

it('resolves conflict using server version', function() {
cy.openFile(fileName)

cy.log('Inspect editor')
cy.getContent()
.type('Hello you cruel conflicting world')
cy.uploadFile(fileName, mime)

cy.get('#viewer .modal-header button.header-close').click()
cy.get('#viewer').should('not.exist')
cy.openFile(fileName)

getWrapper()
.get('[data-cy="resolveServerVersion"]')
.click()

getWrapper()
.get('#read-only-editor')
.should('not.exist')
cy.get('[data-cy="resolveThisVersion"]')
.should('not.exist')
cy.get('[data-cy="resolveServerVersion"]')
.should('not.exist')

cy.get('.text-editor__main')
.should('contain', 'Hello world')
cy.get('.text-editor__main')
.should('not.contain', 'cruel conflicting')
})
})
})
7 changes: 7 additions & 0 deletions cypress/fixtures/lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This file contains multiple lines

Hello world

It's a text file so it should not be parsed as markdown

But when it is these would turn into paragraphs.
2 changes: 1 addition & 1 deletion src/components/CollisionResolveDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import {
useEditorMixin,
useIsRichEditorMixin,
useSyncServiceMixin
useSyncServiceMixin,
} from './Editor.provider.js'
import { NcButton } from '@nextcloud/vue'
import setContent from './../mixins/setContent.js'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ export default {
if (!documentState && documentSource) {
this.setContent(documentSource, {
isRich: this.isRichEditor,
addToHistory: false
addToHistory: false,
})
}
this.listenEditorEvents()
Expand Down

0 comments on commit f0efbc2

Please sign in to comment.