From e7975ec71f710e90671345243b35c94cf3760b88 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 3 Jul 2020 17:33:59 +0300 Subject: [PATCH] clean up Signed-off-by: Roman --- src/common/user-store_spec.ts | 73 ----------------------------------- src/common/utils/singleton.ts | 6 +-- 2 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 src/common/user-store_spec.ts diff --git a/src/common/user-store_spec.ts b/src/common/user-store_spec.ts deleted file mode 100644 index 71aab0ed1d..0000000000 --- a/src/common/user-store_spec.ts +++ /dev/null @@ -1,73 +0,0 @@ -import mockFs from "mock-fs" -import { userStore, UserStore } from "./user-store" - -// fixme: most probably due __mocks_/electron.ts "projectVersion" from "electron-store" cannot be ensured -describe.skip("for an empty config", () => { - beforeEach(() => { - UserStore.resetInstance() - const mockOpts = { - 'tmp': { - 'config.json': JSON.stringify({}) - } - } - mockFs(mockOpts) - const userStore = UserStore.getInstance() - }) - - afterEach(() => { - mockFs.restore() - }) - - it("allows setting and retrieving lastSeenAppVersion", async () => { - userStore.setLastSeenAppVersion("1.2.3"); - expect(userStore.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() - 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({ - httpsProxy: 'abcd://defg', - }) - const storedPreferences = userStore.getPreferences() - expect(storedPreferences.httpsProxy).toBe('abcd://defg') - expect(storedPreferences.colorTheme).toBe('dark') // defaults to dark - userStore.setPreferences({ - colorTheme: 'light' - }) - expect(userStore.getPreferences().colorTheme).toBe('light') - }) -}) - -describe.skip("migrations", () => { - beforeEach(() => { - UserStore.resetInstance() - const mockOpts = { - 'tmp': { - 'config.json': JSON.stringify({ - user: { username: 'foobar' }, - preferences: { colorTheme: 'light' }, - lastSeenAppVersion: '1.2.3' - }) - } - } - mockFs(mockOpts) - const userStore = UserStore.getInstance() - }) - - afterEach(() => { - mockFs.restore() - }) - - it("sets last seen app version to 0.0.0", async () => { - expect(userStore.lastSeenAppVersion()).toBe('0.0.0') - }) -}) diff --git a/src/common/utils/singleton.ts b/src/common/utils/singleton.ts index 252524cd95..a5d2aa5ca3 100644 --- a/src/common/utils/singleton.ts +++ b/src/common/utils/singleton.ts @@ -9,7 +9,7 @@ export class Singleton { private static instances = new WeakMap(); - // todo: figure out how to infer child class type + arguments + // todo: figure out how to infer child class + arguments types static getInstance(...args: any[]): T { if (!Singleton.instances.has(this)) { Singleton.instances.set(this, Reflect.construct(this, args)); @@ -20,8 +20,4 @@ export class Singleton { static resetInstance() { Singleton.instances.delete(this); } - - protected constructor() { - return this; - } }