fc968fcc4fe3a091b2fd52650678f18181e91d50
[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             case DIRECTIVE_NODE_FILTER:
84                 return new CompositionDirectiveNodeFilterTab(webDriver);
85             default:
86                 throw new IllegalStateException("Not yet implemented: " + tabName);
87         }
88     }
89
90     /**
91      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
92      */
93     @AllArgsConstructor
94     private enum XpathSelector {
95         MAIN_ELEMENT_DIV("w-sdc-designer-sidebar", "//div[@class='%s']"),
96         DETAIL_SIDE_BAR_TOGGLE_DIV("w-sdc-designer-sidebar-toggle", "//div[contains(concat(' ',normalize-space(@class),' '),' %s ')]"),
97         DETAIL_HEADER("w-sdc-designer-sidebar-head", "//div[@data-tests-id='%s']"),
98         DETAIL_COMPONENT_NAME_DIV("selectedCompTitle", "//div[@data-tests-id='%s']"),
99         TAB_LIST("sdc-tabs-list", "//ul[@class='%s']/li"),
100         INFORMATION_TAB("detail-tab-information", "//li[@data-tests-id='%s']"),
101         INPUTS_TAB("detail-tab-inputs", "//li[@data-tests-id='%s']"),
102         DEPLOYMENT_ARTIFACTS_TAB("detail-tab-deployment-artifacts", "//li[@data-tests-id='%s']"),
103         INFORMATION_ARTIFACTS_TAB("detail-tab-information-artifacts", "//li[@data-tests-id='%s']"),
104         REQUIREMENTS_CAPABILITIES_TAB("detail-tab-requirements-capabilities", "//li[@data-tests-id='%s']"),
105         API_ARTIFACTS_TAB("detail-tab-api-artifacts", "//li[@data-tests-id='%s']"),
106         INTERFACE_OPERATIONS_TAB("detail-tab-interface-operations", "//li[@data-tests-id='%s']"),
107         SUBSTITUTION_FILTER_TAB("detail-tab-substitution-filter", "//li[@data-tests-id='%s']"),
108         DIRECTIVE_NODE_FILTER_TAB("detail-tab-directives-node-filter", "//li[@data-tests-id='%s']");
109
110         @Getter
111         private final String id;
112         private final String xpathFormat;
113
114         public String getXpath() {
115             return String.format(xpathFormat, id);
116         }
117     }
118
119     @Getter
120     @AllArgsConstructor
121     public enum CompositionDetailTabName {
122         INFORMATION(XpathSelector.INFORMATION_TAB),
123         INPUTS(XpathSelector.INPUTS_TAB),
124         DEPLOYMENT_ARTIFACTS(XpathSelector.DEPLOYMENT_ARTIFACTS_TAB),
125         INFORMATIONAL_ARTIFACTS(XpathSelector.INFORMATION_ARTIFACTS_TAB),
126         API_ARTIFACTS(XpathSelector.API_ARTIFACTS_TAB),
127         SUBSTITUTION_FILTER(XpathSelector.SUBSTITUTION_FILTER_TAB),
128         INTERFACE_OPERATIONS(XpathSelector.INTERFACE_OPERATIONS_TAB),
129         REQUIREMENTS_CAPABILITIES(XpathSelector.REQUIREMENTS_CAPABILITIES_TAB),
130         DIRECTIVE_NODE_FILTER(XpathSelector.DIRECTIVE_NODE_FILTER_TAB);
131
132         private final XpathSelector xpathSelector;
133
134     }
135 }
136