diff --git a/cypress/e2e/conflict.spec.js b/cypress/e2e/conflict.spec.js index be75f1d2f26..a52b84c6f8b 100644 --- a/cypress/e2e/conflict.spec.js +++ b/cypress/e2e/conflict.spec.js @@ -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') + }) }) }) diff --git a/cypress/fixtures/lines.txt b/cypress/fixtures/lines.txt new file mode 100644 index 00000000000..3d13dc820ce --- /dev/null +++ b/cypress/fixtures/lines.txt @@ -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. diff --git a/src/components/CollisionResolveDialog.vue b/src/components/CollisionResolveDialog.vue index 6b4daecb8e7..e25f6a008dc 100644 --- a/src/components/CollisionResolveDialog.vue +++ b/src/components/CollisionResolveDialog.vue @@ -35,7 +35,7 @@ import { useEditorMixin, useIsRichEditorMixin, - useSyncServiceMixin + useSyncServiceMixin, } from './Editor.provider.js' import { NcButton } from '@nextcloud/vue' import setContent from './../mixins/setContent.js' diff --git a/src/components/Editor.vue b/src/components/Editor.vue index 1764f2e2c02..71376f664e0 100644 --- a/src/components/Editor.vue +++ b/src/components/Editor.vue @@ -522,7 +522,7 @@ export default { if (!documentState && documentSource) { this.setContent(documentSource, { isRich: this.isRichEditor, - addToHistory: false + addToHistory: false, }) } this.listenEditorEvents()