Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] fix: handle non markdown files in conflicts #4272

Merged
merged 5 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/files-modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/files-modal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading