Refactor ExtensionsStore (#1620)

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti authored and GitHub committed 2020-12-03 11:43:33 +02:00
1 parent 6630419457
commit 432b00b8cc
3 files changed
+57 -26

No files matched your search

@@ -1,9 +1,18 @@
import { ExtensionLoader } from "../extension-loader";
import { ipcRenderer } from "electron";
import { extensionsStore } from "../extensions-store";
const manifestPath = "manifest/path";
const manifestPath2 = "manifest/path2";
const manifestPath3 = "manifest/path3";
jest.mock("../extensions-store", () => ({
extensionsStore: {
whenLoaded: Promise.resolve(true),
mergeState: jest.fn()
}
}));
jest.mock(
"electron",
() => ({
@@ -129,4 +138,29 @@ describe("ExtensionLoader", () => {
done();
}, 10);
});
it("updates ExtensionsStore after isEnabled is changed", async () => {
(extensionsStore.mergeState as any).mockClear();
// Disable sending events in this test
(ipcRenderer.on as any).mockImplementation();
const extensionLoader = new ExtensionLoader();
await extensionLoader.init();
expect(extensionsStore.mergeState).not.toHaveBeenCalled();
Array.from(extensionLoader.userExtensions.values())[0].isEnabled = false;
expect(extensionsStore.mergeState).toHaveBeenCalledWith({
"manifest/path": {
enabled: false,
name: "TestExtension"
},
"manifest/path2": {
enabled: true,
name: "TestExtension2"
}});
});
});