Skip to content

Commit

Permalink
Fix temporary error message for Operators (#1642)
Browse files Browse the repository at this point in the history
* Fix temporary error message for Operators

* Dispatch receiveCustomResources even if the list is empty
  • Loading branch information
Andres Martinez Gotor authored Apr 8, 2020
1 parent 1fc968b commit 59064ac
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 45 deletions.
6 changes: 5 additions & 1 deletion dashboard/src/actions/operators.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("checkOLMInstalled", () => {
type: getType(operatorActions.checkingOLM),
},
{
type: getType(operatorActions.errorOperators),
type: getType(operatorActions.errorOLMCheck),
payload: new Error("nope"),
},
];
Expand Down Expand Up @@ -327,6 +327,10 @@ describe("getResources", () => {
type: getType(operatorActions.errorCustomResource),
payload: new Error("Boom!"),
},
{
type: getType(operatorActions.receiveCustomResources),
payload: [],
},
];
await store.dispatch(operatorActions.getResources("default"));
expect(store.getActions()).toEqual(expectedActions);
Expand Down
10 changes: 6 additions & 4 deletions dashboard/src/actions/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { IClusterServiceVersion, IPackageManifest, IResource, IStoreState } from

export const checkingOLM = createAction("CHECKING_OLM");
export const OLMInstalled = createAction("OLM_INSTALLED");
export const errorOLMCheck = createAction("ERROR_OLM_CHECK", resolve => {
return (err: Error) => resolve(err);
});

export const requestOperators = createAction("REQUEST_OPERATORS");
export const receiveOperators = createAction("RECEIVE_OPERATORS", resolve => {
Expand Down Expand Up @@ -76,6 +79,7 @@ export const receiveCustomResource = createAction("RECEIVE_CUSTOM_RESOURCE", res
const actions = [
checkingOLM,
OLMInstalled,
errorOLMCheck,
requestOperators,
receiveOperators,
errorOperators,
Expand Down Expand Up @@ -119,7 +123,7 @@ export function checkOLMInstalled(): ThunkAction<
}
return installed;
} catch (e) {
dispatch(errorOperators(e));
dispatch(errorOLMCheck(e));
return false;
}
};
Expand Down Expand Up @@ -282,9 +286,7 @@ export function getResources(
await Promise.all(crdPromises);
});
await Promise.all(csvPromises);
if (resources.length) {
dispatch(receiveCustomResources(resources));
}
dispatch(receiveCustomResources(resources));
return resources;
};
}
Expand Down
113 changes: 99 additions & 14 deletions dashboard/src/reducers/operators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ describe("catalogReducer", () => {

beforeEach(() => {
initialState = {
isFetchingElem: {
OLM: false,
operator: false,
csv: false,
resource: false,
},
isFetching: false,
isOLMInstalled: false,
operators: [],
Expand Down Expand Up @@ -52,14 +58,22 @@ describe("catalogReducer", () => {
operatorReducer(undefined, {
type: actionTypes.checkingOLM as any,
}),
).toEqual({ ...initialState, isFetching: true });
).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: true, operator: false, csv: false, resource: false },
});
});

