Skip to content

Commit

Permalink
Review (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor authored Mar 18, 2020
1 parent 6f1ea36 commit 56bb18c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
6 changes: 4 additions & 2 deletions dashboard/src/actions/operators.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import { IResource } from "shared/types";
import { getType } from "typesafe-actions";
import actions from ".";
import { Operators } from "../shared/Operators";
Expand Down Expand Up @@ -193,14 +194,15 @@ describe("getCSV", () => {

describe("createResource", () => {
it("creates a resource", async () => {
Operators.createResource = jest.fn(() => true);
const resource = {} as IResource;
Operators.createResource = jest.fn(() => resource);
const expectedActions = [
{
type: getType(operatorActions.creatingResource),
},
{
type: getType(operatorActions.resourceCreated),
payload: true,
payload: resource,
},
];
await store.dispatch(operatorActions.createResource("default", "v1", "pods", {}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ it("retrieves the example values and the target CRD from the given CSV", () => {
owned: [defaultCRD],
},
},
} as IClusterServiceVersion;
} as any;
const wrapper = shallow(<OperatorInstanceForm {...defaultProps} />);
wrapper.setProps({ csv });
expect(wrapper.state()).toMatchObject({
Expand All @@ -58,6 +58,23 @@ it("retrieves the example values and the target CRD from the given CSV", () => {
});
});

it("defaults to empty defaultValues if the examples annotation is not found", () => {
const csv = {
metadata: {},
spec: {
customresourcedefinitions: {
owned: [defaultCRD],
},
},
} as IClusterServiceVersion;
const wrapper = shallow(<OperatorInstanceForm {...defaultProps} />);
wrapper.setProps({ csv });
expect(wrapper.state()).toMatchObject({
defaultValues: "",
crd: defaultCRD,
});
});

it("renders an error if there is some error fetching", () => {
const wrapper = shallow(
<OperatorInstanceForm {...defaultProps} errors={{ fetch: new Error("Boom!") }} />,
Expand Down Expand Up @@ -88,7 +105,9 @@ it("restores the default values", async () => {
const restoreConfirmButton = wrapper.find("button").filterWhere(b => b.text() === "Restore");
restoreConfirmButton.simulate("click");

// expect(wrapper.state() as any).toMatchObject({ values: "foo", defaultValues: "foo" });
const { values, defaultValues } = wrapper.state() as any;
expect(values).toEqual("foo");
expect(defaultValues).toEqual("foo");
});

it("should submit the form", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ class DeploymentFormBody extends React.Component<
if (ownedCRD.name === crdName) {
// Got the target CRD, extract the example
const kind = ownedCRD.kind;
const rawExamples = csv.metadata.annotations["alm-examples"];
const rawExamples = get(csv, 'metadata.annotations["alm-examples"]', "[]");
const examples = JSON.parse(rawExamples) as IResource[];
let defaultValues = "";
examples.forEach(example => {
if (example.kind === kind) {
// Found the example, set the default values
const yamlValues = yaml.safeDump(example);
this.setState({
values: yamlValues,
defaultValues: yamlValues,
crd: ownedCRD,
});
defaultValues = yaml.safeDump(example);
}
});
this.setState({
values: defaultValues,
defaultValues,
crd: ownedCRD,
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export interface IResource {
metadata: {
name: string;
namespace: string;
annotations: any;
annotations: { [key: string]: string };
creationTimestamp: string;
selfLink: string;
resourceVersion: string;
Expand Down

0 comments on commit 56bb18c

Please sign in to comment.