mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2025-07-27 08:00:06 +02:00

* [history-v1-ot] initial implementation of using doc-level history-v1-ot * [web] fix advancing of the otMigrationStage Use 'nextStage' for the user provided, desired stage when advancing. Co-authored-by: Brian Gough <brian.gough@overleaf.com> * [document-updater] document size check in editor-core * [history-ot] rename history-v1-ot to history-ot and add types * [history-ot] apply review feedback - remove extra !! - merge variable assignment when processing diff-match-match output - add helper function for getting docstore lines view of StringFileData Co-authored-by: Alf Eaton <alf.eaton@overleaf.com> * Revert "[document-updater] add safe rollback point for history-ot (#25283)" This reverts commit d7230dd14a379a27d2c6ab03a006463a18979d06 Signed-off-by: Jakob Ackermann <jakob.ackermann@overleaf.com> --------- Signed-off-by: Jakob Ackermann <jakob.ackermann@overleaf.com> Co-authored-by: Brian Gough <brian.gough@overleaf.com> Co-authored-by: Alf Eaton <alf.eaton@overleaf.com> GitOrigin-RevId: 89c497782adb0427635d50d02263d6f535b12481
292 lines
8.3 KiB
JavaScript
292 lines
8.3 KiB
JavaScript
/* eslint-disable
|
|
no-unused-vars,
|
|
*/
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
// Fix any style issues and re-enable lint.
|
|
/*
|
|
* decaffeinate suggestions:
|
|
* DS101: Remove unnecessary use of Array.from
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
* DS207: Consider shorter variations of null checks
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
*/
|
|
const { expect } = require('chai')
|
|
|
|
const RealTimeClient = require('./helpers/RealTimeClient')
|
|
const MockWebServer = require('./helpers/MockWebServer')
|
|
const FixturesManager = require('./helpers/FixturesManager')
|
|
|
|
const async = require('async')
|
|
|
|
describe('clientTracking', function () {
|
|
describe('when another logged in user joins a project', function () {
|
|
before(function (done) {
|
|
return async.series(
|
|
[
|
|
cb => {
|
|
return FixturesManager.setUpProject(
|
|
{
|
|
privilegeLevel: 'owner',
|
|
project: { name: 'Test Project' },
|
|
},
|
|
(error, { user_id: userId, project_id: projectId }) => {
|
|
if (error) return done(error)
|
|
this.user_id = userId
|
|
this.project_id = projectId
|
|
return cb()
|
|
}
|
|
)
|
|
},
|
|
|
|
cb => {
|
|
return FixturesManager.setUpDoc(
|
|
this.project_id,
|
|
{ lines: this.lines, version: this.version, ops: this.ops },
|
|
(e, { doc_id: docId }) => {
|
|
this.doc_id = docId
|
|
return cb(e)
|
|
}
|
|
)
|
|
},
|
|
|
|
cb => {
|
|
this.clientA = RealTimeClient.connect(this.project_id, cb)
|
|
},
|
|
|
|
cb => {
|
|
RealTimeClient.countConnectedClients(
|
|
this.project_id,
|
|
(err, body) => {
|
|
if (err) return cb(err)
|
|
expect(body).to.deep.equal({ nConnectedClients: 1 })
|
|
cb()
|
|
}
|
|
)
|
|
},
|
|
|
|
cb => {
|
|
this.clientB = RealTimeClient.connect(this.project_id, cb)
|
|
},
|
|
],
|
|
done
|
|
)
|
|
})
|
|
|
|
it('should record the initial state in getConnectedUsers', function (done) {
|
|
this.clientA.emit('clientTracking.getConnectedUsers', (error, users) => {
|
|
if (error) return done(error)
|
|
for (const user of Array.from(users)) {
|
|
if (user.client_id === this.clientB.publicId) {
|
|
expect(user.cursorData).to.not.exist
|
|
return done()
|
|
}
|
|
}
|
|
throw new Error('other user was never found')
|
|
})
|
|
})
|
|
it('should list both clients via HTTP', function (done) {
|
|
RealTimeClient.countConnectedClients(this.project_id, (err, body) => {
|
|
if (err) return done(err)
|
|
expect(body).to.deep.equal({ nConnectedClients: 2 })
|
|
done()
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('when a client updates its cursor location', function () {
|
|
before(function (done) {
|
|
return async.series(
|
|
[
|
|
cb => {
|
|
return FixturesManager.setUpProject(
|
|
{
|
|
privilegeLevel: 'owner',
|
|
project: { name: 'Test Project' },
|
|
},
|
|
(error, { user_id: userId, project_id: projectId }) => {
|
|
if (error) return done(error)
|
|
this.user_id = userId
|
|
this.project_id = projectId
|
|
return cb()
|
|
}
|
|
)
|
|
},
|
|
|
|
cb => {
|
|
return FixturesManager.setUpDoc(
|
|
this.project_id,
|
|
{ lines: this.lines, version: this.version, ops: this.ops },
|
|
(e, { doc_id: docId }) => {
|
|
this.doc_id = docId
|
|
return cb(e)
|
|
}
|
|
)
|
|
},
|
|
|
|
cb => {
|
|
this.clientA = RealTimeClient.connect(this.project_id, cb)
|
|
},
|
|
|
|
cb => {
|
|
this.clientB = RealTimeClient.connect(this.project_id, cb)
|
|
},
|
|
|
|
cb => {
|
|
return this.clientA.emit('joinDoc', this.doc_id, cb)
|
|
},
|
|
|
|
cb => {
|
|
this.updates = []
|
|
this.clientB.on('clientTracking.clientUpdated', data => {
|
|
return this.updates.push(data)
|
|
})
|
|
|
|
return this.clientA.emit(
|
|
'clientTracking.updatePosition',
|
|
{
|
|
row: (this.row = 42),
|
|
column: (this.column = 36),
|
|
doc_id: this.doc_id,
|
|
},
|
|
error => {
|
|
if (error != null) {
|
|
throw error
|
|
}
|
|
return setTimeout(cb, 300)
|
|
}
|
|
)
|
|
}, // Give the message a chance to reach client B.
|
|
],
|
|
done
|
|
)
|
|
})
|
|
|
|
it('should tell other clients about the update', function () {
|
|
return this.updates.should.deep.equal([
|
|
{
|
|
row: this.row,
|
|
column: this.column,
|
|
doc_id: this.doc_id,
|
|
id: this.clientA.publicId,
|
|
user_id: this.user_id,
|
|
name: 'Joe Bloggs',
|
|
},
|
|
])
|
|
})
|
|
|
|
return it('should record the update in getConnectedUsers', function (done) {
|
|
return this.clientB.emit(
|
|
'clientTracking.getConnectedUsers',
|
|
(error, users) => {
|
|
if (error) return done(error)
|
|
for (const user of Array.from(users)) {
|
|
if (user.client_id === this.clientA.publicId) {
|
|
expect(user.cursorData).to.deep.equal({
|
|
row: this.row,
|
|
column: this.column,
|
|
doc_id: this.doc_id,
|
|
})
|
|
return done()
|
|
}
|
|
}
|
|
throw new Error('user was never found')
|
|
}
|
|
)
|
|
})
|
|
})
|
|
|
|
return describe('when an anonymous client updates its cursor location', function () {
|
|
before(function (done) {
|
|
return async.series(
|
|
[
|
|
cb => {
|
|
return FixturesManager.setUpProject(
|
|
{
|
|
privilegeLevel: 'owner',
|
|
project: { name: 'Test Project' },
|
|
publicAccess: 'readAndWrite',
|
|
},
|
|
(
|
|
error,
|
|
{ user_id: userId, project_id: projectId, anonymousAccessToken }
|
|
) => {
|
|
if (error) return done(error)
|
|
this.user_id = userId
|
|
this.project_id = projectId
|
|
this.anonymousAccessToken = anonymousAccessToken
|
|
return cb()
|
|
}
|
|
)
|
|
},
|
|
|
|
cb => {
|
|
return FixturesManager.setUpDoc(
|
|
this.project_id,
|
|
{ lines: this.lines, version: this.version, ops: this.ops },
|
|
(e, { doc_id: docId }) => {
|
|
this.doc_id = docId
|
|
return cb(e)
|
|
}
|
|
)
|
|
},
|
|
|
|
cb => {
|
|
this.clientA = RealTimeClient.connect(this.project_id, cb)
|
|
},
|
|
|
|
cb => {
|
|
RealTimeClient.setAnonSession(
|
|
this.project_id,
|
|
this.anonymousAccessToken,
|
|
cb
|
|
)
|
|
},
|
|
|
|
cb => {
|
|
this.anonymous = RealTimeClient.connect(this.project_id, cb)
|
|
},
|
|
|
|
cb => {
|
|
return this.anonymous.emit('joinDoc', this.doc_id, cb)
|
|
},
|
|
|
|
cb => {
|
|
this.updates = []
|
|
this.clientA.on('clientTracking.clientUpdated', data => {
|
|
return this.updates.push(data)
|
|
})
|
|
|
|
return this.anonymous.emit(
|
|
'clientTracking.updatePosition',
|
|
{
|
|
row: (this.row = 42),
|
|
column: (this.column = 36),
|
|
doc_id: this.doc_id,
|
|
},
|
|
error => {
|
|
if (error != null) {
|
|
throw error
|
|
}
|
|
return setTimeout(cb, 300)
|
|
}
|
|
)
|
|
}, // Give the message a chance to reach client B.
|
|
],
|
|
done
|
|
)
|
|
})
|
|
|
|
return it('should tell other clients about the update', function () {
|
|
return this.updates.should.deep.equal([
|
|
{
|
|
row: this.row,
|
|
column: this.column,
|
|
doc_id: this.doc_id,
|
|
id: this.anonymous.publicId,
|
|
user_id: 'anonymous-user',
|
|
name: '',
|
|
},
|
|
])
|
|
})
|
|
})
|
|
})
|