-
Notifications
You must be signed in to change notification settings - Fork 705
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more robust way of loading resources for AppView sections (#918)
* store received resources from sockets in redux * wrap ServiceItems in a container and fetch Service data from Redux store * use apiVersion from returned resource The k8s API server keeps the apiVersion in the object consistent, so we can safely use it to key for our cache * just pass name down to ServiceItem instead of full serviceRef * add TODO comments about moving WebSockets to redux * add ResourceRef class for referencing resources * switch to using ResourceRef class from interface * add getResourceURL method to ResourceRef - make use of ResourceRef.getResourceURL in ServiceItemContainer to get cache key - use ResourceRef.getResourceURL as the React key for the map of ServiceItem components * fix AppView tests * remove unnecessary comment * fix tests * update ServiceItem tests switch from LoadingSpinner to LoadingWrapper * switch to main class constructor for ResourceRef * add ServiceItem test for calling getService * add ServiceItemContainer test * rename namespace to releaseNamespace in parseResources * ResourceRef: throw error if default namespace not defined * fix tests
- Loading branch information
Showing
16 changed files
with
483 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 103 additions & 36 deletions
139
dashboard/src/components/AppView/ServicesTable/ServiceItem.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,115 @@ | ||
import { shallow } from "enzyme"; | ||
import context from "jest-plugin-context"; | ||
import * as React from "react"; | ||
|
||
import { IResource } from "shared/types"; | ||
import itBehavesLike from "../../../shared/specs"; | ||
import { IKubeItem, IResource } from "../../../shared/types"; | ||
import ServiceItem from "./ServiceItem"; | ||
|
||
it("renders a simple view without IP", () => { | ||
const service = { | ||
metadata: { | ||
name: "foo", | ||
}, | ||
spec: { | ||
type: "ClusterIP", | ||
ports: [], | ||
}, | ||
} as IResource; | ||
const wrapper = shallow(<ServiceItem service={service} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
const kubeItem: IKubeItem<IResource> = { | ||
isFetching: false, | ||
}; | ||
|
||
describe("componentDidMount", () => { | ||
it("calls getService", () => { | ||
const mock = jest.fn(); | ||
shallow(<ServiceItem name="foo" getService={mock} />); | ||
expect(mock).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it("renders a simple view with IP", () => { | ||
const service = { | ||
metadata: { | ||
name: "foo", | ||
}, | ||
spec: { | ||
ports: [{ port: 80 }], | ||
type: "LoadBalancer", | ||
}, | ||
status: { | ||
loadBalancer: { | ||
ingress: [{ ip: "1.2.3.4" }], | ||
context("when fetching services", () => { | ||
[undefined, { isFetching: true }].forEach(service => { | ||
itBehavesLike("aLoadingComponent", { | ||
component: ServiceItem, | ||
props: { | ||
service, | ||
getService: jest.fn(), | ||
}, | ||
}, | ||
} as IResource; | ||
const wrapper = shallow(<ServiceItem service={service} />); | ||
expect(wrapper.text()).toContain("1.2.3.4"); | ||
}); | ||
it("displays the name of the Service", () => { | ||
const wrapper = shallow(<ServiceItem service={service} name="foo" getService={jest.fn()} />); | ||
expect(wrapper.text()).toContain("foo"); | ||
}); | ||
}); | ||
}); | ||
|
||
it("renders a view with IP", () => { | ||
context("when there is an error fetching the Service", () => { | ||
const service = { | ||
metadata: { name: "foo" }, | ||
spec: { ports: [{ port: 80 }], type: "LoadBalancer" }, | ||
status: { loadBalancer: { ingress: [{ ip: "1.2.3.4" }] } }, | ||
} as IResource; | ||
const wrapper = shallow(<ServiceItem service={service} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
error: new Error('services "foo" not found'), | ||
isFetching: false, | ||
}; | ||
const wrapper = shallow(<ServiceItem service={service} name="foo" getService={jest.fn()} />); | ||
|
||
it("diplays the Service name in the first column", () => { | ||
expect( | ||
wrapper | ||
.find("td") | ||
.first() | ||
.text(), | ||
).toEqual("foo"); | ||
}); | ||
|
||
it("displays the error message in the second column", () => { | ||
expect( | ||
wrapper | ||
.find("td") | ||
.at(1) | ||
.text(), | ||
).toContain('Error: services "foo" not found'); | ||
}); | ||
}); | ||
|
||
context("when there is a valid Service", () => { | ||
it("renders a simple view without IP", () => { | ||
const service = { | ||
metadata: { | ||
name: "foo", | ||
}, | ||
spec: { | ||
type: "ClusterIP", | ||
ports: [], | ||
}, | ||
} as IResource; | ||
kubeItem.item = service; | ||
const wrapper = shallow( | ||
<ServiceItem service={kubeItem} name={service.metadata.name} getService={jest.fn()} />, | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it("renders a simple view with IP", () => { | ||
const service = { | ||
metadata: { | ||
name: "foo", | ||
}, | ||
spec: { | ||
ports: [{ port: 80 }], | ||
type: "LoadBalancer", | ||
}, | ||
status: { | ||
loadBalancer: { | ||
ingress: [{ ip: "1.2.3.4" }], | ||
}, | ||
}, | ||
} as IResource; | ||
kubeItem.item = service; | ||
const wrapper = shallow( | ||
<ServiceItem service={kubeItem} name={service.metadata.name} getService={jest.fn()} />, | ||
); | ||
expect(wrapper.text()).toContain("1.2.3.4"); | ||
}); | ||
|
||
it("renders a view with IP", () => { | ||
const service = { | ||
metadata: { name: "foo" }, | ||
spec: { ports: [{ port: 80 }], type: "LoadBalancer" }, | ||
status: { loadBalancer: { ingress: [{ ip: "1.2.3.4" }] } }, | ||
} as IResource; | ||
kubeItem.item = service; | ||
const wrapper = shallow( | ||
<ServiceItem service={kubeItem} name={service.metadata.name} getService={jest.fn()} />, | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.