Skip to content

Commit

Permalink
Merge pull request #3818 from nextcloud/fix/3817-fix-direct-editing-s…
Browse files Browse the repository at this point in the history
…ession

fix(DirectEditing): delay the initialSession so hooks can register
  • Loading branch information
max-nextcloud authored Feb 21, 2023
2 parents 98d05bc + 447905f commit faa8b69
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 32 deletions.
29 changes: 19 additions & 10 deletions cypress/e2e/directediting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,25 @@ describe('direct editing', function() {
})
const closeRequestAlias = 'closeRequest'
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)

cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')
cy.getContent()
.type('# This is a headline')
.type('{enter}')
.type('Some text')
.type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
cy.wait('@sync', { timeout: 7000 })

cy.get('button.icon-close').click()
cy.wait(`@${closeRequestAlias}`).then(() => {
cy.getFileContent('empty.md').then((content) => {
// FIXME: This currently fails due to the save not happening fast enough
// The best would be if we always send the markdown at least on close and perform a save if the content changed
// expect(content).to.equal('# This is a headline\n\nSome text');
expect(content).to.equal('# This is a headline\n\nSome text')
})
})
})

it('Create a file, edit and close it', () => {
createDirectEditingLinkForNewFile(user, 'newfile.md')
.then((token) => {
Expand All @@ -85,19 +88,22 @@ describe('direct editing', function() {
})
const closeRequestAlias = 'closeRequest'
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')

cy.getContent()
.type('# This is a headline')
.type('{enter}')
.type('Some text')
.type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
cy.wait('@sync', { timeout: 7000 })

cy.get('button.icon-close').click()
cy.wait(`@${closeRequestAlias}`).then(() => {
cy.getFileContent('newfile.md').then((content) => {
// FIXME: This currently fails due to the save not happening fast enough
// The best would be if we always send the markdown at least on close and perform a save if the content changed
// expect(content).to.equal('# This is a headline\n\nSome text');
expect(content).to.equal('# This is a headline\n\nSome text')
})
})
})
Expand All @@ -110,19 +116,22 @@ describe('direct editing', function() {
})
const closeRequestAlias = 'closeRequest'
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')

cy.getContent()
.type('# This is a headline')
.type('{enter}')
.type('Some text')
.type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
cy.wait('@sync', { timeout: 7000 })

cy.get('button.icon-close').click()
cy.wait(`@${closeRequestAlias}`).then(() => {
cy.getFileContent('empty.txt').then((content) => {
// FIXME: This currently fails due to the save not happening fast enough
// The best would be if we always send the markdown at least on close and perform a save if the content changed
// expect(content).to.equal('# This is a headline\n\nSome text');
expect(content).to.equal('# This is a headline\nSome text\n')
})
})
})
Expand Down
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/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.

10 changes: 6 additions & 4 deletions src/services/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ class SyncService {
this.sessions = sessions
})

// TODO: Only continue if a connection was made
this.connection = initialSession
? new Connection({ data: initialSession }, {})
: await this._api.open({ fileId })
const connect = initialSession
? Promise.resolve(new Connection({ data: initialSession }, {}))
: this._api.open({ fileId })
.catch(error => this._emitError(error))

// TODO: Only continue if a connection was made
this.connection = await connect

this.version = this.connection.lastSavedVersion
this.emit('opened', {
...this.connection.state,
Expand Down

0 comments on commit faa8b69

Please sign in to comment.