Skip to content

Commit

Permalink
fix(editservicemodal): show error if service was not found
Browse files Browse the repository at this point in the history
Closes DCOS_OSS-2355
  • Loading branch information
Daniel Schmidt committed Apr 9, 2018
1 parent 1d05008 commit 3e83da3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
18 changes: 17 additions & 1 deletion plugins/services/src/js/components/modals/EditServiceModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,33 @@ import CreateServiceModal
from "#PLUGINS/services/src/js/components/modals/CreateServiceModal";
import DCOSStore from "#SRC/js/stores/DCOSStore";
import FullScreenModal from "#SRC/js/components/modals/FullScreenModal";
import RequestErrorMsg from "#SRC/js/components/RequestErrorMsg";
import Page from "#SRC/js/components/Page";

class EditServiceModal extends Component {
render() {
const { id = "/" } = this.props.params;
const serviceID = decodeURIComponent(id);
const serviceLoaded = DCOSStore.serviceDataReceived;
const service = DCOSStore.serviceTree.findItemById(serviceID);

if (!service) {
// Loading, showing an empty modal instead
if (!serviceLoaded) {
return <FullScreenModal open={true} />;
}

// Service not found
if (!service) {
return (
<Page>
<Page.Header />
<RequestErrorMsg
header={<p>This service does not exist, you can not edit it</p>}
/>
</Page>
);
}

if (
service.getLabels().DCOS_PACKAGE_DEFINITION != null ||
service.getLabels().DCOS_PACKAGE_METADATA != null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
import React from "react";
import { shallow } from "enzyme";
import { shallow, mount } from "enzyme";

jest.mock("#SRC/js/stores/DCOSStore");

const DCOSStore = require("#SRC/js/stores/DCOSStore");
const EditServiceModal = require("../EditServiceModal").default;

describe("EditServiceModal", function() {
it("renders an empty modal if no service is found", function() {
it("renders an empty modal if the service is loaded", function() {
DCOSStore.serviceDataReceived = false;
DCOSStore.serviceTree = {
findItemById() {
return null;
}
};

const wrapper = shallow(
<EditServiceModal params={{ id: "/my-non-existant-service" }} />
<EditServiceModal params={{ id: "/my-service" }} />
);
expect(wrapper.type().name).toBe("FullScreenModal");
});

it("renders an error if the service could not be found", function() {
DCOSStore.serviceDataReceived = true;
DCOSStore.serviceTree = {
findItemById() {
return null;
}
};

const wrapper = mount(
<EditServiceModal params={{ id: "/my-non-existant-service" }} />
);

expect(wrapper.text()).toContain(
"This service does not exist, you can not edit it"
);
});

it("renders an edit modal if the service has been created", function() {
DCOSStore.serviceDataReceived = true;
DCOSStore.serviceTree = {
findItemById() {
return {
Expand All @@ -38,6 +57,7 @@ describe("EditServiceModal", function() {
});

it("renders a create modal if the service has not been created", function() {
DCOSStore.serviceDataReceived = true;
DCOSStore.serviceTree = {
findItemById() {
return {
Expand Down

0 comments on commit 3e83da3

Please sign in to comment.