forked from FirebaseExtended/firepad
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathremote-client.spec.ts
52 lines (45 loc) · 1.57 KB
/
remote-client.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Cursor } from "../src/cursor";
import { UserIDType } from "../src/database-adapter";
import { IEditorAdapter } from "../src/editor-adapter";
import { IRemoteClient, RemoteClient } from "../src/remote-client";
import { getEditorAdapter, IEditorAdapterMock } from "./factory";
describe("Remote Client", () => {
let clientId: UserIDType;
let remoteClient: IRemoteClient;
let editorAdapter: IEditorAdapterMock;
beforeAll(() => {
clientId = Math.round(Math.random() * 100);
editorAdapter = getEditorAdapter();
remoteClient = new RemoteClient(clientId, editorAdapter as IEditorAdapter);
});
describe("#setColor", () => {
it("should set cursor/selection color for remote user", () => {
const fn = () => remoteClient.setColor("#fff");
expect(fn).not.toThrowError();
});
});
describe("#setUserName", () => {
it("should set name/short-name for remote user", () => {
const fn = () => remoteClient.setUserName("Robin");
expect(fn).not.toThrowError();
});
});
describe("#updateCursor", () => {
it("should update cursor/selection position for remote user", () => {
const userCursor = new Cursor(5, 8);
remoteClient.updateCursor(userCursor);
expect(editorAdapter.setOtherCursor).toHaveBeenCalledWith(
clientId,
userCursor,
"#fff",
"Robin"
);
});
});
describe("#removeCursor", () => {
it("should remove cursor/selection for remote user", () => {
remoteClient.removeCursor();
expect(editorAdapter.disposeCursor).toHaveBeenCalled();
});
});
});