Skip to content

Commit

Permalink
Remove service watching from AccessURLTable (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor committed Jun 21, 2019
1 parent 15ed9e0 commit b20f0d8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 99 deletions.
Expand Up @@ -12,46 +12,7 @@ import AccessURLTable from "./AccessURLTable";
describe("componentDidMount", () => {
it("fetches ingresses", () => {
const mock = jest.fn();
shallow(
<AccessURLTable
services={[]}
ingresses={[]}
fetchIngresses={mock}
watchServices={jest.fn()}
closeWatches={jest.fn()}
/>,
);
expect(mock).toHaveBeenCalled();
});

it("initiates a watch on services", () => {
const mock = jest.fn();
shallow(
<AccessURLTable
services={[]}
ingresses={[]}
fetchIngresses={jest.fn()}
watchServices={mock}
closeWatches={jest.fn()}
/>,
);
expect(mock).toHaveBeenCalled();
});
});

describe("componentWillUnmount", () => {
it("closes watches on the Services", () => {
const mock = jest.fn();
const wrapper = shallow(
<AccessURLTable
services={[]}
ingresses={[]}
fetchIngresses={jest.fn()}
watchServices={mock}
closeWatches={jest.fn()}
/>,
);
wrapper.unmount();
shallow(<AccessURLTable services={[]} ingresses={[]} fetchIngresses={mock} />);
expect(mock).toHaveBeenCalled();
});
});
Expand Down Expand Up @@ -81,13 +42,7 @@ context("when fetching ingresses or services", () => {

it("renders a message if there are no services or ingresses", () => {
const wrapper = shallow(
<AccessURLTable
services={[]}
ingresses={[]}
fetchIngresses={jest.fn()}
watchServices={jest.fn()}
closeWatches={jest.fn()}
/>,
<AccessURLTable services={[]} ingresses={[]} fetchIngresses={jest.fn()} />,
);
expect(
wrapper
Expand Down Expand Up @@ -120,13 +75,7 @@ context("when the app contains services", () => {
} as IResource;
const services = [{ isFetching: false, item: service }];
const wrapper = shallow(
<AccessURLTable
services={services}
ingresses={[]}
fetchIngresses={jest.fn()}
watchServices={jest.fn()}
closeWatches={jest.fn()}
/>,
<AccessURLTable services={services} ingresses={[]} fetchIngresses={jest.fn()} />,
);
expect(
wrapper
Expand All @@ -152,13 +101,7 @@ context("when the app contains services", () => {
} as IResource;
const services = [{ isFetching: false, item: service }];
const wrapper = shallow(
<AccessURLTable
services={services}
ingresses={[]}
fetchIngresses={jest.fn()}
watchServices={jest.fn()}
closeWatches={jest.fn()}
/>,
<AccessURLTable services={services} ingresses={[]} fetchIngresses={jest.fn()} />,
);
expect(wrapper.find(AccessURLItem)).toExist();
expect(wrapper).toMatchSnapshot();
Expand All @@ -185,13 +128,7 @@ context("when the app contains ingresses", () => {
} as IResource;
const ingresses = [{ isFetching: false, item: ingress }];
const wrapper = shallow(
<AccessURLTable
services={[]}
ingresses={ingresses}
fetchIngresses={jest.fn()}
watchServices={jest.fn()}
closeWatches={jest.fn()}
/>,
<AccessURLTable services={[]} ingresses={ingresses} fetchIngresses={jest.fn()} />,
);
expect(wrapper.find(AccessURLItem)).toExist();
expect(wrapper).toMatchSnapshot();
Expand Down Expand Up @@ -232,13 +169,7 @@ context("when the app contains services and ingresses", () => {
} as IResource;
const ingresses = [{ isFetching: false, item: ingress }];
const wrapper = shallow(
<AccessURLTable
services={services}
ingresses={ingresses}
fetchIngresses={jest.fn()}
watchServices={jest.fn()}
closeWatches={jest.fn()}
/>,
<AccessURLTable services={services} ingresses={ingresses} fetchIngresses={jest.fn()} />,
);
expect(wrapper.find(AccessURLItem)).toExist();
expect(wrapper).toMatchSnapshot();
Expand All @@ -250,13 +181,7 @@ context("when the app contains resources with errors", () => {
const services = [{ isFetching: false, error: new Error("could not find Service") }];
const ingresses = [{ isFetching: false, error: new Error("could not find Ingress") }];
const wrapper = shallow(
<AccessURLTable
services={services}
ingresses={ingresses}
fetchIngresses={jest.fn()}
watchServices={jest.fn()}
closeWatches={jest.fn()}
/>,
<AccessURLTable services={services} ingresses={ingresses} fetchIngresses={jest.fn()} />,
);

// The Service error is not shown, as it is filtered out because without the
Expand Down
Expand Up @@ -11,20 +11,13 @@ interface IAccessURLTableProps {
services: Array<IKubeItem<IResource>>;
ingresses: Array<IKubeItem<IResource>>;
fetchIngresses: () => void;
watchServices: () => void;
closeWatches: () => void;
}

class AccessURLTable extends React.Component<IAccessURLTableProps> {
public componentDidMount() {
// Fetch all related Ingress resources. We don't need to fetch Services as
// they are expected to be watched by the ServiceTable.
this.props.fetchIngresses();
this.props.watchServices();
}

public componentWillUnmount() {
this.props.closeWatches();
}

public render() {
Expand Down
Expand Up @@ -32,16 +32,6 @@ function mapDispatchToProps(
dispatch(actions.kube.getResource(r));
});
},
watchServices: () => {
props.serviceRefs.forEach(r => {
dispatch(actions.kube.getAndWatchResource(r));
});
},
closeWatches: () => {
props.serviceRefs.forEach(r => {
dispatch(actions.kube.closeWatchResource(r));
});
},
};
}

Expand Down

0 comments on commit b20f0d8

Please sign in to comment.