Skip to content

Commit 58526f4

Browse files
committed
Add tests to check migration behaviour.
1 parent 25ed17e commit 58526f4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/unit-tests/settings/SettingsStore-test.ts

+42
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,47 @@ describe("SettingsStore", () => {
139139

140140
expect(room.getAccountData).not.toHaveBeenCalled();
141141
});
142+
143+
describe("Migrate media preview configuration", () => {
144+
beforeEach(() => {
145+
client.getAccountData = jest.fn().mockImplementation((type) => {
146+
if (type === "im.vector.web.settings") {
147+
return {
148+
getContent: jest.fn().mockReturnValue({
149+
showImages: false,
150+
showAvatarsOnInvites: false,
151+
}),
152+
};
153+
} else {
154+
return undefined;
155+
}
156+
});
157+
});
158+
159+
it("migrates media preview configuration", async () => {
160+
client.setAccountData = jest.fn();
161+
SettingsStore.runMigrations(false);
162+
client.emit(ClientEvent.Sync, SyncState.Prepared, null);
163+
expect(client.setAccountData).toHaveBeenCalledWith("io.element.msc4278.media_preview_config", {
164+
invite_avatars: "off",
165+
media_previews: "off",
166+
});
167+
});
168+
169+
it("does not migrate media preview configuration if the session is fresh", async () => {
170+
client.setAccountData = jest.fn();
171+
SettingsStore.runMigrations(true);
172+
client.emit(ClientEvent.Sync, SyncState.Prepared, null);
173+
expect(client.setAccountData).not.toHaveBeenCalled();
174+
});
175+
176+
it("does not migrate media preview configuration if the account data is already set", async () => {
177+
client.setAccountData = jest.fn();
178+
client.getAccountData = jest.fn().mockReturnValue({});
179+
SettingsStore.runMigrations(false);
180+
client.emit(ClientEvent.Sync, SyncState.Prepared, null);
181+
expect(client.setAccountData).not.toHaveBeenCalled();
182+
});
183+
});
142184
});
143185
});

0 commit comments

Comments
 (0)