diff --git a/src/model.ts b/src/model.ts index d785ed5822..a7b41c7635 100644 --- a/src/model.ts +++ b/src/model.ts @@ -284,7 +284,7 @@ export class Model extends EventBus implements CommandDispatcher { this.joinSession(); - if (config.snapshotRequested) { + if (config.snapshotRequested || (data["[Content_Types].xml"] && !this.getters.isReadonly())) { const startSnapshot = performance.now(); console.debug("Snapshot requested"); this.session.snapshot(this.exportData()); diff --git a/tests/model/model.test.ts b/tests/model/model.test.ts index aa42453a68..f72c410423 100644 --- a/tests/model/model.test.ts +++ b/tests/model/model.test.ts @@ -1,9 +1,12 @@ import { CommandResult, CorePlugin } from "../../src"; +import { MESSAGE_VERSION } from "../../src/constants"; import { toZone } from "../../src/helpers"; import { Model, ModelConfig } from "../../src/model"; import { corePluginRegistry, featurePluginRegistry } from "../../src/plugins/index"; import { UIPlugin } from "../../src/plugins/ui_plugin"; import { Command, CommandTypes, CoreCommand, DispatchResult, coreTypes } from "../../src/types"; +import { MockTransportService } from "../__mocks__/transport_service"; +import { getTextXlsxFiles } from "../__xlsx__/read_demo_xlsx"; import { setupCollaborativeEnv } from "../collaborative/collaborative_helpers"; import { copy, selectCell, setCellContent } from "../test_helpers/commands_helpers"; import { @@ -366,4 +369,33 @@ describe("Model", () => { ], }); }); + + test("it should snapshot when importing xlsx file", async () => { + const transport = new MockTransportService(); + const spy = jest.spyOn(transport, "sendMessage"); + const xlsxData = await getTextXlsxFiles(); + new Model(xlsxData, { + transportService: transport, + client: { id: "test", name: "Test" }, + }); + expect(spy).toHaveBeenCalledWith({ + type: "SNAPSHOT", + version: MESSAGE_VERSION, + nextRevisionId: expect.any(String), + serverRevisionId: "START_REVISION", + data: expect.any(Object), + }); + }); + + test("it should not snapshot when importing xlsx file in readonly mode", async () => { + const transport = new MockTransportService(); + const spy = jest.spyOn(transport, "sendMessage"); + const xlsxData = await getTextXlsxFiles(); + new Model(xlsxData, { + transportService: transport, + client: { id: "test", name: "Test" }, + mode: "readonly", + }); + expect(spy).not.toHaveBeenCalled(); + }); });