diff --git a/locales/en/messages.po b/locales/en/messages.po index 3fd54c5325..30d81b3b08 100644 --- a/locales/en/messages.po +++ b/locales/en/messages.po @@ -2416,6 +2416,10 @@ msgstr "There are no logs available." msgid "This field is required" msgstr "This field is required" +#: src/renderer/components/input/input.validators.ts:39 +msgid "A System Name must be lowercase DNS labels separated by dots. DNS labels are alphanumerics and dashes enclosed by alphanumerics." +msgstr "A System Name must be lowercase DNS labels separated by dots. DNS labels are alphanumerics and dashes enclosed by alphanumerics." + #: src/renderer/components/cluster-manager/clusters-menu.tsx:104 msgid "This is the quick launch menu." msgstr "This is the quick launch menu." diff --git a/locales/fi/messages.po b/locales/fi/messages.po index 00717c4193..36a8a390a5 100644 --- a/locales/fi/messages.po +++ b/locales/fi/messages.po @@ -2399,6 +2399,10 @@ msgstr "" msgid "This field is required" msgstr "" +#: src/renderer/components/input/input.validators.ts:39 +msgid "A System Name must be lowercase DNS labels separated by dots. DNS labels are alphanumerics and dashes enclosed by alphanumerics." +msgstr "" + #: src/renderer/components/cluster-manager/clusters-menu.tsx:104 msgid "This is the quick launch menu." msgstr "" diff --git a/locales/ru/messages.po b/locales/ru/messages.po index 5b9954d255..704970ed74 100644 --- a/locales/ru/messages.po +++ b/locales/ru/messages.po @@ -2417,6 +2417,10 @@ msgstr "Логи отсутствуют." msgid "This field is required" msgstr "Это обязательное поле" +#: src/renderer/components/input/input.validators.ts:39 +msgid "A System Name must be lowercase DNS labels separated by dots. DNS labels are alphanumerics and dashes enclosed by alphanumerics." +msgstr "Это поле может содержать только латинские буквы в нижнем регистре, номера и дефис." + #: src/renderer/components/cluster-manager/clusters-menu.tsx:104 msgid "This is the quick launch menu." msgstr "" diff --git a/src/common/base-store.ts b/src/common/base-store.ts index 722698fa67..0cc087eb9f 100644 --- a/src/common/base-store.ts +++ b/src/common/base-store.ts @@ -135,8 +135,4 @@ export class BaseStore extends Singleton { recurseEverything: true, }) } - - * [Symbol.iterator]() { - yield* Object.entries(this.toJSON()); - } } diff --git a/src/common/kube-helpers.ts b/src/common/kube-helpers.ts index 65737b6134..26e73db4a8 100644 --- a/src/common/kube-helpers.ts +++ b/src/common/kube-helpers.ts @@ -1,11 +1,10 @@ import { app, remote } from "electron"; import { KubeConfig, V1Node, V1Pod } from "@kubernetes/client-node" -import { ensureDirSync, readFile, writeFileSync } from "fs-extra"; +import fse, { ensureDirSync, readFile, writeFileSync } from "fs-extra"; import path from "path" import os from "os" import yaml from "js-yaml" import logger from "../main/logger"; -import fse from "fs-extra" function resolveTilde(filePath: string) { if (filePath[0] === "~" && (filePath[1] === "/" || filePath.length === 1)) { @@ -135,8 +134,6 @@ export function podHasIssues(pod: V1Pod) { ) } -// Logic adapted from dashboard -// see: https://github.com/kontena/kontena-k8s-dashboard/blob/7d8f9cb678cc817a22dd1886c5e79415b212b9bf/client/api/endpoints/nodes.api.ts#L147 export function getNodeWarningConditions(node: V1Node) { return node.status.conditions.filter(c => c.status.toLowerCase() === "true" && c.type !== "Ready" && c.type !== "HostUpgrades" diff --git a/src/common/tracker.ts b/src/common/tracker.ts index c904d2c806..bc9a8e191b 100644 --- a/src/common/tracker.ts +++ b/src/common/tracker.ts @@ -3,6 +3,7 @@ import ua from "universal-analytics" import { machineIdSync } from "node-machine-id" import Singleton from "./utils/singleton"; import { userStore } from "./user-store" +import logger from "../main/logger"; export class Tracker extends Singleton { static readonly GA_ID = "UA-159377374-1" @@ -40,7 +41,7 @@ export class Tracker extends Singleton { ...otherParams, }).send() } catch (err) { - console.error(`Failed to track "${eventCategory}:${eventAction}"`, err) + logger.error(`Failed to track "${eventCategory}:${eventAction}"`, err) } } } diff --git a/src/common/user-store_test.ts b/src/common/user-store_test.ts new file mode 100644 index 0000000000..4e9efe97d8 --- /dev/null +++ b/src/common/user-store_test.ts @@ -0,0 +1,102 @@ +import mockFs from "mock-fs" + +jest.mock("electron", () => { + return { + app: { + getVersion: () => '99.99.99', + getPath: () => 'tmp', + getLocale: () => 'en' + } + } +}) + +import { UserStore } from "./user-store" +import { SemVer } from "semver" +import electron from "electron" + +describe("user store tests", () => { + describe("for an empty config", () => { + beforeEach(() => { + UserStore.resetInstance() + mockFs({ tmp: { 'config.json': "{}" } }) + }) + + afterEach(() => { + mockFs.restore() + }) + + it("allows setting and retrieving lastSeenAppVersion", () => { + const us = UserStore.getInstance(); + + us.lastSeenAppVersion = "1.2.3"; + expect(us.lastSeenAppVersion).toBe("1.2.3"); + }) + + it("allows adding and listing seen contexts", () => { + const us = UserStore.getInstance(); + + us.seenContexts.add('foo') + expect(us.seenContexts.size).toBe(1) + + us.seenContexts.add('foo') + us.seenContexts.add('bar') + expect(us.seenContexts.size).toBe(2) // check 'foo' isn't added twice + expect(us.seenContexts.has('foo')).toBe(true) + expect(us.seenContexts.has('bar')).toBe(true) + }) + + it("allows setting and getting preferences", () => { + const us = UserStore.getInstance(); + + us.preferences.httpsProxy = 'abcd://defg'; + + expect(us.preferences.httpsProxy).toBe('abcd://defg') + expect(us.preferences.colorTheme).toBe(UserStore.defaultTheme) + + us.preferences.colorTheme = "light"; + expect(us.preferences.colorTheme).toBe('light') + }) + + it("correctly resets theme to default value", () => { + const us = UserStore.getInstance(); + + us.preferences.colorTheme = "some other theme"; + us.resetTheme(); + expect(us.preferences.colorTheme).toBe(UserStore.defaultTheme); + }) + + it("correctly calculates if the last seen version is an old release", () => { + const us = UserStore.getInstance(); + + expect(us.isNewVersion).toBe(true); + + us.lastSeenAppVersion = (new SemVer(electron.app.getVersion())).inc("major").format(); + expect(us.isNewVersion).toBe(false); + }) + }) + + describe("migrations", () => { + beforeEach(() => { + UserStore.resetInstance() + mockFs({ + 'tmp': { + 'config.json': JSON.stringify({ + user: { username: 'foobar' }, + preferences: { colorTheme: 'light' }, + lastSeenAppVersion: '1.2.3' + }) + } + }) + }) + + afterEach(() => { + mockFs.restore() + }) + + it("sets last seen app version to 0.0.0", () => { + const us = UserStore.getInstance(); + + expect(us.lastSeenAppVersion).toBe('0.0.0') + }) + }) +}) \ No newline at end of file diff --git a/src/common/workspace-store.ts b/src/common/workspace-store.ts index 3935dda02e..dd10a4c433 100644 --- a/src/common/workspace-store.ts +++ b/src/common/workspace-store.ts @@ -51,6 +51,10 @@ export class WorkspaceStore extends BaseStore { @action setActive(id = WorkspaceStore.defaultId) { + if (!this.getById(id)) { + throw new Error(`workspace ${id} doesn't exist`); + } + this.currentWorkspaceId = id; } diff --git a/src/common/workspace-store_test.ts b/src/common/workspace-store_test.ts new file mode 100644 index 0000000000..55e9672663 --- /dev/null +++ b/src/common/workspace-store_test.ts @@ -0,0 +1,128 @@ +import mockFs from "mock-fs" + +jest.mock("electron", () => { + return { + app: { + getVersion: () => '99.99.99', + getPath: () => 'tmp', + getLocale: () => 'en' + } + } +}) + +import { WorkspaceStore } from "./workspace-store" + +describe("workspace store tests", () => { + describe("for an empty config", () => { + beforeEach(async () => { + WorkspaceStore.resetInstance() + mockFs({ tmp: { 'lens-workspace-store.json': "{}" } }) + + await WorkspaceStore.getInstance().load(); + }) + + afterEach(() => { + mockFs.restore() + }) + + it("default workspace should always exist", () => { + const ws = WorkspaceStore.getInstance(); + + expect(ws.workspaces.size).toBe(1); + expect(ws.getById(WorkspaceStore.defaultId)).not.toBe(null); + }) + + it("cannot remove the default workspace", () => { + const ws = WorkspaceStore.getInstance(); + + expect(() => ws.removeWorkspace(WorkspaceStore.defaultId)).toThrowError("Cannot remove"); + }) + + it("can update default workspace name", () => { + const ws = WorkspaceStore.getInstance(); + + ws.saveWorkspace({ + id: WorkspaceStore.defaultId, + name: "foobar", + }); + + expect(ws.currentWorkspace.name).toBe("foobar"); + }) + + it("can add workspaces", () => { + const ws = WorkspaceStore.getInstance(); + + ws.saveWorkspace({ + id: "123", + name: "foobar", + }); + + expect(ws.getById("123").name).toBe("foobar"); + }) + + it("cannot set a non-existent workspace to be active", () => { + const ws = WorkspaceStore.getInstance(); + + expect(() => ws.setActive("abc")).toThrow("doesn't exist"); + }) + + it("can set a existent workspace to be active", () => { + const ws = WorkspaceStore.getInstance(); + + ws.saveWorkspace({ + id: "abc", + name: "foobar", + }); + + expect(() => ws.setActive("abc")).not.toThrowError(); + }) + + it("can remove a workspace", () => { + const ws = WorkspaceStore.getInstance(); + + ws.saveWorkspace({ + id: "123", + name: "foobar", + }); + ws.saveWorkspace({ + id: "1234", + name: "foobar 1", + }); + ws.removeWorkspace("123"); + + expect(ws.workspaces.size).toBe(2); + }) + }) + + describe("for a non-empty config", () => { + beforeEach(async () => { + WorkspaceStore.resetInstance() + mockFs({ + tmp: { + 'lens-workspace-store.json': JSON.stringify({ + currentWorkspace: "abc", + workspaces: [{ + id: "abc", + name: "test" + }, { + id: "default", + name: "default" + }] + }) + } + }) + + await WorkspaceStore.getInstance().load(); + }) + + afterEach(() => { + mockFs.restore() + }) + + it("doesn't revert to default workspace", async () => { + const ws = WorkspaceStore.getInstance(); + + expect(ws.currentWorkspaceId).toBe("abc"); + }) + }) +}) \ No newline at end of file diff --git a/src/renderer/components/+cluster-settings/cluster-settings.tsx b/src/renderer/components/+cluster-settings/cluster-settings.tsx index 28726de561..7f1f0382fc 100644 --- a/src/renderer/components/+cluster-settings/cluster-settings.tsx +++ b/src/renderer/components/+cluster-settings/cluster-settings.tsx @@ -1,6 +1,7 @@ import "./cluster-settings.scss"; import React from "react"; +import { Link } from "react-router-dom"; import { observer } from "mobx-react"; import { Features } from "./features"; import { Removal } from "./removal";