CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/sync/editor/string/test/ephemeral-syncstring.test.ts
Views: 791
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import ephemeralSyncstring from "./ephemeral-syncstring";
7
8
// This mostly tests the trivial minimal edge cases.
9
describe("create ephemeral syncstring and test managing undo/redo using it", () => {
10
it("creates ephemeral syncstring and tests undo/redo", async () => {
11
const syncstring = await ephemeralSyncstring();
12
syncstring.from_str("cocalc");
13
expect(syncstring.to_str()).toBe("cocalc");
14
await syncstring.save();
15
syncstring.from_str("cocalc and sagemath");
16
expect(syncstring.to_str()).toBe("cocalc and sagemath");
17
syncstring.undo();
18
expect(syncstring.to_str()).toBe("cocalc");
19
syncstring.undo();
20
expect(syncstring.to_str()).toBe("");
21
syncstring.redo();
22
expect(syncstring.to_str()).toBe("cocalc");
23
syncstring.redo();
24
expect(syncstring.to_str()).toBe("cocalc and sagemath");
25
await syncstring.close();
26
});
27
28
it("illustrates how you have to use save to get a step in the undo/redo", async () => {
29
const syncstring = await ephemeralSyncstring();
30
syncstring.from_str("cocalc");
31
expect(syncstring.to_str()).toBe("cocalc");
32
syncstring.from_str("cocalc and sagemath");
33
expect(syncstring.to_str()).toBe("cocalc and sagemath");
34
syncstring.undo();
35
expect(syncstring.to_str()).toBe("");
36
syncstring.redo();
37
expect(syncstring.to_str()).toBe("cocalc and sagemath");
38
await syncstring.close();
39
});
40
});
41
42