From 6687b48b58bf1248532de48f3e375b1f663f4015 Mon Sep 17 00:00:00 2001 From: "saul.gill" Date: Fri, 2 Jul 2021 17:10:54 +0100 Subject: Changed components to be service-centric Moved endpoints to ControlLoopService.js Refactored components and tests Issue-ID: POLICY-3424 Change-Id: I70d48750250eecd651b845ef0c726617983f75f5 Signed-off-by: saul.gill --- gui-clamp/ui-react/src/LoopUI.js | 4 +- gui-clamp/ui-react/src/api/ControlLoopService.js | 34 +++++ gui-clamp/ui-react/src/api/GetToscaTemplate.js | 56 -------- .../ui-react/src/api/GetToscaTemplate.test.js | 55 -------- gui-clamp/ui-react/src/api/UploadToscaFile.js | 63 --------- gui-clamp/ui-react/src/api/UploadToscaFile.test.js | 63 --------- .../__snapshots__/GetToscaTemplate.test.js.snap | 15 -- .../api/__snapshots__/UploadToscaFile.test.js.snap | 16 --- .../ControlLoop/GetLocalToscaFileForUpload.js | 150 ++++++++++++++++++++ .../ControlLoop/GetLocalToscaFileForUpload.test.js | 122 ++++++++++++++++ .../dialogs/ControlLoop/GetToscaTemplate.js | 50 +++++++ .../dialogs/ControlLoop/GetToscaTemplate.test.js | 53 +++++++ .../dialogs/ControlLoop/ReadAndConvertYaml.js | 96 +++++++++++++ .../dialogs/ControlLoop/ReadAndConvertYaml.test.js | 99 +++++++++++++ .../dialogs/ControlLoop/UploadToscaFile.js | 54 ++++++++ .../dialogs/ControlLoop/UploadToscaFile.test.js | 61 ++++++++ .../GetLocalToscaFileForUpload.test.js.snap | 103 ++++++++++++++ .../__snapshots__/GetToscaTemplate.test.js.snap | 15 ++ .../__snapshots__/ReadAndConvertYaml.test.js.snap | 46 +++++++ .../__snapshots__/UploadToscaFile.test.js.snap | 16 +++ .../dialogs/GetLocalToscaFileForUpload.js | 153 --------------------- .../dialogs/GetLocalToscaFileForUpload.test.js | 124 ----------------- .../src/components/dialogs/ReadAndConvertYaml.js | 87 ------------ .../components/dialogs/ReadAndConvertYaml.test.js | 101 -------------- .../GetLocalToscaFileForUpload.test.js.snap | 103 -------------- .../__snapshots__/ReadAndConvertYaml.test.js.snap | 39 ------ gui-clamp/ui-react/src/components/menu/MenuBar.js | 8 +- .../menu/__snapshots__/MenuBar.test.js.snap | 138 ++++++++++--------- 28 files changed, 976 insertions(+), 948 deletions(-) delete mode 100644 gui-clamp/ui-react/src/api/GetToscaTemplate.js delete mode 100644 gui-clamp/ui-react/src/api/GetToscaTemplate.test.js delete mode 100644 gui-clamp/ui-react/src/api/UploadToscaFile.js delete mode 100644 gui-clamp/ui-react/src/api/UploadToscaFile.test.js delete mode 100644 gui-clamp/ui-react/src/api/__snapshots__/GetToscaTemplate.test.js.snap delete mode 100644 gui-clamp/ui-react/src/api/__snapshots__/UploadToscaFile.test.js.snap create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetLocalToscaFileForUpload.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetLocalToscaFileForUpload.test.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetToscaTemplate.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetToscaTemplate.test.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.test.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaFile.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaFile.test.js create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/GetLocalToscaFileForUpload.test.js.snap create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/GetToscaTemplate.test.js.snap create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/ReadAndConvertYaml.test.js.snap create mode 100644 gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaFile.test.js.snap delete mode 100644 gui-clamp/ui-react/src/components/dialogs/GetLocalToscaFileForUpload.js delete mode 100644 gui-clamp/ui-react/src/components/dialogs/GetLocalToscaFileForUpload.test.js delete mode 100644 gui-clamp/ui-react/src/components/dialogs/ReadAndConvertYaml.js delete mode 100644 gui-clamp/ui-react/src/components/dialogs/ReadAndConvertYaml.test.js delete mode 100644 gui-clamp/ui-react/src/components/dialogs/__snapshots__/GetLocalToscaFileForUpload.test.js.snap delete mode 100644 gui-clamp/ui-react/src/components/dialogs/__snapshots__/ReadAndConvertYaml.test.js.snap (limited to 'gui-clamp/ui-react') diff --git a/gui-clamp/ui-react/src/LoopUI.js b/gui-clamp/ui-react/src/LoopUI.js index 4009bf1..752c89d 100644 --- a/gui-clamp/ui-react/src/LoopUI.js +++ b/gui-clamp/ui-react/src/LoopUI.js @@ -51,9 +51,9 @@ import Alert from 'react-bootstrap/Alert'; import Spinner from 'react-bootstrap/Spinner'; import { Link } from 'react-router-dom'; -import ReadAndConvertYaml from "./components/dialogs/ReadAndConvertYaml"; +import ReadAndConvertYaml from "./components/dialogs/ControlLoop/ReadAndConvertYaml"; import MonitoringControlLoopModal from "./components/dialogs/ControlLoop/MonitoringControlLoopModal"; -import GetLocalToscaFileForUpload from "./components/dialogs/GetLocalToscaFileForUpload"; +import GetLocalToscaFileForUpload from "./components/dialogs/ControlLoop/GetLocalToscaFileForUpload"; const StyledMainDiv = styled.div` background-color: ${ props => props.theme.backgroundColor }; diff --git a/gui-clamp/ui-react/src/api/ControlLoopService.js b/gui-clamp/ui-react/src/api/ControlLoopService.js index 5ef7529..1882f78 100644 --- a/gui-clamp/ui-react/src/api/ControlLoopService.js +++ b/gui-clamp/ui-react/src/api/ControlLoopService.js @@ -44,4 +44,38 @@ export default class ControlLoopService { return undefined; }); } + + static async getToscaTemplate(name, version, windowLocationPathname) { + const params = { + name: name, + version: version + } + + const response = await fetch(windowLocationPathname + + '/restservices/clds/v2/toscaControlLoop/getToscaTemplate' + '?' + (new URLSearchParams(params))); + + if (!response.ok) { + const message = `An error has occurred: ${response.status}`; + throw new Error(message); + } + + const data = await response; + + return data; + } + + static async uploadToscaFile(toscaObject, windowLocationPathName) { + const response = await fetch(windowLocationPathName + + '/restservices/clds/v2/toscaControlLoop/commissionToscaTemplate', { + method: 'POST', + headers: { + "Content-Type": "application/json" + }, + credentials: 'same-origin', + body: JSON.stringify(toscaObject), + }); + + return response + + } } diff --git a/gui-clamp/ui-react/src/api/GetToscaTemplate.js b/gui-clamp/ui-react/src/api/GetToscaTemplate.js deleted file mode 100644 index d428491..0000000 --- a/gui-clamp/ui-react/src/api/GetToscaTemplate.js +++ /dev/null @@ -1,56 +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, { useState } from "react"; -import Button from "react-bootstrap/Button"; - -const GetToscaTemplate = (props) => { - - const [windowLocationPathName, setWindowLocationPathname] = useState(''); - - const getTemplateHandler = async () => { - console.log('getTemplateHandler called') - setWindowLocationPathname(window.location.pathname); - - const params = { - name: props.templateName, - version: props.templateVersion - } - - const response = await fetch(windowLocationPathName + - '/restservices/clds/v2/toscaControlLoop/getToscaTemplate' + '?' + (new URLSearchParams(params))); - - const data = await response.json(); - - props.onGetToscaServiceTemplate(data); - - } - - return ( - - - - ); - - -} - -export default GetToscaTemplate; diff --git a/gui-clamp/ui-react/src/api/GetToscaTemplate.test.js b/gui-clamp/ui-react/src/api/GetToscaTemplate.test.js deleted file mode 100644 index 338ee83..0000000 --- a/gui-clamp/ui-react/src/api/GetToscaTemplate.test.js +++ /dev/null @@ -1,55 +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 { mount, shallow } from 'enzyme'; -import GetToscaTemplate from './GetToscaTemplate'; -import toJson from "enzyme-to-json"; - -describe('Verify GetToscaTemplate', () => { - - 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 call getTemplateHandler when clicked', async () => { - const component = mount() - const logSpy = jest.spyOn(console, 'log'); - - component.find('[variant="primary"]').simulate('click'); - expect(logSpy).toHaveBeenCalledWith('getTemplateHandler called'); - }); - - it('should have a Button element with specified text', () => { - const container = shallow() - expect(container.find('Button').text()).toBe('Get Tosca Service Template'); - }); -}); diff --git a/gui-clamp/ui-react/src/api/UploadToscaFile.js b/gui-clamp/ui-react/src/api/UploadToscaFile.js deleted file mode 100644 index 4173e0d..0000000 --- a/gui-clamp/ui-react/src/api/UploadToscaFile.js +++ /dev/null @@ -1,63 +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 Button from "react-bootstrap/Button"; -import React, { useState } from "react"; - -const UploadToscaFile = (props) => { - const [windowLocationPathName, setWindowLocationPathname] = useState(''); - - const postServiceTemplateHandler = async (event) => { - event.preventDefault(); - console.log('postServiceTemplateHandler called'); - setWindowLocationPathname(window.location.pathname); - - const response = await fetch(windowLocationPathName + - '/restservices/clds/v2/toscaControlLoop/commissionToscaTemplate', { - method: 'POST', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin', - body: JSON.stringify(props.toscaObject), - }); - - const responseObj = await response; - const responseMessage = await response.text(); - - props.onResponseReceived(responseObj, responseMessage); - - } - - return ( - - - - ); - -}; - -export default UploadToscaFile; diff --git a/gui-clamp/ui-react/src/api/UploadToscaFile.test.js b/gui-clamp/ui-react/src/api/UploadToscaFile.test.js deleted file mode 100644 index 681acc7..0000000 --- a/gui-clamp/ui-react/src/api/UploadToscaFile.test.js +++ /dev/null @@ -1,63 +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 { mount, shallow } from 'enzyme'; -import UploadToscaFile from './UploadToscaFile'; -import toJson from "enzyme-to-json"; -import { act } from "react-dom/test-utils"; - -describe('Verify UploadToscaFile', () => { - - 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 call postServiceTemplateHandler when clicked', async () => { - const component = mount() - const logSpy = jest.spyOn(console, 'log'); - const event = { - preventDefault() { - } - }; - - act(async () => { - component.find('[variant="primary"]').get(0).props.onClick(event); - expect(logSpy).toHaveBeenCalledWith('postServiceTemplateHandler called'); - }) - - }); - - it('should have a Button element with specified text', () => { - const container = shallow() - expect(container.find('Button').text()).toBe('Upload Tosca Service Template'); - }); -}); diff --git a/gui-clamp/ui-react/src/api/__snapshots__/GetToscaTemplate.test.js.snap b/gui-clamp/ui-react/src/api/__snapshots__/GetToscaTemplate.test.js.snap deleted file mode 100644 index 2c591d9..0000000 --- a/gui-clamp/ui-react/src/api/__snapshots__/GetToscaTemplate.test.js.snap +++ /dev/null @@ -1,15 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Verify GetToscaTemplate renders correctly 1`] = ` - - - -`; diff --git a/gui-clamp/ui-react/src/api/__snapshots__/UploadToscaFile.test.js.snap b/gui-clamp/ui-react/src/api/__snapshots__/UploadToscaFile.test.js.snap deleted file mode 100644 index a1ae439..0000000 --- a/gui-clamp/ui-react/src/api/__snapshots__/UploadToscaFile.test.js.snap +++ /dev/null @@ -1,16 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Verify UploadToscaFile renders correctly 1`] = ` - - - -`; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetLocalToscaFileForUpload.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetLocalToscaFileForUpload.js new file mode 100644 index 0000000..013dd89 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetLocalToscaFileForUpload.js @@ -0,0 +1,150 @@ +/* + * ============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 Button from "react-bootstrap/Button"; +import Modal from 'react-bootstrap/Modal'; +import Form from 'react-bootstrap/Form'; +import Row from 'react-bootstrap/Row'; +import styled from 'styled-components'; +import Alert from 'react-bootstrap/Alert'; +import * as yaml from "js-yaml"; +import UploadToscaFile from "./UploadToscaFile"; + +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 GetLocalToscaFileForUpload = (props) => { + const [selectedFile, setSelectedFile] = useState(); + const [fileIsSelected, setFileIsSelected] = useState(false); + const [toscaJsonObject, setToscaJsonObject] = useState({}); + const [show, setShow] = useState(true); + const [alertMessages, setAlertMessages] = useState(); + + const handleClose = () => { + console.log('handleClose called'); + setShow(false); + props.history.push('/'); + } + + const fileChangeHandler = (event) => { + event.preventDefault(); + console.log('fileChangeHandler called'); + + if (event.currentTarget.files[0] !== undefined) { + console.log('file defined'); + setSelectedFile(event.currentTarget.files[0]); + setFileIsSelected(true); + + const file = event.currentTarget.files[0]; + + setAlertMessages([]); + + const fileReader = new FileReader(); + + fileReader.onload = () => { + const jsonObj = yaml.load(fileReader.result, 'utf8'); + setToscaJsonObject(jsonObj); + } + + fileReader.readAsText(file); + + } else { + return; + } + }; + + const receiveResponseFromUpload = async (response) => { + + if (await response.ok) { + setAlertMessages( + Upload Success +

Tosca Service Template from { selectedFile.name } was Successfully Uploaded

+
+

Type: { selectedFile.type }

Size: { +selectedFile.size / 1000 }Kb

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

Tosca Service Template 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

+
); + } + }; + + return ( + + + Upload Tosca to Commissioning API + +
+
+ +
+ + + + Only .yaml, .yml and .json files are supported + + + + + + + { alertMessages } + + +
+
+
+ + + +
+ ); +} + +export default GetLocalToscaFileForUpload; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetLocalToscaFileForUpload.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetLocalToscaFileForUpload.test.js new file mode 100644 index 0000000..9b885c6 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetLocalToscaFileForUpload.test.js @@ -0,0 +1,122 @@ +/* + * ============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 { mount, shallow } from 'enzyme'; +import toJson from 'enzyme-to-json'; +import { act } from "react-dom/test-utils"; +import GetLocalToscaFileForUpload from './GetLocalToscaFileForUpload'; +import { createMemoryHistory } from 'history'; + + +describe('Verify GetLocalToscaFileForUpload', () => { + const fs = require('fs'); + let testFile = fs.readFileSync('src/components/dialogs/Policy/toscaData.test.json'); + const file = new Blob([testFile], { type: 'file' }); + + beforeEach(() => { + fetch.resetMocks(); + fetch.mockImplementation(() => { + return Promise.resolve({ + ok: true, + status: 200, + json: () => { + return Promise.resolve({ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "data_types": {}, + "policy_types": {}, + "topology_template": {}, + "name": "ToscaServiceTemplateSimple", + "version": "1.0.0", + "metadata": {}, + "id": "0.19518677404255147" + }); + } + }); + }); + }) + + it("renders without crashing", () => { + shallow(); + }); + + it("renders correctly", () => { + const tree = shallow(); + expect(toJson(tree)).toMatchSnapshot(); + }); + + it('should have a UploadToscaFile element', () => { + const container = shallow() + expect(container.find('UploadToscaFile').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('should call fileChangeHandler on change, file undefined', () => { + 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('fileChangeHandler called'); + }); + }); + + it('should call fileChangeHandler on change, file defined', async () => { + const component = mount(); + const logSpy = jest.spyOn(console, 'log'); + const event = { + preventDefault() { + }, + currentTarget: { files: [file] } + }; + + act(async () => { + component.find('[type="file"]').get(0).props.onChange(event); + expect(logSpy).toHaveBeenCalledWith('file defined'); + }); + }); +}); diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetToscaTemplate.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetToscaTemplate.js new file mode 100644 index 0000000..7da8c13 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetToscaTemplate.js @@ -0,0 +1,50 @@ +/* + * ============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 Button from "react-bootstrap/Button"; +import ControlLoopService from "../../../api/ControlLoopService"; + +const GetToscaTemplate = (props) => { + + const [windowLocationPathName, setWindowLocationPathname] = useState(''); + + const getTemplateHandler = async () => { + console.log('getTemplateHandler called') + setWindowLocationPathname(window.location.pathname); + + const response = await ControlLoopService.getToscaTemplate(props.templateName, props.templateVersion, windowLocationPathName) + .catch(error => error.message); + + props.onGetToscaServiceTemplate(response); + + } + + return ( + + + + ); + + +} + +export default GetToscaTemplate; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetToscaTemplate.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetToscaTemplate.test.js new file mode 100644 index 0000000..ce2a398 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/GetToscaTemplate.test.js @@ -0,0 +1,53 @@ +/* + * ============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 { mount, shallow } from 'enzyme'; +import GetToscaTemplate from './GetToscaTemplate'; +import toJson from "enzyme-to-json"; + +describe('Verify GetToscaTemplate', () => { + + 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 call getTemplateHandler when clicked', async () => { + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + + component.find('[variant="primary"]').simulate('click'); + expect(logSpy).toHaveBeenCalledWith('getTemplateHandler called'); + }); + + it('should have a Button element with specified text', () => { + const container = shallow() + expect(container.find('Button').text()).toBe('Get Tosca Service Template'); + }); +}); diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js new file mode 100644 index 0000000..53b541c --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js @@ -0,0 +1,96 @@ +/* + * ============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 GetToscaTemplate from "./GetToscaTemplate"; +import Modal from "react-bootstrap/Modal"; +import Button from "react-bootstrap/Button"; +import { Alert } from "react-bootstrap"; + +import styled from 'styled-components'; + +const ModalStyled = styled(Modal)` + background-color: transparent; +` + +const AlertStyled = styled(Alert)` + margin-top: 10px; +` + +const PreStyled = styled.pre` + color: #7F0055; + overflow: auto; + max-height: 70vh; + margin-top: 10px; +` + +const ReadAndConvertYaml = (props) => { + const [show, setShow] = useState(true); + const [toscaTemplateData, setToscaTemplateData] = useState(); + const [responeOk, setResponseOk] = useState(true); + const name = 'ToscaServiceTemplateSimple'; + const version = '1.0.0'; + + const handleClose = () => { + console.log('handleClose called'); + setShow(false); + props.history.push('/'); + } + + const getToscaServiceTemplateHandler = async (toscaServiceTemplateResponse) => { + // console.log('getToscaServiceTemplateHandler called: ' + toscaServiceTemplate); + + if (!toscaServiceTemplateResponse.ok) { + setResponseOk(false); + const toscaData = await toscaServiceTemplateResponse; + setToscaTemplateData(toscaData); + } else { + setResponseOk(true); + const toscaData = await toscaServiceTemplateResponse.json(); + setToscaTemplateData(toscaData); + } + } + + return ( + + + View Tosca Template + + + + { responeOk && { JSON.stringify(toscaTemplateData, null, 2) } } + { toscaTemplateData } + + + + + + ); +}; + +export default ReadAndConvertYaml; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.test.js new file mode 100644 index 0000000..90d7185 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.test.js @@ -0,0 +1,99 @@ +/* + * ============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 { mount, shallow } from 'enzyme'; +import ReadAndConvertYaml from './ReadAndConvertYaml'; +import toJson from "enzyme-to-json"; +import { act } from "react-dom/test-utils"; +import { createMemoryHistory } from "history"; + +describe('Verify ReadAndConvertYaml', () => { + + beforeEach(() => { + fetch.resetMocks(); + fetch.mockImplementation(() => { + return Promise.resolve({ + ok: true, + status: 200, + json: () => { + return Promise.resolve({ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "data_types": {}, + "policy_types": {}, + "topology_template": {}, + "name": "ToscaServiceTemplateSimple", + "version": "1.0.0", + "metadata": {}, + "id": "0.19518677404255147" + }); + } + }); + }); + }) + + it("renders without crashing", () => { + shallow(); + }); + + it("renders correctly", () => { + const tree = shallow(); + expect(toJson(tree)).toMatchSnapshot(); + }); + + it('should have a GetToscaTemplate element', () => { + const container = shallow() + expect(container.find('GetToscaTemplate').length).toEqual(1); + }); + + it('should call getToscaServiceTemplateHandler on click', async () => { + const component = mount(); + const logSpy = jest.spyOn(console, 'log'); + + act(async () => { + component.find('GetToscaTemplate').simulate('click'); + expect(logSpy).toHaveBeenCalledWith('getToscaServiceTemplateHandler called'); + }); + }); + + 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/UploadToscaFile.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaFile.js new file mode 100644 index 0000000..6ee6a43 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaFile.js @@ -0,0 +1,54 @@ +/* + * ============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 Button from "react-bootstrap/Button"; +import React, { useState } from "react"; +import ControlLoopService from "../../../api/ControlLoopService"; + +const UploadToscaFile = (props) => { + const [windowLocationPathName, setWindowLocationPathname] = useState(''); + + const postServiceTemplateHandler = async (event) => { + event.preventDefault(); + console.log('postServiceTemplateHandler called'); + setWindowLocationPathname(window.location.pathname); + + const response = await ControlLoopService.uploadToscaFile(props.toscaObject, windowLocationPathName) + .catch(error => error.message); + + // const responseMessage = await response.text(); + + props.onResponseReceived(response); + + } + + return ( + + + + ); + +}; + +export default UploadToscaFile; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaFile.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaFile.test.js new file mode 100644 index 0000000..94d9038 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/UploadToscaFile.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 React from 'react'; +import { mount, shallow } from 'enzyme'; +import UploadToscaFile from './UploadToscaFile'; +import toJson from "enzyme-to-json"; +import { act } from "react-dom/test-utils"; + +describe('Verify UploadToscaFile', () => { + + 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 call postServiceTemplateHandler when clicked', async () => { + const component = mount() + const logSpy = jest.spyOn(console, 'log'); + const event = { + preventDefault() { + } + }; + + act(async () => { + component.find('[variant="primary"]').get(0).props.onClick(event); + expect(logSpy).toHaveBeenCalledWith('postServiceTemplateHandler called'); + }) + + }); + + it('should have a Button element with specified text', () => { + const container = shallow() + expect(container.find('Button').text()).toBe('Upload Tosca Service Template'); + }); +}); diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/GetLocalToscaFileForUpload.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/GetLocalToscaFileForUpload.test.js.snap new file mode 100644 index 0000000..84168fd --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/GetLocalToscaFileForUpload.test.js.snap @@ -0,0 +1,103 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Verify GetLocalToscaFileForUpload renders correctly 1`] = ` + + + + Upload Tosca to Commissioning API + + +
+
+ +
+ + + + Only .yaml, .yml and .json files are supported + + + + + + + + +
+
+
+ + + +
+`; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/GetToscaTemplate.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/GetToscaTemplate.test.js.snap new file mode 100644 index 0000000..2c591d9 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/GetToscaTemplate.test.js.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Verify GetToscaTemplate renders correctly 1`] = ` + + + +`; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/ReadAndConvertYaml.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/ReadAndConvertYaml.test.js.snap new file mode 100644 index 0000000..fab7801 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/ReadAndConvertYaml.test.js.snap @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Verify ReadAndConvertYaml renders correctly 1`] = ` + + + + View Tosca Template + + + + + + + + + + + + + + +`; diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaFile.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaFile.test.js.snap new file mode 100644 index 0000000..a1ae439 --- /dev/null +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/__snapshots__/UploadToscaFile.test.js.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Verify UploadToscaFile renders correctly 1`] = ` + + + +`; diff --git a/gui-clamp/ui-react/src/components/dialogs/GetLocalToscaFileForUpload.js b/gui-clamp/ui-react/src/components/dialogs/GetLocalToscaFileForUpload.js deleted file mode 100644 index bac9953..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/GetLocalToscaFileForUpload.js +++ /dev/null @@ -1,153 +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, { useState } from 'react'; -import Button from "react-bootstrap/Button"; -import Modal from 'react-bootstrap/Modal'; -import Form from 'react-bootstrap/Form'; -import Row from 'react-bootstrap/Row'; -import styled from 'styled-components'; -import Alert from 'react-bootstrap/Alert'; -import * as yaml from "js-yaml"; -import UploadToscaFile from "../../api/UploadToscaFile"; - -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 GetLocalToscaFileForUpload = (props) => { - const [selectedFile, setSelectedFile] = useState(); - const [fileIsSelected, setFileIsSelected] = useState(false); - const [toscaJsonObject, setToscaJsonObject] = useState({}); - const [show, setShow] = useState(true); - const [alertMessages, setAlertMessages] = useState(); - - const handleClose = () => { - console.log('handleClose called'); - setShow(false); - props.history.push('/'); - } - - const fileChangeHandler = (event) => { - event.preventDefault(); - console.log('fileChangeHandler called'); - - if (event.currentTarget.files[0] !== undefined) { - console.log('file defined'); - setSelectedFile(event.currentTarget.files[0]); - setFileIsSelected(true); - - const file = event.currentTarget.files[0]; - - setAlertMessages([]); - - const fileReader = new FileReader(); - - fileReader.onload = () => { - const jsonObj = yaml.load(fileReader.result, 'utf8'); - setToscaJsonObject(jsonObj); - } - - fileReader.readAsText(file); - - } else { - return; - } - }; - - const receiveResponseFromUpload = (response, responseMessage) => { - - if (response.ok) { - setAlertMessages( - Upload Success -

Tosca Service Template from { selectedFile.name } was Successfully Uploaded

-
-

Type: { selectedFile.type }

Size: { +selectedFile.size / 1000 }Kb

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

Tosca Service Template from { selectedFile.name } failed to upload

-

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

-

Response from CLAMP: { responseMessage }

-
-

Type: { selectedFile.type }

Size: { +selectedFile.size / 1000 }Kb

-
); - } - }; - - return ( - - - Upload Tosca to Commissioning API - -
-
- -
- - - - Only .yaml, .yml and .json files are supported - - - - - - - { alertMessages } - - -
-
-
- - - -
- ); -} - -export default GetLocalToscaFileForUpload; diff --git a/gui-clamp/ui-react/src/components/dialogs/GetLocalToscaFileForUpload.test.js b/gui-clamp/ui-react/src/components/dialogs/GetLocalToscaFileForUpload.test.js deleted file mode 100644 index dfd3b9e..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/GetLocalToscaFileForUpload.test.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 from 'react'; -import { mount, shallow } from 'enzyme'; -import toJson from 'enzyme-to-json'; -import { act } from "react-dom/test-utils"; -import GetLocalToscaFileForUpload from './GetLocalToscaFileForUpload'; -import { createMemoryHistory } from 'history'; - - -describe('Verify GetLocalToscaFileForUpload', () => { - const fs = require('fs'); - let testFile = fs.readFileSync('src/components/dialogs/Policy/toscaData.test.json'); - const file = new Blob([testFile], { type: 'file' }); - - beforeEach(() => { - fetch.resetMocks(); - fetch.mockImplementation(() => { - return Promise.resolve({ - ok: true, - status: 200, - json: () => { - return Promise.resolve({ - "tosca_definitions_version": "tosca_simple_yaml_1_1_0", - "data_types": {}, - "policy_types": {}, - "topology_template": {}, - "name": "ToscaServiceTemplateSimple", - "version": "1.0.0", - "metadata": {}, - "id": "0.19518677404255147" - }); - } - }); - }); - }) - - it("renders without crashing", () => { - shallow(); - }); - - it("renders correctly", () => { - const tree = shallow(); - expect(toJson(tree)).toMatchSnapshot(); - }); - - it('should have a UploadToscaFile element', () => { - const container = shallow() - expect(container.find('UploadToscaFile').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('should call fileChangeHandler on change, file undefined', () => { - 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('fileChangeHandler called'); - }); - }); - - it('should call fileChangeHandler on change, file defined', async () => { - const component = mount(); - const logSpy = jest.spyOn(console, 'log'); - const event = { - preventDefault() { - }, - currentTarget: { files: [file] } - }; - - act(async () => { - component.find('[type="file"]').get(0).props.onChange(event); - expect(logSpy).toHaveBeenCalledWith('file defined'); - }); - }); -}); diff --git a/gui-clamp/ui-react/src/components/dialogs/ReadAndConvertYaml.js b/gui-clamp/ui-react/src/components/dialogs/ReadAndConvertYaml.js deleted file mode 100644 index 3a02588..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/ReadAndConvertYaml.js +++ /dev/null @@ -1,87 +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, { useState } from "react"; -import GetToscaTemplate from "../../api/GetToscaTemplate"; -import Modal from "react-bootstrap/Modal"; -import Button from "react-bootstrap/Button"; - -import styled from 'styled-components'; - -const ModalStyled = styled(Modal)` - background-color: transparent; -` - -const ErrMsgStyled = styled.div` - color: red; -` - -const PreStyled = styled.pre` - color: #7F0055; - overflow: auto; - max-height: 70vh; -` - -const ReadAndConvertYaml = (props) => { - const [show, setShow] = useState(true); - const [toscaTemplateData, setToscaTemplateData] = useState(); - const name = 'ToscaServiceTemplateSimple'; - const version = '1.0.0'; - - const handleClose = () => { - console.log('handleClose called'); - setShow(false); - props.history.push('/'); - } - - const getToscaServiceTemplateHandler = async (toscaServiceTemplate) => { - console.log('getToscaServiceTemplateHandler called'); - const toscaData = { - ...toscaServiceTemplate, - id: Math.random().toString() - }; - // console.log(toscaData); - setToscaTemplateData(toscaData); - } - - return ( - - - View Tosca Template - - - - { JSON.stringify(toscaTemplateData, null, 2) } - - - - - - ); -} - -export default ReadAndConvertYaml; diff --git a/gui-clamp/ui-react/src/components/dialogs/ReadAndConvertYaml.test.js b/gui-clamp/ui-react/src/components/dialogs/ReadAndConvertYaml.test.js deleted file mode 100644 index daec619..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/ReadAndConvertYaml.test.js +++ /dev/null @@ -1,101 +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 { mount, shallow } from 'enzyme'; -import ReadAndConvertYaml from './ReadAndConvertYaml'; -import toJson from "enzyme-to-json"; -import { act } from "react-dom/test-utils"; -import { createMemoryHistory } from "history"; - -describe('Verify ReadAndConvertYaml', () => { - - beforeEach(() => { - fetch.resetMocks(); - fetch.mockImplementation(() => { - return Promise.resolve({ - ok: true, - status: 200, - json: () => { - return Promise.resolve({ - "tosca_definitions_version": "tosca_simple_yaml_1_1_0", - "data_types": {}, - "policy_types": {}, - "topology_template": {}, - "name": "ToscaServiceTemplateSimple", - "version": "1.0.0", - "metadata": {}, - "id": "0.19518677404255147" - }); - } - }); - }); - }) - - it("renders without crashing", () => { - shallow(); - }); - - it("renders correctly", () => { - const tree = shallow(); - expect(toJson(tree)).toMatchSnapshot(); - }); - - it('should have a GetToscaTemplate element', () => { - const container = shallow() - expect(container.find('GetToscaTemplate').length).toEqual(1); - }); - - it('should call getToscaServiceTemplateHandler on click', async () => { - const component = mount(); - const logSpy = jest.spyOn(console, 'log'); - - act(async () => { - component.find('GetToscaTemplate').simulate('click'); - expect(logSpy).toHaveBeenCalledWith('getToscaServiceTemplateHandler called'); - }); - }); - - 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/__snapshots__/GetLocalToscaFileForUpload.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/__snapshots__/GetLocalToscaFileForUpload.test.js.snap deleted file mode 100644 index 84168fd..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/__snapshots__/GetLocalToscaFileForUpload.test.js.snap +++ /dev/null @@ -1,103 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Verify GetLocalToscaFileForUpload renders correctly 1`] = ` - - - - Upload Tosca to Commissioning API - - -
-
- -
- - - - Only .yaml, .yml and .json files are supported - - - - - - - - -
-
-
- - - -
-`; diff --git a/gui-clamp/ui-react/src/components/dialogs/__snapshots__/ReadAndConvertYaml.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/__snapshots__/ReadAndConvertYaml.test.js.snap deleted file mode 100644 index cbead03..0000000 --- a/gui-clamp/ui-react/src/components/dialogs/__snapshots__/ReadAndConvertYaml.test.js.snap +++ /dev/null @@ -1,39 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Verify ReadAndConvertYaml renders correctly 1`] = ` - - - - View Tosca Template - - - - - - - - - - -`; diff --git a/gui-clamp/ui-react/src/components/menu/MenuBar.js b/gui-clamp/ui-react/src/components/menu/MenuBar.js index d7784ef..4574a2a 100644 --- a/gui-clamp/ui-react/src/components/menu/MenuBar.js +++ b/gui-clamp/ui-react/src/components/menu/MenuBar.js @@ -87,10 +87,6 @@ export default class MenuBar extends React.Component { render() { return ( - - View Tosca Template - Upload Tosca to Commissioning - View All Policies @@ -119,6 +115,10 @@ export default class MenuBar extends React.Component { Monitoring Control Loop + + Commissioning + View Tosca Template + Upload Tosca to Commissioning Wiki diff --git a/gui-clamp/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap b/gui-clamp/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap index 416d62e..8bdfb09 100644 --- a/gui-clamp/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap +++ b/gui-clamp/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap @@ -3,7 +3,7 @@ exports[`Verify MenuBar Test the render method 1`] = ` - View Tosca Template + View All Policies + + - Upload Tosca to Commissioning + Tosca Metadata Dictionaries - - + - View All Policies + View All Loop Templates - Tosca Metadata Dictionaries + Create - - View All Loop Templates + Open - - - Create + Close - Open + Modify + - Close + Properties - Modify + Refresh Status - + + - Properties + Create and deploy to Policy Framework (SUBMIT) - Refresh Status + Undeploy from Policy Framework (STOP) - - - Create and deploy to Policy Framework (SUBMIT) + ReDeploy to Policy Framework (RESTART) - Undeploy from Policy Framework (STOP) + Delete loop instance (DELETE) + - ReDeploy to Policy Framework (RESTART) + Deploy to DCAE (DEPLOY) - Delete loop instance (DELETE) + UnDeploy to DCAE (UNDEPLOY) - + + - Deploy to DCAE (DEPLOY) + Monitoring Control Loop + + + Commissioning + - UnDeploy to DCAE (UNDEPLOY) + View Tosca Template - - - Monitoring Control Loop + Upload Tosca to Commissioning