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

Review from #1584 #1589

Merged
merged 1 commit into from
Mar 18, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that this can change means the test isn't actually verifying the resource, I think? But fine either way.

Copy link
Contributor Author

@andresmgot andresmgot Mar 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, since the method is mocked no validation is made

},
];
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