Clean up electron-store based stores

- Add some type script types for better editor experience
- Remove redundent global of a singleton

Signed-off-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
Sebastian Malton committed 2020-06-23 12:31:31 -04:00
1 parent cd66a985cc
commit 97645f4327
17 files changed
+87 -107

No files matched your search

+5 -5
View File
@@ -197,7 +197,7 @@ describe("for a pre 2.0 config with an existing cluster", () => {
it("migrates to modern format with kubeconfig under a key", async () => {
const clusterStore = ClusterStore.getInstance()
const storedCluster = clusterStore.store.get('clusters')[0]
const storedCluster = clusterStore.getAllClusters()[0]
expect(storedCluster.kubeConfig).toBe('kubeconfig content')
})
})
@@ -231,7 +231,7 @@ describe("for a pre 2.4.1 config with an existing cluster", () => {
it("migrates to modern format throwing out the state related data", async () => {
const clusterStore = ClusterStore.getInstance()
const storedClusterData = clusterStore.store.get('clusters')[0]
const storedClusterData = clusterStore.getAllClusters()[0]
expect(storedClusterData.hasOwnProperty('online')).toBe(false)
expect(storedClusterData.hasOwnProperty('accessible')).toBe(false)
expect(storedClusterData.hasOwnProperty('failureReason')).toBe(false)
@@ -264,7 +264,7 @@ describe("for a pre 2.6.0 config with a cluster that has arrays in auth config",
it("replaces array format access token and expiry into string", async () => {
const clusterStore = ClusterStore.getInstance()
const storedClusterData = clusterStore.store.get('clusters')[0]
const storedClusterData = clusterStore.getAllClusters()[0]
const kc = yaml.safeLoad(storedClusterData.kubeConfig)
expect(kc.users[0].user['auth-provider'].config['access-token']).toBe("should be string")
expect(kc.users[0].user['auth-provider'].config['expiry']).toBe("should be string")
@@ -301,7 +301,7 @@ describe("for a pre 2.6.0 config with a cluster icon", () => {
it("moves the icon into preferences", async () => {
const clusterStore = ClusterStore.getInstance()
const storedClusterData = clusterStore.store.get('clusters')[0]
const storedClusterData = clusterStore.getAllClusters()[0]
expect(storedClusterData.hasOwnProperty('icon')).toBe(false)
expect(storedClusterData.preferences.hasOwnProperty('icon')).toBe(true)
expect(storedClusterData.preferences.icon).toBe("icon path")
@@ -338,7 +338,7 @@ describe("for a pre 2.7.0-beta.0 config without a workspace", () => {
it("adds cluster to default workspace", async () => {
const clusterStore = ClusterStore.getInstance()
const storedClusterData = clusterStore.store.get("clusters")[0]
const storedClusterData = clusterStore.getAllClusters()[0]
expect(storedClusterData.workspace).toBe('default')
})
})
+12 -14
View File
@@ -14,7 +14,7 @@ jest.mock("electron", () => {
// Console.log needs to be called before fs-mocks, see https://github.com/tschaub/mock-fs/issues/234
console.log("");
import { userStore, User, UserPreferences, UserStore } from "../../../src/common/user-store"
import { UserStore } from "../../../src/common/user-store"
describe("for an empty config", () => {
beforeEach(() => {
@@ -25,7 +25,6 @@ describe("for an empty config", () => {
}
}
mockFs(mockOpts)
const userStore = UserStore.getInstance()
})
afterEach(() => {
@@ -33,31 +32,31 @@ describe("for an empty config", () => {
})
it("allows setting and retrieving lastSeenAppVersion", async () => {
userStore.setLastSeenAppVersion("1.2.3");
expect(userStore.lastSeenAppVersion()).toBe("1.2.3");
UserStore.getInstance().setLastSeenAppVersion("1.2.3");
expect(UserStore.getInstance().lastSeenAppVersion()).toBe("1.2.3");
})
it("allows adding and listing seen contexts", async () => {
userStore.storeSeenContext(['foo'])
expect(userStore.getSeenContexts().length).toBe(1)
userStore.storeSeenContext(['foo', 'bar'])
const seenContexts = userStore.getSeenContexts()
UserStore.getInstance().storeSeenContext(['foo'])
expect(UserStore.getInstance().getSeenContexts().length).toBe(1)
UserStore.getInstance().storeSeenContext(['foo', 'bar'])
const seenContexts = UserStore.getInstance().getSeenContexts()
expect(seenContexts.length).toBe(2) // check 'foo' isn't added twice
expect(seenContexts[0]).toBe('foo')
expect(seenContexts[1]).toBe('bar')
})
it("allows setting and getting preferences", async () => {
userStore.setPreferences({
UserStore.getInstance().setPreferences({
httpsProxy: 'abcd://defg',
})
const storedPreferences = userStore.getPreferences()
const storedPreferences = UserStore.getInstance().getPreferences()
expect(storedPreferences.httpsProxy).toBe('abcd://defg')
expect(storedPreferences.colorTheme).toBe('dark') // defaults to dark
userStore.setPreferences({
UserStore.getInstance().setPreferences({
colorTheme: 'light'
})
expect(userStore.getPreferences().colorTheme).toBe('light')
expect(UserStore.getInstance().getPreferences().colorTheme).toBe('light')
})
})
@@ -74,7 +73,6 @@ describe("migrations", () => {
}
}
mockFs(mockOpts)
const userStore = UserStore.getInstance()
})
afterEach(() => {
@@ -82,6 +80,6 @@ describe("migrations", () => {
})
it("sets last seen app version to 0.0.0", async () => {
expect(userStore.lastSeenAppVersion()).toBe('0.0.0')
expect(UserStore.getInstance().lastSeenAppVersion()).toBe('0.0.0')
})
})