Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] model: create snapshot when loading xlsx file #5320

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class Model extends EventBus<any> 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());
Expand Down
32 changes: 32 additions & 0 deletions tests/model/model.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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();
});
});