Add UI feedback when saving a interface operation
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / component / workspace / InterfaceDefinitionOperationsModal.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.sdc.frontend.ci.tests.pages.component.workspace;
21
22 import com.aventstack.extentreports.Status;
23 import java.time.Duration;
24 import java.util.List;
25 import lombok.AllArgsConstructor;
26 import lombok.Getter;
27 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
28 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
29 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.InterfaceDefinitionOperationsModal.InterfaceOperationsData.InputData;
30 import org.openqa.selenium.By;
31 import org.openqa.selenium.WebDriver;
32 import org.openqa.selenium.WebElement;
33 import org.openqa.selenium.interactions.Actions;
34
35 import static org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils.waitForLoader;
36
37 /**
38  * Represents the Composition Interface Operations Modal.
39  */
40 public class InterfaceDefinitionOperationsModal extends AbstractPageObject {
41
42     private InterfaceOperationInputListComponent inputListComponent;
43     private InterfaceOperationAddInputComponent addInputComponent;
44
45     public InterfaceDefinitionOperationsModal(final WebDriver webDriver) {
46         super(webDriver);
47     }
48
49     @Override
50     public void isLoaded() {
51         isLoaded(false);
52     }
53
54     public void isLoaded(boolean isInViewMode) {
55         waitForElementVisibility(By.xpath(XpathSelector.TITLE_SPAN.getXPath()));
56         waitForElementVisibility(By.xpath(XpathSelector.INTERFACE_NAME_LABEL.getXPath()));
57         waitForElementVisibility(By.xpath(XpathSelector.OPERATION_NAME_LABEL.getXPath()));
58         waitForElementVisibility(By.xpath(XpathSelector.SAVE_BTN.getXPath()));
59         waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath()));
60         this.inputListComponent = new InterfaceOperationInputListComponent(webDriver);
61         this.inputListComponent.isLoaded();
62         if (!isInViewMode) {
63             this.addInputComponent = new InterfaceOperationAddInputComponent(webDriver);
64             this.addInputComponent.isLoaded();
65         }
66     }
67
68     public void isUnloaded() {
69         waitForElementInvisibility(By.xpath(XpathSelector.TITLE_SPAN.getXPath()));
70         waitForElementInvisibility(By.xpath(XpathSelector.INTERFACE_NAME_LABEL.getXPath()));
71         waitForElementInvisibility(By.xpath(XpathSelector.OPERATION_NAME_LABEL.getXPath()));
72         waitForElementInvisibility(By.xpath(XpathSelector.SAVE_BTN.getXPath()));
73         waitForElementInvisibility(By.xpath(XpathSelector.CANCEL_BTN.getXPath()));
74     }
75
76     private void clickOnSave() {
77         waitToBeClickable(By.xpath(XpathSelector.SAVE_BTN.getXPath())).click();
78     }
79
80     public void clickOnCancel() {
81         waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath())).click();
82     }
83
84     public void clickOnDelete() {
85         waitToBeClickable(By.xpath(XpathSelector.DELETE_BTN.getXPath())).click();
86     }
87
88     public void deleteInput(String inputName) {
89         inputListComponent.loadInputList();
90         inputListComponent.deleteInput(inputName);
91     }
92
93     public void updateInterfaceOperation(final InterfaceOperationsData interfaceOperationsData) {
94         fillDescription(interfaceOperationsData.getDescription());
95         fillImplementationName(interfaceOperationsData.getImplementationName());
96         interfaceOperationsData.getInputList().forEach(inputData -> {
97             final InterfaceOperationAddInputComponent addInputComponent = new InterfaceOperationAddInputComponent(webDriver);
98             addInputComponent.isLoaded();
99             addInputComponent.clickOnAddInputLink();
100             addInputComponent.fillInput(inputData);
101             addInputComponent.clickOnAddButton();
102             ExtentTestActions.takeScreenshot(Status.INFO,
103                 "compositionInterfaceOperationsModal.addInput." + inputData.getName(),
104                 String.format("Input '%s' added", inputData.getName())
105             );
106             addInputComponent.fillValue(inputData);
107         });
108         clickOnSave();
109         waitForLoader();
110     }
111
112     private void fillDescription(final String description) {
113         setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath()), description);
114     }
115
116     private void fillImplementationName(final String implementationName) {
117         setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath()), implementationName);
118     }
119
120     private void setInputField(final By locator, final String value) {
121         if (value == null) {
122             return;
123         }
124         final WebElement webElement = findElement(locator);
125         webElement.clear();
126         webElement.sendKeys(value);
127
128         ExtentTestActions.takeScreenshot(Status.INFO, value, value);
129     }
130
131     public void clickOnAddInput() {
132         addInputComponent.clickOnAddInputLink();
133     }
134
135     public String getDescription() {
136         return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath())).getAttribute("value");
137     }
138
139     public String getImplementationName() {
140         return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath())).getAttribute("value");
141     }
142
143     public List<InputData> getInputs() {
144         inputListComponent.loadInputList();
145         return inputListComponent.getInputList();
146     }
147
148     @AllArgsConstructor
149     private enum XpathSelector {
150         TITLE_SPAN("//span[@class='title' and contains(text(), 'Edit Operation')]"),
151         DELETE_BTN("//svg-icon[@name='trash-o']"),
152         SAVE_BTN("//button[@data-tests-id='Save']"),
153         CANCEL_BTN("//button[@data-tests-id='Cancel']"),
154         INTERFACE_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Interface Name')]"),
155         OPERATION_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Operation Name')]"),
156         INTERFACE_OPERATION_DESCRIPTION_INPUT("//input[@data-tests-id='interface-operation-description']"),
157         INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT("//input[@data-tests-id='interface-operation-implementation-name']");
158
159         private final String xPath;
160
161         public String getXPath(final String... xpathParams) {
162             return String.format(xPath, xpathParams);
163         }
164     }
165
166     @Getter
167     @AllArgsConstructor
168     public static class InterfaceOperationsData {
169
170         private final String description;
171         private final String implementationName;
172         private final List<InputData> inputList;
173
174         @Getter
175         @AllArgsConstructor
176         public static class InputData {
177
178             private final String name;
179             private final String type;
180             private final Object value;
181         }
182     }
183 }