346f6394056f5d15c0068e79fcc012de866d6720
[sdc.git] /
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 static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.is;
24
25 import lombok.AllArgsConstructor;
26 import lombok.Getter;
27 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.Dimension;
30 import org.openqa.selenium.WebDriver;
31 import org.openqa.selenium.WebElement;
32
33 public class CompositionDetailSideBarComponent extends AbstractPageObject {
34
35     private WebElement wrappingElement;
36
37     public CompositionDetailSideBarComponent(final WebDriver webDriver) {
38         super(webDriver);
39     }
40
41     @Override
42     public void isLoaded() {
43         wrappingElement = waitForElementVisibility(By.xpath(XpathSelector.MAIN_ELEMENT_DIV.getXpath()));
44     }
45
46     public String getSelectedComponentName() {
47         return wrappingElement.findElement(By.xpath(XpathSelector.DETAIL_COMPONENT_NAME_DIV.getXpath())).getText();
48     }
49
50     public void checkComponentIsSelected(final String componentName) {
51         assertThat("The selected component should be as expected", getSelectedComponentName(), is(componentName));
52     }
53
54     public Dimension getSize() {
55         final WebElement sideBarToggle = waitForElementVisibility(XpathSelector.DETAIL_SIDE_BAR_TOGGLE_DIV.getXpath());
56         if (!sideBarToggle.getAttribute("class").contains("active")) {
57             return new Dimension(0, 0);
58         }
59
60         return wrappingElement.getSize();
61     }
62
63     public AbstractPageObject selectTab(final CompositionDetailTabName tabName) {
64         final WebElement tabElement = wrappingElement.findElement(By.xpath(tabName.getXpathSelector().getXpath()));
65         tabElement.click();
66         switch (tabName) {
67             case INFORMATION:
68                 return new CompositionInformationTab(webDriver);
69             case INPUTS:
70                 return new CompositionInputsTab(webDriver);
71             case DEPLOYMENT_ARTIFACTS:
72                 return new CompositionDeploymentArtifactsTab(webDriver);
73             case INFORMATIONAL_ARTIFACTS:
74                 return new CompositionInformationalArtifactsTab(webDriver);
75             case API_ARTIFACTS:
76                 return new CompositionApiArtifactsTab(webDriver);
77             case SUBSTITUTION_FILTER:
78                 return new CompositionSubstitutionFilterTab(webDriver);
79             case REQUIREMENTS_CAPABILITIES:
80                 return new CompositionRequirementsCapabilitiesTab(webDriver);
81             case INTERFACE_OPERATIONS:
82                 return new CompositionInterfaceOperationsTab(webDriver);
83             default:
84                 throw new IllegalStateException("Not yet implemented: " + tabName);
85         }
86     }
87
88     /**
89      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
90      */
91     @AllArgsConstructor
92     private enum XpathSelector {
93         MAIN_ELEMENT_DIV("w-sdc-designer-sidebar", "//div[@class='%s']"),
94         DETAIL_SIDE_BAR_TOGGLE_DIV("w-sdc-designer-sidebar-toggle", "//div[contains(concat(' ',normalize-space(@class),' '),' %s ')]"),
95         DETAIL_HEADER("w-sdc-designer-sidebar-head", "//div[@data-tests-id='%s']"),
96         DETAIL_COMPONENT_NAME_DIV("selectedCompTitle", "//div[@data-tests-id='%s']"),
97         TAB_LIST("sdc-tabs-list", "//ul[@class='%s']/li"),
98         INFORMATION_TAB("detail-tab-information", "//li[@data-tests-id='%s']"),
99         INPUTS_TAB("detail-tab-inputs", "//li[@data-tests-id='%s']"),
100         DEPLOYMENT_ARTIFACTS_TAB("detail-tab-deployment-artifacts", "//li[@data-tests-id='%s']"),
101         INFORMATION_ARTIFACTS_TAB("detail-tab-information-artifacts", "//li[@data-tests-id='%s']"),
102         REQUIREMENTS_CAPABILITIES_TAB("detail-tab-requirements-capabilities", "//li[@data-tests-id='%s']"),
103         API_ARTIFACTS_TAB("detail-tab-api-artifacts", "//li[@data-tests-id='%s']"),
104         INTERFACE_OPERATIONS_TAB("detail-tab-interface-operations", "//li[@data-tests-id='%s']"),
105         SUBSTITUTION_FILTER_TAB("detail-tab-substitution-filter", "//li[@data-tests-id='%s']");
106
107         @Getter
108         private final String id;
109         private final String xpathFormat;
110
111         public String getXpath() {
112             return String.format(xpathFormat, id);
113         }
114     }
115
116     @Getter
117     @AllArgsConstructor
118     public enum CompositionDetailTabName {
119         INFORMATION(XpathSelector.INFORMATION_TAB),
120         INPUTS(XpathSelector.INPUTS_TAB),
121         DEPLOYMENT_ARTIFACTS(XpathSelector.DEPLOYMENT_ARTIFACTS_TAB),
122         INFORMATIONAL_ARTIFACTS(XpathSelector.INFORMATION_ARTIFACTS_TAB),
123         API_ARTIFACTS(XpathSelector.API_ARTIFACTS_TAB),
124         SUBSTITUTION_FILTER(XpathSelector.SUBSTITUTION_FILTER_TAB),
125         INTERFACE_OPERATIONS(XpathSelector.INTERFACE_OPERATIONS_TAB),
126         REQUIREMENTS_CAPABILITIES(XpathSelector.REQUIREMENTS_CAPABILITIES_TAB);
127
128         private final XpathSelector xpathSelector;
129
130     }
131 }
132