summaryrefslogtreecommitdiffstats
path: root/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/component/workspace/InterfaceOperationAddInputComponent.java
blob: f28d98d3c707040c95c21e7f0c33a28166e9edd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * -
 *  ============LICENSE_START=======================================================
 *  Copyright (C) 2022 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=========================================================
 */

package org.onap.sdc.frontend.ci.tests.pages.component.workspace;

import lombok.AllArgsConstructor;
import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
import org.onap.sdc.frontend.ci.tests.pages.component.workspace.InterfaceDefinitionOperationsModal.InterfaceOperationsData.InputData;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

/**
 * Handles the add input inside the interface operation modal.
 *
 * @see "catalog-ui app-add-input component"
 */
public class InterfaceOperationAddInputComponent extends AbstractPageObject {

    public InterfaceOperationAddInputComponent(final WebDriver webDriver) {
        super(webDriver);
    }

    @Override
    public void isLoaded() {
        waitForElementVisibility(XpathSelector.ADD_INPUT_LINK.getXPath());
    }

    /**
     * Clicks on the add input link, that opens the add input form.
     */
    public void clickOnAddInputLink() {
        waitToBeClickable(By.xpath(XpathSelector.ADD_INPUT_LINK.getXPath())).click();
        waitForElementVisibility(XpathSelector.NAME_INPUT.getXPath());
        waitForElementVisibility(XpathSelector.TYPE_INPUT.getXPath());
        waitForElementVisibility(XpathSelector.ADD_BTN.getXPath());
        waitForElementVisibility(XpathSelector.CANCEL_BTN.getXPath());
    }

    /**
     * Clicks on the add button that submits the input form.
     */
    public void clickOnAddButton() {
        waitToBeClickable(By.xpath(XpathSelector.ADD_BTN.getXPath())).click();
    }

    /**
     * Fills the input form fields with the given data.
     *
     * @param inputData the input information
     */
    public void fillInput(final InputData inputData) {
        fillName(inputData.getName());
        fillType(inputData.getType());
    }

    /**
     * Fills an input value, in the input list, based on the given input data.
     *
     * @param inputData the input information
     */
    public void fillValue(final InputData inputData) {
        var interfaceOperationInputListComponent = new InterfaceOperationInputListComponent(webDriver);
        interfaceOperationInputListComponent.isLoaded();
        interfaceOperationInputListComponent.fillInputValue(inputData.getName(), inputData.getValue());
    }

    /**
     * Fills the input name field.
     *
     * @param name the name to fill
     */
    public void fillName(final String name) {
        setInputValue(By.xpath(XpathSelector.NAME_INPUT.getXPath()), name);
    }

    /**
     * Fills the input type field.
     *
     * @param type the type to fill
     */
    public void fillType(final String type) {
        final WebElement inputElement = findElement(By.xpath(XpathSelector.TYPE_INPUT.getXPath()));
        inputElement.click();
        waitForElementVisibility(By.xpath(XpathSelector.DROPDOWN_RESULTS.getXPath()));
        inputElement.sendKeys(type);
        waitForElementVisibility(By.xpath(XpathSelector.DROPDOWN_OPTION.getXPath(type))).click();
    }

    private void setInputValue(final By locator, final String value) {
        if (value == null) {
            return;
        }

        final WebElement webElement = findElement(locator);
        webElement.clear();
        webElement.sendKeys(value);
    }

    @AllArgsConstructor
    private enum XpathSelector {
        ADD_INPUT_LINK("//a[@data-tests-id='add-input.add-input-link']"),
        NAME_INPUT("//input[@data-tests-id='add-input.input-name']"),
        TYPE_INPUT("//input[starts-with(@data-tests-id, 'add-input.input-type')]"),
        ADD_BTN("//button[@data-tests-id='add-input.add-input-btn']"),
        CANCEL_BTN("//button[@data-tests-id='add-input.cancel-btn']"),
        DROPDOWN_RESULTS("//dropdown-results"),
        DROPDOWN_OPTION("//li[@data-tests-id='%s']");

        private final String xPath;

        public String getXPath(final String... xpathParams) {
            return String.format(xPath, xpathParams);
        }
    }
}