Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types to the state used in tests #5217

Merged
merged 4 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion dashboard/src/actions/auth.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import { Auth } from "shared/Auth";
import Namespace, * as NS from "shared/Namespace";
import { initialState } from "shared/specs/mountWrapper";
import { IStoreState } from "shared/types";
import { getType } from "typesafe-actions";
import actions from ".";

Expand Down Expand Up @@ -35,12 +37,14 @@ beforeEach(() => {

store = mockStore({
auth: {
...initialState.auth,
state,
},
config: {
...initialState.config,
oauthLogoutURI: "/log/out",
},
});
} as Partial<IStoreState>);
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/actions/availablepackages.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Plugin } from "gen/kubeappsapis/core/plugins/v1alpha1/plugins";
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import PackagesService from "shared/PackagesService";
import { FetchError, IReceivePackagesActionPayload } from "shared/types";
import { FetchError, IReceivePackagesActionPayload, IStoreState } from "shared/types";
import { getType } from "typesafe-actions";
import actions from ".";

Expand Down Expand Up @@ -73,7 +73,7 @@ beforeEach(() => {
packages: {
isFetching: false,
},
});
} as Partial<IStoreState>);
});

afterEach(() => {
Expand Down
14 changes: 7 additions & 7 deletions dashboard/src/actions/kube.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright 2018-2022 the Kubeapps contributors.
// SPDX-License-Identifier: Apache-2.0

import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import { Kube } from "shared/Kube";
import { IKubeState, IResource } from "shared/types";
import { getType } from "typesafe-actions";
import actions from ".";
import {
InstalledPackageReference,
ResourceRef as APIResourceRef,
} from "gen/kubeappsapis/core/packages/v1alpha1/packages";
import { GetResourcesResponse } from "gen/kubeappsapis/plugins/resources/v1alpha1/resources";
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import { Kube } from "shared/Kube";
import { IKubeState, IResource, IStoreState } from "shared/types";
import { getType } from "typesafe-actions";
import actions from ".";

const mockStore = configureMockStore([thunk]);

Expand All @@ -22,7 +22,7 @@ const makeStore = (operatorsEnabled: boolean) => {
kinds: {},
};
const config = operatorsEnabled ? { featureFlags: { operators: true } } : {};
return mockStore({ kube: state, config: config });
return mockStore({ kube: state, config: config } as Partial<IStoreState>);
};

let store: any;
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/actions/operators.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import { Operators } from "shared/Operators";
import { IResource } from "shared/types";
import { IResource, IStoreState } from "shared/types";
import { getType } from "typesafe-actions";
import actions from ".";

Expand All @@ -14,7 +14,7 @@ const mockStore = configureMockStore([thunk]);
let store: any;

beforeEach(() => {
store = mockStore({});
store = mockStore({} as Partial<IStoreState>);
});

afterEach(jest.restoreAllMocks);
Expand Down
5 changes: 4 additions & 1 deletion dashboard/src/actions/repos.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,17 @@ describe("deleteRepo", () => {
it("dispatches requestRepoSummaries with current namespace", async () => {
const storeWithFlag: any = mockStore({
clusters: {
...initialState.clusters,
currentCluster: "defaultCluster",
clusters: {
...initialState.clusters.clusters,
defaultCluster: {
...initialState.clusters.clusters[initialState.clusters.currentCluster],
currentNamespace,
},
},
},
});
} as Partial<IStoreState>);
await storeWithFlag.dispatch(
repoActions.deleteRepo({
context: { cluster: "default", namespace: "my-namespace" },
Expand Down
17 changes: 9 additions & 8 deletions dashboard/src/components/AppUpgrade/AppUpgrade.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
FetchError,
IInstalledPackageState,
IPackageState,
IStoreState,
UpgradeError,
} from "shared/types";
import { PluginNames } from "shared/utils";
Expand Down Expand Up @@ -132,7 +133,7 @@ it("renders the repo selection form if not introduced", () => {
} as IInstalledPackageState,
};
const wrapper = mountWrapper(
getStore({ ...defaultStore, ...state }),
getStore({ ...defaultStore, ...state } as Partial<IStoreState>),
<MemoryRouter initialEntries={[routePathParam]}>
<Route path={routePath}>
<AppUpgrade />,
Expand All @@ -157,7 +158,7 @@ it("renders the repo selection form if not introduced when the app is loaded", (
getStore({
...defaultStore,
...state,
}),
} as Partial<IStoreState>),
<MemoryRouter initialEntries={[routePathParam]}>
<Route path={routePath}>
<AppUpgrade />,
Expand All @@ -180,7 +181,7 @@ describe("when an error exists", () => {
getStore({
...defaultStore,
...state,
}),
} as Partial<IStoreState>),
<MemoryRouter initialEntries={[routePathParam]}>
<Route path={routePath}>
<AppUpgrade />,
Expand Down Expand Up @@ -210,7 +211,7 @@ describe("when an error exists", () => {
getStore({
...defaultStore,
...state,
}),
} as Partial<IStoreState>),
<MemoryRouter initialEntries={[routePathParam]}>
<Route path={routePath}>
<AppUpgrade />,
Expand Down Expand Up @@ -238,7 +239,7 @@ describe("when an error exists", () => {
getStore({
...defaultStore,
...state,
}),
} as Partial<IStoreState>),
<MemoryRouter initialEntries={[routePathParam]}>
<Route path={routePath}>
<AppUpgrade />,
Expand Down Expand Up @@ -273,7 +274,7 @@ it("renders the upgrade form when the repo is available, clears state and fetche
getStore({
...defaultStore,
...state,
}),
} as Partial<IStoreState>),
<MemoryRouter initialEntries={[routePathParam]}>
<Route path={routePath}>
<AppUpgrade />,
Expand Down Expand Up @@ -309,7 +310,7 @@ it("renders the upgrade form with the version property", () => {
getStore({
...defaultStore,
...state,
}),
} as Partial<IStoreState>),
<MemoryRouter initialEntries={[routePathParam + "/0.0.1"]}>
<Route path={routePath + "/:version"}>
<AppUpgrade />,
Expand Down Expand Up @@ -337,7 +338,7 @@ it("skips the repo selection form if the app contains upgrade info", () => {
getStore({
...defaultStore,
...state,
}),
} as Partial<IStoreState>),
<MemoryRouter initialEntries={[routePathParam]}>
<Route path={routePath}>
<AppUpgrade />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { act } from "react-dom/test-utils";
import * as ReactRedux from "react-redux";
import ReactTooltip from "react-tooltip";
import { defaultStore, getStore, mountWrapper } from "shared/specs/mountWrapper";
import { DeleteError } from "shared/types";
import { DeleteError, IInstalledPackageState, IStoreState } from "shared/types";
import DeleteButton from "./DeleteButton";

const defaultProps = {
Expand Down Expand Up @@ -63,7 +63,9 @@ it("deletes an application", async () => {
});

it("renders an error", async () => {
const store = getStore({ apps: { error: new DeleteError("Boom!") } });
const store = getStore({
apps: { error: new DeleteError("Boom!") } as Partial<IInstalledPackageState>,
} as Partial<IStoreState>);
const wrapper = mountWrapper(store, <DeleteButton {...defaultProps} />);
// Open modal
act(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { act } from "react-dom/test-utils";
import * as ReactRedux from "react-redux";
import ReactTooltip from "react-tooltip";
import { defaultStore, getStore, mountWrapper } from "shared/specs/mountWrapper";
import { RollbackError } from "shared/types";
import { IInstalledPackageState, RollbackError } from "shared/types";
import RollbackButton from "./RollbackButton";

const defaultProps = {
Expand Down Expand Up @@ -70,7 +70,9 @@ it("rolls back an application", async () => {
});

it("renders an error", async () => {
const store = getStore({ apps: { error: new RollbackError("Boom!") } });
const store = getStore({
apps: { error: new RollbackError("Boom!") },
} as Partial<IInstalledPackageState>);
const wrapper = mountWrapper(store, <RollbackButton {...defaultProps} />);
// Open modal
act(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { keyForResourceRef } from "shared/ResourceRef";
import { ResourceRef } from "gen/kubeappsapis/core/packages/v1alpha1/packages";
import { defaultStore, getStore, mountWrapper } from "shared/specs/mountWrapper";
import { ISecret } from "shared/types";
import { defaultStore, getStore, initialState, mountWrapper } from "shared/specs/mountWrapper";
import { ISecret, IStoreState } from "shared/types";
import SecretItemDatum from "../ResourceTable/ResourceItem/SecretItem/SecretItemDatum";
import AppSecrets from "./AppSecrets";

Expand Down Expand Up @@ -38,15 +38,18 @@ it("shows a message if there are no secrets", () => {
it("renders a secretItemDatum per secret", () => {
const key = keyForResourceRef(sampleResourceRef);
const state = getStore({
...initialState,
kube: {
...initialState.kube,
items: {
...initialState.kube.items,
[key]: {
isFetching: false,
item: secret,
},
},
},
});
} as Partial<IStoreState>);
const wrapper = mountWrapper(state, <AppSecrets secretRefs={[sampleResourceRef]} />);
expect(wrapper.find(SecretItemDatum)).toHaveLength(2);
});
5 changes: 3 additions & 2 deletions dashboard/src/components/AppView/AppValues/AppValues.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import AceEditor from "react-ace";
import { SupportedThemes } from "shared/Config";
import { defaultStore, getStore, mountWrapper } from "shared/specs/mountWrapper";
import { defaultStore, getStore, initialState, mountWrapper } from "shared/specs/mountWrapper";
import { IStoreState } from "shared/types";
import AppValues from "./AppValues";

it("includes values", () => {
Expand All @@ -26,7 +27,7 @@ it("sets light theme by default", () => {

it("changes theme", () => {
const wrapper = mountWrapper(
getStore({ config: { theme: SupportedThemes.dark } }),
getStore({ ...initialState, config: { theme: SupportedThemes.dark } } as Partial<IStoreState>),
<AppValues values="foo: bar" />,
);
expect(wrapper.find(AceEditor).prop("theme")).toBe("solarized_dark");
Expand Down