it("unsets isFetching and mark OLM as installed", () => {
const state = operatorReducer(undefined, {
type: actionTypes.checkingOLM as any,
});
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: true, operator: false, csv: false, resource: false },
});
expect(
operatorReducer(undefined, {
type: actionTypes.OLMInstalled as any,
Expand All @@ -72,7 +86,11 @@ describe("catalogReducer", () => {
type: actionTypes.requestOperators as any,
});
const op = {} as IPackageManifest;
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: true, csv: false, resource: false },
});
expect(
operatorReducer(undefined, {
type: actionTypes.receiveOperators as any,
Expand All @@ -85,7 +103,11 @@ describe("catalogReducer", () => {
const state = operatorReducer(undefined, {
type: actionTypes.requestOperators as any,
});
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: true, csv: false, resource: false },
});
expect(
operatorReducer(undefined, {
type: actionTypes.errorOperators as any,
Expand Down Expand Up @@ -118,6 +140,7 @@ describe("catalogReducer", () => {
{
...initialState,
isFetching: true,
isFetchingElem: { OLM: true, operator: false, csv: false, resource: false },
errors: { fetch: new Error("Boom!") },
operators: [{} as any],
},
Expand All @@ -133,7 +156,11 @@ describe("catalogReducer", () => {
type: actionTypes.requestOperator as any,
});
const op = {} as IPackageManifest;
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: true, csv: false, resource: false },
});
expect(
operatorReducer(undefined, {
type: actionTypes.receiveOperator as any,
Expand All @@ -147,7 +174,11 @@ describe("catalogReducer", () => {
type: actionTypes.requestCSVs as any,
});
const csv = {} as IClusterServiceVersion;
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: false, csv: true, resource: false },
});
expect(
operatorReducer(undefined, {
type: actionTypes.receiveCSVs as any,
Expand All @@ -160,7 +191,11 @@ describe("catalogReducer", () => {
const state = operatorReducer(undefined, {
type: actionTypes.requestCSVs as any,
});
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: false, csv: true, resource: false },
});
expect(
operatorReducer(undefined, {
type: actionTypes.errorCSVs as any,
Expand All @@ -174,7 +209,11 @@ describe("catalogReducer", () => {
type: actionTypes.requestCSV as any,
});
const csv = {} as IClusterServiceVersion;
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: false, csv: true, resource: false },
});
expect(
operatorReducer(undefined, {
type: actionTypes.receiveCSV as any,
Expand All @@ -189,7 +228,11 @@ describe("catalogReducer", () => {
type: actionTypes.creatingResource as any,
});
const resource = {} as IResource;
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: false, csv: false, resource: true },
});
expect(
operatorReducer(undefined, {
type: actionTypes.resourceCreated as any,
Expand All @@ -202,7 +245,11 @@ describe("catalogReducer", () => {
const state = operatorReducer(undefined, {
type: actionTypes.creatingResource as any,
});
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: false, csv: false, resource: true },
});
expect(
operatorReducer(undefined, {
type: actionTypes.errorResourceCreate as any,
Expand All @@ -216,7 +263,11 @@ describe("catalogReducer", () => {
type: actionTypes.requestCustomResources as any,
});
const resource = {} as IResource;
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: false, csv: false, resource: true },
});
expect(
operatorReducer(undefined, {
type: actionTypes.receiveCustomResources as any,
Expand All @@ -229,7 +280,11 @@ describe("catalogReducer", () => {
const state = operatorReducer(undefined, {
type: actionTypes.requestCustomResources as any,
});
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: false, csv: false, resource: true },
});
expect(
operatorReducer(undefined, {
type: actionTypes.errorCustomResource as any,
Expand All @@ -243,7 +298,11 @@ describe("catalogReducer", () => {
type: actionTypes.requestCustomResource as any,
});
const resource = {} as IResource;
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: false, csv: false, resource: true },
});
expect(
operatorReducer(undefined, {
type: actionTypes.receiveCustomResource as any,
Expand All @@ -256,12 +315,38 @@ describe("catalogReducer", () => {
const state = operatorReducer(undefined, {
type: actionTypes.deletingResource as any,
});
expect(state).toEqual({ ...initialState, isFetching: true });
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: false, operator: false, csv: false, resource: true },
});
expect(
operatorReducer(undefined, {
type: actionTypes.resourceDeleted as any,
}),
).toEqual({ ...initialState, isFetching: false });
});

it("marks as still fetching if some resource is still fetching", () => {
let state = operatorReducer(undefined, {
type: actionTypes.checkingOLM as any,
});
state = operatorReducer(state, {
type: actionTypes.requestOperator as any,
});
expect(state).toEqual({
...initialState,
isFetching: true,
isFetchingElem: { OLM: true, operator: true, csv: false, resource: false },
});
state = operatorReducer(state, {
type: actionTypes.OLMInstalled as any,
});
expect(state.isFetching).toBe(true);
state = operatorReducer(state, {
type: actionTypes.receiveOperator as any,
});
expect(state.isFetching).toBe(false);
});
});
});
Loading

0 comments on commit 59064ac

Please sign in to comment.