diff --git a/package.json b/package.json index 059ffc63ef..0d1589db30 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,6 @@ ] }, "jest": { - "testRegex": ".*_(spec|test)\\.[jt]sx?$", "collectCoverage": false, "verbose": true, "testEnvironment": "node", diff --git a/src/common/cluster-store_test.ts b/src/common/__tests__/cluster-store.test.ts similarity index 66% rename from src/common/cluster-store_test.ts rename to src/common/__tests__/cluster-store.test.ts index 3c0369def3..724a83f0d7 100644 --- a/src/common/cluster-store_test.ts +++ b/src/common/__tests__/cluster-store.test.ts @@ -1,9 +1,9 @@ import fs from "fs"; import mockFs from "mock-fs"; import yaml from "js-yaml"; -import { Cluster } from "../main/cluster"; -import { ClusterStore } from "./cluster-store"; -import { workspaceStore } from "./workspace-store"; +import { Cluster } from "../../main/cluster"; +import { ClusterStore } from "../cluster-store"; +import { workspaceStore } from "../workspace-store"; const testDataIcon = fs.readFileSync("test-data/cluster-store-migration-icon.png") @@ -12,7 +12,7 @@ console.log("") // fix bug let clusterStore: ClusterStore; describe("empty config", () => { - beforeAll(() => { + beforeEach(() => { ClusterStore.resetInstance(); const mockOpts = { 'tmp': { @@ -24,109 +24,120 @@ describe("empty config", () => { return clusterStore.load(); }) - afterAll(() => { + afterEach(() => { mockFs.restore(); }) - it("adds new cluster to store", async () => { - const cluster = new Cluster({ - id: "foo", - contextName: "minikube", - preferences: { - terminalCWD: "/tmp", - icon: "data:;base64,iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5", - clusterName: "minikube" - }, - kubeConfigPath: ClusterStore.embedCustomKubeConfig("foo", "fancy foo config"), - workspace: workspaceStore.currentWorkspaceId + describe("with foo cluster added", () => { + beforeEach(() => { + clusterStore.addCluster( + new Cluster({ + id: "foo", + contextName: "minikube", + preferences: { + terminalCWD: "/tmp", + icon: "data:image/jpeg;base64, iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5", + clusterName: "minikube" + }, + kubeConfigPath: ClusterStore.embedCustomKubeConfig("foo", "fancy foo config"), + workspace: workspaceStore.currentWorkspaceId + }) + ); + }) + + it("adds new cluster to store", async () => { + const storedCluster = clusterStore.getById("foo"); + expect(storedCluster.id).toBe("foo"); + expect(storedCluster.preferences.terminalCWD).toBe("/tmp"); + expect(storedCluster.preferences.icon).toBe("data:image/jpeg;base64, iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5"); + }) + + it("adds cluster to default workspace", () => { + const storedCluster = clusterStore.getById("foo"); + expect(storedCluster.workspace).toBe("default"); + }) + + it("removes cluster from store", async () => { + await clusterStore.removeById("foo"); + expect(clusterStore.getById("foo")).toBeUndefined(); + }) + + it("sets active cluster", () => { + clusterStore.setActive("foo"); + expect(clusterStore.activeCluster.id).toBe("foo"); + }) + }) + + describe("with prod and dev clusters added", () => { + beforeEach(() => { + clusterStore.addCluster( + new Cluster({ + id: "prod", + contextName: "prod", + preferences: { + clusterName: "prod" + }, + kubeConfigPath: ClusterStore.embedCustomKubeConfig("prod", "fancy config"), + workspace: "workstation" + }), + new Cluster({ + id: "dev", + contextName: "dev", + preferences: { + clusterName: "dev" + }, + kubeConfigPath: ClusterStore.embedCustomKubeConfig("dev", "fancy config"), + workspace: "workstation" + }) + ) + }) + + it("check if store can contain multiple clusters", () => { + expect(clusterStore.hasClusters()).toBeTruthy(); + expect(clusterStore.clusters.size).toBe(2); }); - clusterStore.addCluster(cluster); - const storedCluster = clusterStore.getById(cluster.id); - expect(storedCluster.id).toBe(cluster.id); - expect(storedCluster.preferences.terminalCWD).toBe(cluster.preferences.terminalCWD); - expect(storedCluster.preferences.icon).toBe(cluster.preferences.icon); - }) - it("adds cluster to default workspace", () => { - const storedCluster = clusterStore.getById("foo"); - expect(storedCluster.workspace).toBe("default"); - }) + it("gets clusters by workspaces", () => { + const wsClusters = clusterStore.getByWorkspaceId("workstation"); + const defaultClusters = clusterStore.getByWorkspaceId("default"); + expect(defaultClusters.length).toBe(0); + expect(wsClusters.length).toBe(2); + expect(wsClusters[0].id).toBe("prod"); + expect(wsClusters[1].id).toBe("dev"); + }) - it("check if store can contain multiple clusters", () => { - const prodCluster = new Cluster({ - id: "prod", - contextName: "prod", - preferences: { - clusterName: "prod" - }, - kubeConfigPath: ClusterStore.embedCustomKubeConfig("prod", "fancy config"), - workspace: "workstation" - }); - const devCluster = new Cluster({ - id: "dev", - contextName: "dev", - preferences: { - clusterName: "dev" - }, - kubeConfigPath: ClusterStore.embedCustomKubeConfig("dev", "fancy config"), - workspace: "workstation" - }); - clusterStore.addCluster(prodCluster); - clusterStore.addCluster(devCluster); - expect(clusterStore.hasClusters()).toBeTruthy(); - expect(clusterStore.clusters.size).toBe(3); - }); + it("check if cluster's kubeconfig file saved", () => { + const file = ClusterStore.embedCustomKubeConfig("boo", "kubeconfig"); + expect(fs.readFileSync(file, "utf8")).toBe("kubeconfig"); + }) - it("gets clusters by workspaces", () => { - const wsClusters = clusterStore.getByWorkspaceId("workstation"); - const defaultClusters = clusterStore.getByWorkspaceId("default"); - expect(defaultClusters.length).toBe(1); - expect(wsClusters.length).toBe(2); - expect(wsClusters[0].id).toBe("prod"); - expect(wsClusters[1].id).toBe("dev"); - }) + it("check if reorderring works for same from and to", () => { + clusterStore.swapIconOrders("workstation", 1, 1) - it("sets active cluster", () => { - clusterStore.setActive("foo"); - expect(clusterStore.activeCluster.id).toBe("foo"); - }) + const clusters = clusterStore.getByWorkspaceId("workstation"); + expect(clusters[0].id).toBe("prod") + expect(clusters[0].preferences.iconOrder).toBe(0) + expect(clusters[1].id).toBe("dev") + expect(clusters[1].preferences.iconOrder).toBe(1) + }) - it("check if cluster's kubeconfig file saved", () => { - const file = ClusterStore.embedCustomKubeConfig("boo", "kubeconfig"); - expect(fs.readFileSync(file, "utf8")).toBe("kubeconfig"); - }) + it("check if reorderring works for different from and to", () => { + clusterStore.swapIconOrders("workstation", 0, 1) - it("check if reorderring works for same from and to", () => { - clusterStore.swapIconOrders("workstation", 1, 1) + const clusters = clusterStore.getByWorkspaceId("workstation"); + expect(clusters[0].id).toBe("dev") + expect(clusters[0].preferences.iconOrder).toBe(0) + expect(clusters[1].id).toBe("prod") + expect(clusters[1].preferences.iconOrder).toBe(1) + }) - const clusters = clusterStore.getByWorkspaceId("workstation"); - expect(clusters[0].id).toBe("prod") - expect(clusters[0].preferences.iconOrder).toBe(0) - expect(clusters[1].id).toBe("dev") - expect(clusters[1].preferences.iconOrder).toBe(1) - }); + it("check if after icon reordering, changing workspaces still works", () => { + clusterStore.swapIconOrders("workstation", 1, 1) + clusterStore.getById("prod").workspace = "default" - it("check if reorderring works for different from and to", () => { - clusterStore.swapIconOrders("workstation", 0, 1) - - const clusters = clusterStore.getByWorkspaceId("workstation"); - expect(clusters[0].id).toBe("dev") - expect(clusters[0].preferences.iconOrder).toBe(0) - expect(clusters[1].id).toBe("prod") - expect(clusters[1].preferences.iconOrder).toBe(1) - }); - - it("check if after icon reordering, changing workspaces still works", () => { - clusterStore.swapIconOrders("workstation", 1, 1) - clusterStore.getById("prod").workspace = "default" - - expect(clusterStore.getByWorkspaceId("workstation").length).toBe(1); - expect(clusterStore.getByWorkspaceId("default").length).toBe(2); - }); - - it("removes cluster from store", async () => { - await clusterStore.removeById("foo"); - expect(clusterStore.getById("foo")).toBeUndefined(); + expect(clusterStore.getByWorkspaceId("workstation").length).toBe(1); + expect(clusterStore.getByWorkspaceId("default").length).toBe(1); + }) }) }) diff --git a/src/common/user-store_test.ts b/src/common/__tests__/user-store.test.ts similarity index 98% rename from src/common/user-store_test.ts rename to src/common/__tests__/user-store.test.ts index 4e9efe97d8..e361397565 100644 --- a/src/common/user-store_test.ts +++ b/src/common/__tests__/user-store.test.ts @@ -10,7 +10,7 @@ jest.mock("electron", () => { } }) -import { UserStore } from "./user-store" +import { UserStore } from "../user-store" import { SemVer } from "semver" import electron from "electron" diff --git a/src/common/workspace-store_test.ts b/src/common/__tests__/workspace-store.test.ts similarity index 98% rename from src/common/workspace-store_test.ts rename to src/common/__tests__/workspace-store.test.ts index 232f0b013a..8ac3ac599d 100644 --- a/src/common/workspace-store_test.ts +++ b/src/common/__tests__/workspace-store.test.ts @@ -10,7 +10,7 @@ jest.mock("electron", () => { } }) -import { WorkspaceStore } from "./workspace-store" +import { WorkspaceStore } from "../workspace-store" describe("workspace store tests", () => { describe("for an empty config", () => { diff --git a/src/common/utils/splitArray_test.ts b/src/common/utils/__tests__/splitArray.test.ts similarity index 95% rename from src/common/utils/splitArray_test.ts rename to src/common/utils/__tests__/splitArray.test.ts index ede542d605..a401e07701 100644 --- a/src/common/utils/splitArray_test.ts +++ b/src/common/utils/__tests__/splitArray.test.ts @@ -1,4 +1,4 @@ -import { splitArray } from "./splitArray"; +import { splitArray } from "../splitArray"; describe("split array on element tests", () => { test("empty array", () => { @@ -16,7 +16,7 @@ describe("split array on element tests", () => { test("one elements, in array", () => { expect(splitArray([1], 1)).toStrictEqual([[], [], true]); }); - + test("ten elements, in front array", () => { expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0)).toStrictEqual([[], [1, 2, 3, 4, 5, 6, 7, 8, 9], true]); }); diff --git a/src/renderer/api/kube-api-parse_test.ts b/src/renderer/api/__tests__/kube-api-parse.test.ts similarity index 89% rename from src/renderer/api/kube-api-parse_test.ts rename to src/renderer/api/__tests__/kube-api-parse.test.ts index dee3bf031d..c2aec7fd58 100644 --- a/src/renderer/api/kube-api-parse_test.ts +++ b/src/renderer/api/__tests__/kube-api-parse.test.ts @@ -1,11 +1,11 @@ -import { IKubeApiParsed, parseKubeApi } from "./kube-api-parse"; +import { IKubeApiParsed, parseKubeApi } from "../kube-api-parse"; -interface KubeApi_Parse_Test { +interface KubeApiParseTestData { url: string; expected: Required; } -const tests: KubeApi_Parse_Test[] = [ +const tests: KubeApiParseTestData[] = [ { url: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com", expected: { @@ -125,11 +125,10 @@ const tests: KubeApi_Parse_Test[] = [ }, ]; -describe.only("parseApi unit tests", () => { - for (const i in tests) { - const { url: tUrl, expected:tExpect} = tests[i]; - test(`test #${parseInt(i)+1}`, () => { - expect(parseKubeApi(tUrl)).toStrictEqual(tExpect); +describe("parseApi unit tests", () => { + for (const { url, expected } of tests) { + test(`testing "${url}"`, () => { + expect(parseKubeApi(url)).toStrictEqual(expected); }); } }); diff --git a/src/renderer/components/+cluster-settings/components/cluster-name-setting.tsx b/src/renderer/components/+cluster-settings/components/cluster-name-setting.tsx index a11f8aed6e..54d76c08eb 100644 --- a/src/renderer/components/+cluster-settings/components/cluster-name-setting.tsx +++ b/src/renderer/components/+cluster-settings/components/cluster-name-setting.tsx @@ -4,7 +4,7 @@ import { Input } from "../../input"; import { observable, autorun } from "mobx"; import { observer, disposeOnUnmount } from "mobx-react"; import { SubTitle } from "../../layout/sub-title"; -import { isRequired } from "../../input/input.validators"; +import { isRequired } from "../../input/input_validators"; interface Props { cluster: Cluster; @@ -33,7 +33,7 @@ export class ClusterNameSetting extends React.Component { render() { return ( <> - +

Define cluster name.

{ render() { return ( <> - +

HTTP Proxy server. Used for communicating with Kubernetes API.

{ const isCount = quota.startsWith("count/"); const icon = isCompute ? "memory" : isStorage ? "storage" : isCount ? "looks_one" : ""; return { - label: icon ? {quota} : quota, + label: icon ? {quota} : quota, value: quota, }; }); @@ -151,7 +151,7 @@ export class AddQuotaDialog extends React.Component { /> - Namespace}/> + Namespace} /> { onChange={({ value }) => this.namespace = value} /> - Values}/> + Values} />
{
- Namespace}/> + Namespace} /> { />
- Secret type}/> + Secret type} /> this.name = v.toLowerCase()} /> - Namespace}/> + Namespace} /> { } diff --git a/src/renderer/components/input/input.validators_test.ts b/src/renderer/components/input/__tests__/input_validators.test.ts similarity index 97% rename from src/renderer/components/input/input.validators_test.ts rename to src/renderer/components/input/__tests__/input_validators.test.ts index 4477d63e93..7bf08ffbdb 100644 --- a/src/renderer/components/input/input.validators_test.ts +++ b/src/renderer/components/input/__tests__/input_validators.test.ts @@ -1,4 +1,4 @@ -import { isEmail, systemName } from "./input.validators"; +import { isEmail, systemName } from "../input_validators"; describe("input validation tests", () => { describe("isEmail tests", () => { diff --git a/src/renderer/components/input/input.tsx b/src/renderer/components/input/input.tsx index c109735927..224f7f953e 100644 --- a/src/renderer/components/input/input.tsx +++ b/src/renderer/components/input/input.tsx @@ -3,7 +3,7 @@ import "./input.scss"; import React, { DOMAttributes, InputHTMLAttributes, TextareaHTMLAttributes } from "react"; import { autobind, cssNames, debouncePromise } from "../../utils"; import { Icon } from "../icon"; -import { conditionalValidators, Validator } from "./input.validators"; +import { conditionalValidators, Validator } from "./input_validators"; import isString from "lodash/isString" import isFunction from "lodash/isFunction" import isBoolean from "lodash/isBoolean" @@ -288,9 +288,9 @@ export class Input extends React.Component { return (