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