mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
clean up
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
776fc4462c
commit
e7975ec71f
@ -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')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@ -9,7 +9,7 @@
|
|||||||
export class Singleton {
|
export class Singleton {
|
||||||
private static instances = new WeakMap<object, Singleton>();
|
private static instances = new WeakMap<object, Singleton>();
|
||||||
|
|
||||||
// todo: figure out how to infer child class type + arguments
|
// todo: figure out how to infer child class + arguments types
|
||||||
static getInstance<T extends Singleton>(...args: any[]): T {
|
static getInstance<T extends Singleton>(...args: any[]): T {
|
||||||
if (!Singleton.instances.has(this)) {
|
if (!Singleton.instances.has(this)) {
|
||||||
Singleton.instances.set(this, Reflect.construct(this, args));
|
Singleton.instances.set(this, Reflect.construct(this, args));
|
||||||
@ -20,8 +20,4 @@ export class Singleton {
|
|||||||
static resetInstance() {
|
static resetInstance() {
|
||||||
Singleton.instances.delete(this);
|
Singleton.instances.delete(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected constructor() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user