From 71d6358a8f787c5d2688a485d42ff9514dc58a56 Mon Sep 17 00:00:00 2001 From: brunomilitzer Date: Thu, 8 Jul 2021 15:33:55 +0100 Subject: Add Upload Control Loop Instantiation Created Functionality to Upload JSON file to Control Loop Instantiation. Issue-ID: POLICY-3436 Change-Id: Iefd538c91154b7e61615ab63b440378e2feea502 Signed-off-by: brunomilitzer --- .../dialogs/ControlLoop/ControlLoopElementItem.js | 124 ------------------- .../dialogs/ControlLoop/ControlLoopElements.js | 41 ------- .../dialogs/ControlLoop/ControlLoopItem.js | 128 ------------------- .../ControlLoop/InstantiationElementItem.js | 124 +++++++++++++++++++ .../dialogs/ControlLoop/InstantiationElements.js | 41 +++++++ .../dialogs/ControlLoop/InstantiationItem.js | 128 +++++++++++++++++++ .../dialogs/ControlLoop/MonitorInstantiation.js | 72 +++++++++++ .../ControlLoop/MonitorInstantiation.test.js | 64 ++++++++++ .../ControlLoop/MonitoringControlLoopModal.js | 71 ----------- .../ControlLoop/UploadToscaInstantiation.js | 136 +++++++++++++++++++++ .../ControlLoop/UploadToscaInstantiation.test.js | 102 ++++++++++++++++ .../ControlLoop/UploadToscaInstantiationFile.js | 52 ++++++++ .../UploadToscaInstantiationFile.test.js | 61 +++++++++ .../MonitorInstantiation.test.js.snap | 32 +++++ .../UploadToscaInstantiation.test.js.snap | 91 ++++++++++++++ .../UploadToscaInstantiationFile.test.js.snap | 16 +++ 16 files changed, 919 insertions(+), 364 deletions(-) delete mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElementItem.js delete mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElements.js delete mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopItem.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElementItem.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElements.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationItem.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js delete mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitoringControlLoopModal.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.test.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.test.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/MonitorInstantiation.test.js.snap create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiation.test.js.snap create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiationFile.test.js.snap (limited to 'gui-clamp/ui-react/src/components/dialogs/ControlLoop') diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElementItem.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElementItem.js deleted file mode 100644 index 632cacd..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElementItem.js +++ /dev/null @@ -1,124 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -import React, { useEffect, useState } from "react"; -import styled from "styled-components"; -import { Button } from "react-bootstrap"; - -const UninitialisedBox = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #cccccc; - font-weight: normal; - border-radius: 0; -` -const PassiveBox = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #ffe87c; - font-weight: normal; - border-radius: 0; -` -const RunningBox = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #7ec699; - font-weight: normal; - border-radius: 0; -` -const ButtonStyle = styled(Button)` - margin: 0; - padding: 5px 12px; - width: 100%; - text-align: left; - background: transparent !important; - color: #000000 !important; - text-decoration: none !important; - border: none; - border-radius: 0; - - :hover, :active :focus { - color: #000000 !important; - outline: 0 !important; - box-shadow: none !important; - background: transparent !important; - text-decoration: none !important; - } -` - -const ControlLoopElementItem = (props) => { - const [title, setTitle] = useState(""); - - useEffect(() => { - const title = props.title.split("."); - setTitle(title[4]); - }, []); - - const toggleState = () => { - switch (props.orderedState) { - case 'UNINITIALISED': - return renderUninitialisedOrderedState(); - case 'PASSIVE': - return renderPassiveOrderedState(); - case 'RUNNING': - return renderRunningOrderedState(); - } - } - - const renderUninitialisedOrderedState = () => { - return ( - - - - ) - } - - const renderPassiveOrderedState = () => { - return ( - - - - ) - } - - const renderRunningOrderedState = () => { - return ( - - - - ) - } - - return ( - - { toggleState() } - - ); -} - -export default ControlLoopElementItem; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElements.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElements.js deleted file mode 100644 index 57bdf40..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopElements.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -import React, { useEffect, useState } from "react"; -import ControlLoopElementItem from "./ControlLoopElementItem"; - -const ControlLoopElements = (props) => { - const [clElements, setClElements] = useState([]); - - useEffect(() => { - setClElements(Object.values(props.elements)); - }, []); - - return ( - - { - clElements.map((clEl, index) => ( - - )) - } - - ); -} - -export default ControlLoopElements; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopItem.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopItem.js deleted file mode 100644 index f149517..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ControlLoopItem.js +++ /dev/null @@ -1,128 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -import React from "react"; -import styled from 'styled-components'; - -import { Accordion, Button, Card } from "react-bootstrap"; - -const AccordionBody = styled.div` - margin: 0; - padding: 0; - border: 1px solid #7f7f7f; - border-radius: 0; -` - -const CardBody = styled(Card.Body)` - padding: 0; - margin: 0; -` - -const UninitialisedHeader = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #cccccc; - font-weight: normal; - border-radius: 0; -` - -const PassiveHeader = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #ffe87c; - font-weight: normal; - border-radius: 0; -` - -const RunningHeader = styled.div` - margin: 0; - padding: 0 0 1px 0; - border-bottom: 1px solid #7f7f7f; - background: #7ec699; - font-weight: normal; - border-radius: 0; -` - -const ToggleButton = styled(Button)` - color: #000000; - text-decoration: none; - - :hover, :active { - color: #000000; - text-decoration: none !important; - } -` - -const ControlLoopItem = (props) => { - const toggleState = () => { - switch (props.orderedState) { - case 'UNINITIALISED': - return renderUninitialisedOrderedState() - case 'PASSIVE': - return renderPassiveOrderedState(); - case 'RUNNING': - return renderRunningOrderedState(); - } - } - - const renderUninitialisedOrderedState = () => { - return ( - - - { props.title } - - - ) - } - - const renderPassiveOrderedState = () => { - return ( - - - { props.title } - - - ) - } - - const renderRunningOrderedState = () => { - return ( - - - { props.title } - - - ) - } - - return ( - - - { toggleState() } - - { props.children } - - - - ); -} - -export default ControlLoopItem; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElementItem.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElementItem.js new file mode 100644 index 0000000..0e2c407 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElementItem.js @@ -0,0 +1,124 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React, { useEffect, useState } from "react"; +import styled from "styled-components"; +import { Button } from "react-bootstrap"; + +const UninitialisedBox = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #cccccc; + font-weight: normal; + border-radius: 0; +` +const PassiveBox = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #ffe87c; + font-weight: normal; + border-radius: 0; +` +const RunningBox = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #7ec699; + font-weight: normal; + border-radius: 0; +` +const ButtonStyle = styled(Button)` + margin: 0; + padding: 5px 12px; + width: 100%; + text-align: left; + background: transparent !important; + color: #000000 !important; + text-decoration: none !important; + border: none; + border-radius: 0; + + :hover, :active :focus { + color: #000000 !important; + outline: 0 !important; + box-shadow: none !important; + background: transparent !important; + text-decoration: none !important; + } +` + +const InstantiationElementItem = (props) => { + const [title, setTitle] = useState(""); + + useEffect(() => { + const title = props.title.split("."); + setTitle(title[4]); + }, []); + + const toggleState = () => { + switch (props.orderedState) { + case 'UNINITIALISED': + return renderUninitialisedOrderedState(); + case 'PASSIVE': + return renderPassiveOrderedState(); + case 'RUNNING': + return renderRunningOrderedState(); + } + } + + const renderUninitialisedOrderedState = () => { + return ( + + + + ) + } + + const renderPassiveOrderedState = () => { + return ( + + + + ) + } + + const renderRunningOrderedState = () => { + return ( + + + + ) + } + + return ( + + { toggleState() } + + ); +} + +export default InstantiationElementItem; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElements.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElements.js new file mode 100644 index 0000000..d8e6348 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationElements.js @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React, { useEffect, useState } from "react"; +import InstantiationElementItem from "./InstantiationElementItem"; + +const InstantiationElements = (props) => { + const [clElements, setClElements] = useState([]); + + useEffect(() => { + setClElements(Object.values(props.elements)); + }, []); + + return ( + + { + clElements.map((clEl, index) => ( + + )) + } + + ); +} + +export default InstantiationElements; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationItem.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationItem.js new file mode 100644 index 0000000..a59770b --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationItem.js @@ -0,0 +1,128 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React from "react"; +import styled from 'styled-components'; + +import { Accordion, Button, Card } from "react-bootstrap"; + +const AccordionBody = styled.div` + margin: 0; + padding: 0; + border: 1px solid #7f7f7f; + border-radius: 0; +` + +const CardBody = styled(Card.Body)` + padding: 0; + margin: 0; +` + +const UninitialisedHeader = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #cccccc; + font-weight: normal; + border-radius: 0; +` + +const PassiveHeader = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #ffe87c; + font-weight: normal; + border-radius: 0; +` + +const RunningHeader = styled.div` + margin: 0; + padding: 0 0 1px 0; + border-bottom: 1px solid #7f7f7f; + background: #7ec699; + font-weight: normal; + border-radius: 0; +` + +const ToggleButton = styled(Button)` + color: #000000; + text-decoration: none; + + :hover, :active { + color: #000000; + text-decoration: none !important; + } +` + +const InstantiationItem = (props) => { + const toggleState = () => { + switch (props.orderedState) { + case 'UNINITIALISED': + return renderUninitialisedOrderedState() + case 'PASSIVE': + return renderPassiveOrderedState(); + case 'RUNNING': + return renderRunningOrderedState(); + } + } + + const renderUninitialisedOrderedState = () => { + return ( + + + { props.title } + + + ) + } + + const renderPassiveOrderedState = () => { + return ( + + + { props.title } + + + ) + } + + const renderRunningOrderedState = () => { + return ( + + + { props.title } + + + ) + } + + return ( + + + { toggleState() } + + { props.children } + + + + ); +} + +export default InstantiationItem; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.js new file mode 100644 index 0000000..428defa --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.js @@ -0,0 +1,72 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React, { useEffect, useState } from "react"; +import styled from "styled-components"; +import Modal from "react-bootstrap/Modal"; +import Button from "react-bootstrap/Button"; +import InstantiationItem from "./InstantiationItem"; +import ControlLoopService from "../../../api/ControlLoopService"; +import InstantiationElements from "./InstantiationElements"; + +const ModalStyled = styled(Modal)` + background-color: transparent; +` + +const MonitorInstantiation = (props) => { + const [show, setShow] = useState(true); + const [controlLoopList, setControlLoopList] = useState([]); + const [windowLocationPathname, setWindowLocationPathname] = useState(''); + + useEffect(() => { + setWindowLocationPathname(window.location.pathname); + + ControlLoopService.fetchControlLoopInstantiation(windowLocationPathname).then(controlLoopList => { + setControlLoopList(controlLoopList['controlLoopList']); + }); + }, []) + + const handleClose = () => { + console.log('handleClose called'); + setShow(false); + props.history.push('/'); + } + + return ( + + + Tosca Instantiation - Monitoring + + + { + controlLoopList.map((clList, index) => ( + + + + )) + } + + + + + + ) +} + +export default MonitorInstantiation; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js new file mode 100644 index 0000000..5e30924 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js @@ -0,0 +1,64 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import { mount, shallow } from "enzyme"; +import toJson from "enzyme-to-json"; +import { createMemoryHistory } from "history"; +import React from "react"; +import MonitorInstantiation from "./MonitorInstantiation"; +import { act } from "react-dom/test-utils"; + +describe('Verify MonitoringInstantiation', () => { + + it("renders without crashing", () => { + shallow(); + }); + + it("renders correctly", () => { + const tree = shallow(); + expect(toJson(tree)).toMatchSnapshot(); + }); + + it('should have a Button element', () => { + const container = shallow() + expect(container.find('Button').length).toEqual(1); + }); + + it('handleClose called when bottom button clicked', () => { + const history = createMemoryHistory(); + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + act(() => { + component.find('[variant="secondary"]').simulate('click'); + expect(logSpy).toHaveBeenCalledWith('handleClose called'); + }); + }); + + it('handleClose called when top-right button clicked', () => { + const history = createMemoryHistory(); + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + act(() => { + component.find('[size="xl"]').get(0).props.onHide(); + expect(logSpy).toHaveBeenCalledWith('handleClose called'); + }); + }); +}); diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitoringControlLoopModal.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitoringControlLoopModal.js deleted file mode 100644 index 03fb64b..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitoringControlLoopModal.js +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -import React, { useEffect, useState } from "react"; -import styled from "styled-components"; -import Modal from "react-bootstrap/Modal"; -import Button from "react-bootstrap/Button"; -import ControlLoopItem from "./ControlLoopItem"; -import ControlLoopService from "../../../api/ControlLoopService"; -import ControlLoopElements from "./ControlLoopElements"; - -const ModalStyled = styled(Modal)` - background-color: transparent; -` - -const MonitoringControlLoopModal = (props) => { - const [show, setShow] = useState(true); - const [controlLoopList, setControlLoopList] = useState([]); - const [windowLocationPathname, setWindowLocationPathname] = useState(''); - - useEffect(() => { - setWindowLocationPathname(window.location.pathname); - - ControlLoopService.getControlLoopList(windowLocationPathname).then(controlLoopList => { - setControlLoopList(controlLoopList['controlLoopList']); - }); - }, []) - - const handleClose = () => { - setShow(false); - props.history.push('/'); - } - - return ( - - - Tosca Control Loop - Monitoring - - - { - controlLoopList.map((clList, index) => ( - - - - )) - } - - - - - - ) -} - -export default MonitoringControlLoopModal; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.js new file mode 100644 index 0000000..d9bbe8b --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.js @@ -0,0 +1,136 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React, { useState } from "react"; +import Modal from "react-bootstrap/Modal"; +import Button from "react-bootstrap/Button"; +import styled from "styled-components"; +import Row from "react-bootstrap/Row"; +import Form from "react-bootstrap/Form"; +import UploadToscaInstantiationFile from "./UploadToscaInstantiationFile"; +import jsYaml from "js-yaml"; +import Alert from "react-bootstrap/Alert"; + +const ModalStyled = styled(Modal)` + background-color: transparent; +` +const StyledMessagesDiv = styled.div` + overflow: auto; + min-width: 100%; + max-height: 300px; + padding: 5px 5px 0px 5px; + text-align: center; +` + +const UploadToscaInstantiation = (props) => { + const [show, setShow] = useState(true); + const [fileIsSelected, setFileIsSelected] = useState(false); + const [selectedFile, setSelectedFile] = useState(); + const [jsonObject, setJsonObject] = useState([]); + const [alertMessages, setAlertMessages] = useState(); + + const fileUploadHandler = (event) => { + event.preventDefault(); + console.log('fileUploadHandler called'); + + const file = event.currentTarget.files[0]; + + if (file !== undefined) { + console.log('fileDefined called'); + setSelectedFile(file); + setFileIsSelected(true); + + const fileReader = new FileReader(); + fileReader.onload = () => { + const jsonFile = jsYaml.load(fileReader.result, 'utf8') + setJsonObject(jsonFile) + } + + fileReader.readAsText(file); + } else { + console.log('fileUndefined called'); + } + } + + const onResponseReceivedHandler = async (response) => { + console.log('onResponseReceivedHandler called'); + + if (await response.ok) { + setAlertMessages( + Upload Success +

