increase test coverage for ServiceMesh component (#85)

* increased test coverage for ServiceMesh component

Signed-off-by: Franziska von der Goltz <franziska@vdgoltz.eu>
This commit is contained in:
Franziska von der Goltz 2018-01-03 09:50:29 -08:00 committed by GitHub
parent 449f306aeb
commit a7306113d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 115 additions and 31 deletions

View File

@ -17,7 +17,7 @@ describe('ServiceMesh', () => {
}
beforeEach(() => {
fetchStub = sinon.stub(window, 'fetch');
fetchStub = sinon.stub(window, 'fetch').returnsPromise();
});
afterEach(() => {
@ -27,7 +27,7 @@ describe('ServiceMesh', () => {
it("displays an error if the api call didn't go well", () => {
let errorMsg = "Something went wrong!";
fetchStub.returnsPromise().resolves({
fetchStub.resolves({
ok: false,
statusText: errorMsg
});
@ -38,59 +38,143 @@ describe('ServiceMesh', () => {
});
});
it("displays message for no deployments detetcted", () => {
fetchStub.returnsPromise().resolves({
it("renders the spinner before metrics are loaded", () => {
component = mount(routerWrap(ServiceMesh));
expect(component.find("ConduitSpinner")).to.have.length(1);
expect(component.find("ServiceMesh")).to.have.length(1);
expect(component.find("CallToAction")).to.have.length(0);
});
it("renders a call to action if no metrics are received", () => {
fetchStub.resolves({
ok: true,
json: () => Promise.resolve({ pods: []})
json: () => Promise.resolve({ metrics: [] })
});
component = mount(routerWrap(ServiceMesh));
return withPromise(() => {
expect(component.html()).to.include("No deployments detected.");
expect(component.find("ServiceMesh")).to.have.length(1);
expect(component.find("ConduitSpinner")).to.have.length(0);
expect(component.find("CallToAction")).to.have.length(1);
});
});
it("displays message for more than one deployment added to servicemesh", () => {
fetchStub.returnsPromise().resolves({
ok: true,
json: () => Promise.resolve({ pods: podFixtures.pods})
});
component = mount(routerWrap(ServiceMesh));
return withPromise(() => {
expect(component.html()).to.include("deployments have not been added to the service mesh.");
});
});
it("displays message for only one deployment not added to servicemesh", () => {
let addedPods = _.clone(podFixtures.pods);
it("renders controller component summaries", () => {
let addedPods = _.cloneDeep(podFixtures.pods);
_.set(addedPods[0], "added", true);
fetchStub.returnsPromise().resolves({
fetchStub.resolves({
ok: true,
json: () => Promise.resolve({ pods: addedPods})
});
component = mount(routerWrap(ServiceMesh));
return withPromise(() => {
expect(component.html()).to.include("1 deployment has not been added to the service mesh.");
expect(component.find("ServiceMesh")).to.have.length(1);
expect(component.find("ConduitSpinner")).to.have.length(0);
expect(component.find("DeploymentSummary")).to.have.length(3);
});
});
it("displays message for all deployments added to servicemesh", () => {
let addedPods = _.clone(podFixtures.pods);
_.forEach(addedPods, pod => {
_.set(pod, "added", true);
});
fetchStub.returnsPromise().resolves({
it("renders service mesh details section", () => {
fetchStub.resolves({
ok: true,
json: () => Promise.resolve({ pods: addedPods})
json: () => Promise.resolve({ metrics: [] })
});
component = mount(routerWrap(ServiceMesh));
return withPromise(() => {
expect(component.html()).to.include("All deployments have been added to the service mesh.");
expect(component.find("ServiceMesh")).to.have.length(1);
expect(component.find("ConduitSpinner")).to.have.length(0);
expect(component.html()).to.include("Service mesh details");
expect(component.html()).to.include("Conduit version");
});
});
it("renders control plane section", () => {
fetchStub.resolves({
ok: true,
json: () => Promise.resolve({ metrics: [] })
});
component = mount(routerWrap(ServiceMesh));
return withPromise(() => {
expect(component.find("ServiceMesh")).to.have.length(1);
expect(component.find("ConduitSpinner")).to.have.length(0);
expect(component.html()).to.include("Control plane");
});
});
it("renders data plane section", () => {
fetchStub.resolves({
ok: true,
json: () => Promise.resolve({ metrics: [] })
});
component = mount(routerWrap(ServiceMesh));
return withPromise(() => {
expect(component.find("ServiceMesh")).to.have.length(1);
expect(component.find("ConduitSpinner")).to.have.length(0);
expect(component.html()).to.include("Data plane");
});
});
describe("renderAddDeploymentsMessage", () => {
it("displays when no deployments are in the mesh", () => {
fetchStub.resolves({
ok: true,
json: () => Promise.resolve({ pods: []})
});
component = mount(routerWrap(ServiceMesh));
return withPromise(() => {
expect(component.html()).to.include("No deployments detected.");
});
});
it("displays a message if >1 deployment has not been added to the mesh", () => {
fetchStub.resolves({
ok: true,
json: () => Promise.resolve({ pods: podFixtures.pods})
});
component = mount(routerWrap(ServiceMesh));
return withPromise(() => {
expect(component.html()).to.include("deployments have not been added to the service mesh.");
});
});
it("displays a message if 1 deployment has not added to servicemesh", () => {
let addedPods = _.cloneDeep(podFixtures.pods);
_.set(addedPods[0], "added", true);
fetchStub.resolves({
ok: true,
json: () => Promise.resolve({ pods: addedPods})
});
component = mount(routerWrap(ServiceMesh));
return withPromise(() => {
expect(component.html()).to.include("1 deployment has not been added to the service mesh.");
});
});
it("displays a message if all deployments have been added to servicemesh", () => {
let addedPods = _.cloneDeep(podFixtures.pods);
_.forEach(addedPods, pod => {
_.set(pod, "added", true);
});
fetchStub.resolves({
ok: true,
json: () => Promise.resolve({ pods: addedPods})
});
component = mount(routerWrap(ServiceMesh));
return withPromise(() => {
expect(component.html()).to.include("All deployments have been added to the service mesh.");
});
});
});
});