ClientTrackingTests.coffee 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. chai = require("chai")
  2. expect = chai.expect
  3. chai.should()
  4. RealTimeClient = require "./helpers/RealTimeClient"
  5. MockWebServer = require "./helpers/MockWebServer"
  6. FixturesManager = require "./helpers/FixturesManager"
  7. describe "clientTracking", ->
  8. before (done) ->
  9. FixturesManager.setUpProject {
  10. privilegeLevel: "owner"
  11. project: {
  12. name: "Test Project"
  13. }
  14. }, (error, data) =>
  15. throw error if error?
  16. {@user_id, @project_id} = data
  17. @clientA = RealTimeClient.connect()
  18. @clientB = RealTimeClient.connect()
  19. @clientA.emit "joinProject", {
  20. project_id: @project_id
  21. }, (error) =>
  22. throw error if error?
  23. @clientB.emit "joinProject", {
  24. project_id: @project_id
  25. }, (error) =>
  26. throw error if error?
  27. done()
  28. describe "when a client updates its cursor location", ->
  29. before (done) ->
  30. @updates = []
  31. @clientB.on "clientTracking.clientUpdated", (data) =>
  32. @updates.push data
  33. @clientA.emit "clientTracking.updatePosition", {
  34. row: @row = 42
  35. column: @column = 36
  36. doc_id: @doc_id = "mock-doc-id"
  37. }, (error) ->
  38. throw error if error?
  39. done()
  40. it "should tell other clients about the update", ->
  41. @updates.should.deep.equal [
  42. {
  43. row: @row
  44. column: @column
  45. doc_id: @doc_id
  46. id: @clientA.socket.sessionid
  47. user_id: @user_id
  48. name: "Joe Bloggs"
  49. }
  50. ]
  51. it "should record the update in getConnectedUsers", (done) ->
  52. @clientB.emit "clientTracking.getConnectedUsers", (error, users) =>
  53. for user in users
  54. if user.client_id == @clientA.socket.sessionid
  55. expect(user.cursorData).to.deep.equal({
  56. row: @row
  57. column: @column
  58. doc_id: @doc_id
  59. })
  60. return done()
  61. throw new Error("user was never found")
  62. describe "anonymous users", ->
  63. it "should test something..."