Skip to content
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
39 changes: 28 additions & 11 deletions cypress/e2e/sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { randUser } from '../utils/index.js'

const user = randUser()

describe('yjs document state', () => {
describe('Save', () => {
before(() => {
cy.createUser(user)
})
Expand All @@ -33,31 +33,38 @@ describe('yjs document state', () => {
cy.login(user)
cy.uploadTestFile('test.md')
cy.visit('/apps/files')
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }, (req) => {
if (req.body.autosaveContent) {
req.alias = 'save'
}
}).as('sync')
cy.openTestFile()
cy.getContent().find('h2').should('contain', 'Hello world')
cy.wait('@sync', { timeout: 7000 })
cy.getContent().type('* Saving the doc saves the doc state{enter}')
cy.wait('@sync', { timeout: 7000 })
})

it('saves the actual file and document state', () => {
cy.getContent().type('{ctrl+s}')
cy.wait('@sync').its('request.body')
.should('have.property', 'autosaveContent')
cy.wait('@save').its('request.body')
.should('have.property', 'documentState')
.should('not.be.empty')
cy.testName()
.then(name => cy.downloadFile(`/${name}.md`))
.its('data')
.should('include', 'saves the doc state')
cy.closeFile()
})

it('saves on close', () => {
cy.closeFile()
cy.wait('@save')
cy.testName()
.then(name => cy.downloadFile(`/${name}.md`))
.its('data')
.should('include', 'saves the doc state')
})

it('passes the doc content from one session to the next', () => {
cy.getContent().type('{ctrl+s}')
cy.wait('@sync').its('request.body')
.should('have.property', 'documentState')
.should('not.be.empty')
cy.closeFile()
cy.intercept({ method: 'PUT', url: '**/apps/text/session/create' })
.as('create')
Expand All @@ -66,10 +73,20 @@ describe('yjs document state', () => {
.its('response.body')
.should('have.property', 'content')
.should('not.be.empty')
cy.wait('@sync').its('request.body').should('have.property', 'version')
cy.getContent().find('h2').should('contain', 'Hello world')
cy.getContent().find('li').should('contain', 'Saving the doc saves the doc state')
cy.getContent().type('recovered')
cy.closeFile()
})

// regression test #3834
it('close triggers one close request', () => {
cy.closeFile()
// Wait to make sure there is enough time for all close requests to run
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(100)
// reuse @close intercepted in closeFile()
cy.get('@close.all').should('have.length', 1)
})

})
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.

4 changes: 2 additions & 2 deletions js/text-editors.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-editors.js.map

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ export default {
window.removeEventListener('afterprint', this.preparePrinting)
}
this.$providers.forEach(p => p.destroy())
this.close()
},
methods: {
...mapActions('text', [
Expand Down
22 changes: 4 additions & 18 deletions src/services/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,11 @@ class SyncService {
return this.save({ manualSave: false })
}

close() {
async close() {
this.backend.disconnect()
let closed = false
return new Promise((resolve, reject) => {
this.on('save', () => {
this._close().then(() => {
closed = true
resolve()
}).catch(() => resolve())
})
setTimeout(() => {
if (!closed) {
this._close().then(() => {
resolve()
}).catch(() => resolve())
}
}, 2000)
this.save()
})
const timeout = new Promise((resolve) => setTimeout(resolve, 2000))
await Promise.any([timeout, this.save()])
return this._close()
}

_close() {
Expand Down