aboutsummaryrefslogtreecommitdiffstats
path: root/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/component/workspace/InterfaceDefinitionOperationsModal.java
blob: 5a2cb2f5d533b5063ca11c91639deb14483eb0e4 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * ============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=========================================================
 */

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

import com.aventstack.extentreports.Status;
import java.time.Duration;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
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;
import org.openqa.selenium.interactions.Actions;

/**
 * Represents the Composition Interface Operations Modal.
 */
public class InterfaceDefinitionOperationsModal extends AbstractPageObject {

    private InterfaceOperationInputListComponent inputListComponent;
    private InterfaceOperationAddInputComponent addInputComponent;

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

    @Override
    public void isLoaded() {
        isLoaded(false);
    }

    public void isLoaded(boolean isInViewMode) {
        waitForElementVisibility(By.xpath(XpathSelector.TITLE_SPAN.getXPath()));
        waitForElementVisibility(By.xpath(XpathSelector.INTERFACE_NAME_LABEL.getXPath()));
        waitForElementVisibility(By.xpath(XpathSelector.OPERATION_NAME_LABEL.getXPath()));
        waitForElementVisibility(By.xpath(XpathSelector.SAVE_BTN.getXPath()));
        waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath()));
        this.inputListComponent = new InterfaceOperationInputListComponent(webDriver);
        this.inputListComponent.isLoaded();
        if (!isInViewMode) {
            this.addInputComponent = new InterfaceOperationAddInputComponent(webDriver);
            this.addInputComponent.isLoaded();
        }
    }

    private void clickOnSave() {
        waitToBeClickable(By.xpath(XpathSelector.SAVE_BTN.getXPath())).click();
    }

    public void clickOnCancel() {
        waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath())).click();
    }

    public void clickOnDelete() {
        waitToBeClickable(By.xpath(XpathSelector.DELETE_BTN.getXPath())).click();
    }

    public void deleteInput(String inputName) {
        inputListComponent.loadInputList();
        inputListComponent.deleteInput(inputName);
    }

    public void updateInterfaceOperation(final InterfaceOperationsData interfaceOperationsData) {
        fillDescription(interfaceOperationsData.getDescription());
        fillImplementationName(interfaceOperationsData.getImplementationName());
        interfaceOperationsData.getInputList().forEach(inputData -> {
            final InterfaceOperationAddInputComponent addInputComponent = new InterfaceOperationAddInputComponent(webDriver);
            addInputComponent.isLoaded();
            addInputComponent.clickOnAddInputLink();
            addInputComponent.fillInput(inputData);
            addInputComponent.clickOnAddButton();
            ExtentTestActions.takeScreenshot(Status.INFO,
                "compositionInterfaceOperationsModal.addInput." + inputData.getName(),
                String.format("Input '%s' added", inputData.getName())
            );
            addInputComponent.fillValue(inputData);
        });
        clickOnSave();
        //there is no feedback from the UI to check if the update was successful. Forcing a wait time trying to guarantee that,
        // although time is never a guarantee in this case.
        new Actions(webDriver).pause(Duration.ofSeconds(5)).perform();
    }

    private void fillDescription(final String description) {
        setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath()), description);
    }

    private void fillImplementationName(final String implementationName) {
        setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath()), implementationName);
    }

    private void setInputField(final By locator, final String value) {
        if (value == null) {
            return;
        }
        final WebElement webElement = findElement(locator);
        webElement.clear();
        webElement.sendKeys(value);

        ExtentTestActions.takeScreenshot(Status.INFO, value, value);
    }

    public void clickOnAddInput() {
        addInputComponent.clickOnAddInputLink();
    }

    public String getDescription() {
        return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath())).getAttribute("value");
    }

    public String getImplementationName() {
        return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath())).getAttribute("value");
    }

    public List<InputData> getInputs() {
        inputListComponent.loadInputList();
        return inputListComponent.getInputList();
    }

    @AllArgsConstructor
    private enum XpathSelector {
        TITLE_SPAN("//span[@class='title' and contains(text(), 'Edit Operation')]"),
        DELETE_BTN("//svg-icon[@name='trash-o']"),
        SAVE_BTN("//button[@data-tests-id='Save']"),
        CANCEL_BTN("//button[@data-tests-id='Cancel']"),
        INTERFACE_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Interface Name')]"),
        OPERATION_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Operation Name')]"),
        INTERFACE_OPERATION_DESCRIPTION_INPUT("//input[@data-tests-id='interface-operation-description']"),
        INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT("//input[@data-tests-id='interface-operation-implementation-name']");

        private final String xPath;

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

    @Getter
    @AllArgsConstructor
    public static class InterfaceOperationsData {

        private final String description;
        private final String implementationName;
        private final List<InputData> inputList;

        @Getter
        @AllArgsConstructor
        public static class InputData {

            private final String name;
            private final String type;
            private final Object value;
        }
    }
}