-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(editservicemodal): render empty modal if the service is not loaded
We accessed getLabel on the service without checking if the service is even there. Therefore reloading the edit page caused an error. By checking for a service and rendering an empty modal otherwise we make sure that we don't try to render before we have the data. Rendering the create form in these cases lead to a mutation of the data, which in return lead to the edit form never being rendered. Rendering null if there is no service lead to a dark flickering for the time before the service loads. An empty modal gives a nicer UX. Closes DCOS-21798
- Loading branch information
Daniel Schmidt
committed
Apr 4, 2018
1 parent
594c375
commit df5e92b
Showing
2 changed files
with
61 additions
and
0 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
56 changes: 56 additions & 0 deletions
56
plugins/services/src/js/components/modals/__tests__/EditServiceModal-test.js
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from "react"; | ||
import { shallow } 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() { | ||
DCOSStore.serviceTree = { | ||
findItemById() { | ||
return null; | ||
} | ||
}; | ||
|
||
const wrapper = shallow( | ||
<EditServiceModal params={{ id: "/my-non-existant-service" }} /> | ||
); | ||
expect(wrapper.type().name).toBe("FullScreenModal"); | ||
}); | ||
|
||
it("renders an edit modal if the service has been created", function() { | ||
DCOSStore.serviceTree = { | ||
findItemById() { | ||
return { | ||
getLabels() { | ||
return { DCOS_PACKAGE_DEFINITION: "some-value" }; | ||
} | ||
}; | ||
} | ||
}; | ||
|
||
const wrapper = shallow( | ||
<EditServiceModal params={{ id: "/my-created-service" }} /> | ||
); | ||
expect(wrapper.type().name).toBe("EditFrameworkConfiguration"); | ||
}); | ||
|
||
it("renders a create modal if the service has not been created", function() { | ||
DCOSStore.serviceTree = { | ||
findItemById() { | ||
return { | ||
getLabels() { | ||
return { DCOS_PACKAGE_DEFINITION: null }; | ||
} | ||
}; | ||
} | ||
}; | ||
|
||
const wrapper = shallow( | ||
<EditServiceModal params={{ id: "/my-new-service" }} /> | ||
); | ||
expect(wrapper.type().name).toBe("CreateServiceModal"); | ||
}); | ||
}); |