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