Support complex types in interface operation inputs
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / component / workspace / InterfaceOperationAddInputComponent.java
1 /*
2  * -
3  *  ============LICENSE_START=======================================================
4  *  Copyright (C) 2022 Nordix Foundation.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.sdc.frontend.ci.tests.pages.component.workspace;
23
24 import lombok.AllArgsConstructor;
25 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
26 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.InterfaceDefinitionOperationsModal.InterfaceOperationsData.InputData;
27 import org.openqa.selenium.By;
28 import org.openqa.selenium.WebDriver;
29 import org.openqa.selenium.WebElement;
30
31 /**
32  * Handles the add input inside the interface operation modal.
33  *
34  * @see "catalog-ui app-add-input component"
35  */
36 public class InterfaceOperationAddInputComponent extends AbstractPageObject {
37
38     public InterfaceOperationAddInputComponent(final WebDriver webDriver) {
39         super(webDriver);
40     }
41
42     @Override
43     public void isLoaded() {
44         waitForElementVisibility(XpathSelector.ADD_INPUT_LINK.getXPath());
45     }
46
47     /**
48      * Clicks on the add input link, that opens the add input form.
49      */
50     public void clickOnAddInputLink() {
51         waitToBeClickable(By.xpath(XpathSelector.ADD_INPUT_LINK.getXPath())).click();
52         waitForElementVisibility(XpathSelector.NAME_INPUT.getXPath());
53         waitForElementVisibility(XpathSelector.TYPE_INPUT.getXPath());
54         waitForElementVisibility(XpathSelector.ADD_BTN.getXPath());
55         waitForElementVisibility(XpathSelector.CANCEL_BTN.getXPath());
56     }
57
58     /**
59      * Clicks on the add button that submits the input form.
60      */
61     public void clickOnAddButton() {
62         waitToBeClickable(By.xpath(XpathSelector.ADD_BTN.getXPath())).click();
63     }
64
65     /**
66      * Fills the input form fields with the given data.
67      *
68      * @param inputData the input information
69      */
70     public void fillInput(final InputData inputData) {
71         fillName(inputData.getName());
72         fillType(inputData.getType());
73     }
74
75     /**
76      * Fills an input value, in the input list, based on the given input data.
77      *
78      * @param inputData the input information
79      */
80     public void fillValue(final InputData inputData) {
81         var interfaceOperationInputListComponent = new InterfaceOperationInputListComponent(webDriver);
82         interfaceOperationInputListComponent.isLoaded();
83         interfaceOperationInputListComponent.fillInputValue(inputData.getName(), inputData.getValue());
84     }
85
86     /**
87      * Fills the input name field.
88      *
89      * @param name the name to fill
90      */
91     public void fillName(final String name) {
92         setInputValue(By.xpath(XpathSelector.NAME_INPUT.getXPath()), name);
93     }
94
95     /**
96      * Fills the input type field.
97      *
98      * @param type the type to fill
99      */
100     public void fillType(final String type) {
101         final WebElement inputElement = findElement(By.xpath(XpathSelector.TYPE_INPUT.getXPath()));
102         inputElement.click();
103         waitForElementVisibility(By.xpath(XpathSelector.DROPDOWN_RESULTS.getXPath()));
104         inputElement.sendKeys(type);
105         waitForElementVisibility(By.xpath(XpathSelector.DROPDOWN_OPTION.getXPath(type))).click();
106     }
107
108     private void setInputValue(final By locator, final String value) {
109         if (value == null) {
110             return;
111         }
112
113         final WebElement webElement = findElement(locator);
114         webElement.clear();
115         webElement.sendKeys(value);
116     }
117
118     @AllArgsConstructor
119     private enum XpathSelector {
120         ADD_INPUT_LINK("//a[@data-tests-id='add-input.add-input-link']"),
121         NAME_INPUT("//input[@data-tests-id='add-input.input-name']"),
122         TYPE_INPUT("//input[starts-with(@data-tests-id, 'add-input.input-type')]"),
123         ADD_BTN("//button[@data-tests-id='add-input.add-input-btn']"),
124         CANCEL_BTN("//button[@data-tests-id='add-input.cancel-btn']"),
125         DROPDOWN_RESULTS("//dropdown-results"),
126         DROPDOWN_OPTION("//li[@data-tests-id='%s']");
127
128         private final String xPath;
129
130         public String getXPath(final String... xpathParams) {
131             return String.format(xPath, xpathParams);
132         }
133     }
134 }