Tosca Instantiation from { selectedFile.name } was Successfully Uploaded

+
+

Type: { selectedFile.type }

Size: { +selectedFile.size / 1000 }Kb

+
); + } else { + setAlertMessages( + Upload Failure +

Tosca Instantiation from { selectedFile.name } failed to upload

+

Status code: { await response.status }: { response.statusText }

+

Response Text: { await response.text() }

+
+

Type: { selectedFile.type }

Size: { +selectedFile.size / 1000 }Kb

+
); + } + } + + const handleClose = () => { + console.log('handleClose called'); + setShow(false); + props.history.push('/'); + } + + return ( + + + Tosca Control Loop - Create Instantiation + +
+ +
+ + + + Only .yaml, .yml and .json files are supported + + + + { alertMessages } + + +
+
+
+ + + +
+ ) +} + +export default UploadToscaInstantiation; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.test.js new file mode 100644 index 0000000..79daafb --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiation.test.js @@ -0,0 +1,102 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import { mount, shallow } from "enzyme"; +import React from "react"; +import toJson from "enzyme-to-json"; +import UploadToscaInstantiation from "./UploadToscaInstantiation"; +import { createMemoryHistory } from "history"; +import { act } from "react-dom/test-utils"; + +describe("Verify UploadToscaInstantiation", () => { + const fs = require("fs"); + const jsonFile = fs.readFileSync("src/components/dialogs/Policy/toscaInstantiationData.test.json"); + const file = new Blob([jsonFile], { type: 'file' }); + + it("renders without crashing", () => { + shallow(); + }); + + it("renders correctly", () => { + const tree = shallow(); + expect(toJson(tree)).toMatchSnapshot(); + }); + + it('should have a Button element', () => { + const container = shallow() + expect(container.find('Button').length).toEqual(1); + }); + + it('handleClose called when bottom button clicked', () => { + const history = createMemoryHistory(); + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + + act(() => { + component.find('[variant="secondary"]').simulate('click'); + expect(logSpy).toHaveBeenCalledWith('handleClose called'); + }); + }); + + it('handleClose called when top-right button clicked', () => { + const history = createMemoryHistory(); + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + + act(() => { + component.find('[size="lg"]').get(0).props.onHide(); + expect(logSpy).toHaveBeenCalledWith('handleClose called'); + }); + }); + + it('fileUploadHandler called when uploading a defined file', () => { + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + const event = { + preventDefault() { + }, + currentTarget: { files: [file] } + }; + + act(() => { + component.find('[type="file"]').get(0).props.onChange(event); + expect(logSpy).toHaveBeenCalledWith('fileUploadHandler called'); + expect(logSpy).toHaveBeenCalledWith('fileDefined called'); + }); + }); + + it('fileUploadHandler called when uploading a undefined file', () => { + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + const event = { + preventDefault() { + }, + currentTarget: { files: [] } + }; + + act(() => { + component.find('[type="file"]').get(0).props.onChange(event); + expect(logSpy).toHaveBeenCalledWith('fileUndefined called'); + }); + }); +}); diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.js new file mode 100644 index 0000000..5329bc0 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.js @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import React, { useEffect, useState } from "react"; +import Button from "react-bootstrap/Button"; +import ControlLoopService from "../../../api/ControlLoopService"; + +const UploadToscaInstantiationFile = (props) => { + const [windowLocationPathName, setWindowLocationPathname] = useState(''); + + const postToscaInstantiationHandler = async (event) => { + event.preventDefault(); + console.log('postToscaInstantiationHandler called'); + + setWindowLocationPathname(window.location.pathname); + + const response = await ControlLoopService.uploadToscaInstantiation(props.jsonObject, windowLocationPathName) + .catch(error => error.message); + + props.onResponseReceived(response); + } + + return ( + + + + ); +} + +export default UploadToscaInstantiationFile; + diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.test.js new file mode 100644 index 0000000..83ab8d5 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaInstantiationFile.test.js @@ -0,0 +1,61 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import { mount, shallow } from "enzyme"; +import React from "react"; +import UploadToscaInstantiationFile from "./UploadToscaInstantiationFile"; +import toJson from "enzyme-to-json"; +import { act } from "react-dom/test-utils"; + +describe('Verify UploadToscaInstantiationFile', () => { + + it("renders without crashing", () => { + shallow(); + }); + + it("renders correctly", () => { + const tree = shallow(); + expect(toJson(tree)).toMatchSnapshot(); + }); + + it('should have a Button element', () => { + const container = shallow() + expect(container.find('Button').length).toEqual(1); + }); + + it('Button should have a specific text', () => { + const container = shallow() + expect(container.find('Button').text()).toBe('Upload Tosca Instantiation'); + }); + + it('button should call postToscaInstantiationHandler when clicked', async () => { + const mockFunction = jest.fn(() => 'default'); + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + const event = { + preventDefault() { + } + }; + + await act(async () => { + component.find('[variant="primary"]').get(0).props.onClick(event); + expect(logSpy).toHaveBeenCalledWith('postToscaInstantiationHandler called'); + }); + }); +}); diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/MonitorInstantiation.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/MonitorInstantiation.test.js.snap new file mode 100644 index 0000000..6504b54 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/MonitorInstantiation.test.js.snap @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Verify MonitoringInstantiation renders correctly 1`] = ` + + + + Tosca Instantiation - Monitoring + + + + + + + +`; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiation.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiation.test.js.snap new file mode 100644 index 0000000..77e4b99 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiation.test.js.snap @@ -0,0 +1,91 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Verify UploadToscaInstantiation renders correctly 1`] = ` + + + + Tosca Control Loop - Create Instantiation + + +
+ +
+ + + + + Only .yaml, .yml and .json files are supported + + + + + +
+
+
+ + + +
+`; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiationFile.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiationFile.test.js.snap new file mode 100644 index 0000000..3ac5087 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaInstantiationFile.test.js.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Verify UploadToscaInstantiationFile renders correctly 1`] = ` + + + +`; -- cgit 1.2.3-korg