diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java index a030f3a8c9..d7e5c807d5 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java @@ -29,13 +29,21 @@ import io.restassured.specification.RequestSpecification; import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.DeviceProfile; +import org.thingsboard.server.common.data.EntityView; +import org.thingsboard.server.common.data.User; +import org.thingsboard.server.common.data.alarm.Alarm; +import org.thingsboard.server.common.data.asset.Asset; import org.thingsboard.server.common.data.asset.AssetProfile; +import org.thingsboard.server.common.data.id.AlarmId; +import org.thingsboard.server.common.data.id.AssetId; import org.thingsboard.server.common.data.id.AssetProfileId; import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.DeviceProfileId; import org.thingsboard.server.common.data.id.EntityId; +import org.thingsboard.server.common.data.id.EntityViewId; import org.thingsboard.server.common.data.id.RuleChainId; +import org.thingsboard.server.common.data.id.UserId; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.relation.EntityRelation; @@ -178,7 +186,7 @@ public class TestRestClient { } public JsonPath postProvisionRequest(String provisionRequest) { - return given().spec(requestSpec) + return given().spec(requestSpec) .body(provisionRequest) .post("/api/v1/provision") .getBody() @@ -293,7 +301,7 @@ public class TestRestClient { } public DeviceProfile getDeviceProfileById(DeviceProfileId deviceProfileId) { - return given().spec(requestSpec).get("/api/deviceProfile/{deviceProfileId}", deviceProfileId.getId()) + return given().spec(requestSpec).get("/api/deviceProfile/{deviceProfileId}", deviceProfileId.getId()) .then() .assertThat() .statusCode(HTTP_OK) @@ -388,6 +396,40 @@ public class TestRestClient { }); } + public Alarm postAlarm(Alarm alarm) { + return given().spec(requestSpec) + .body(alarm) + .post("/api/alarm") + .then() + .statusCode(HTTP_OK) + .extract() + .as(Alarm.class); + } + + public void deleteAlarm(AlarmId alarmId) { + given().spec(requestSpec) + .delete("/api/alarm/{alarmId}", alarmId.getId()) + .then() + .statusCode(HTTP_OK); + } + + public User postUser(User user) { + return given().spec(requestSpec) + .body(user) + .post("/api/user?sendActivationMail=false") + .then() + .statusCode(HTTP_OK) + .extract() + .as(User.class); + } + + public void deleteUser(UserId userId) { + given().spec(requestSpec) + .delete("/api/user/{userId}", userId.getId()) + .then() + .statusCode(HTTP_OK); + } + public String getToken() { return token; } @@ -395,4 +437,56 @@ public class TestRestClient { public String getRefreshToken() { return refreshToken; } + + public Asset postAsset(Asset asset) { + return given().spec(requestSpec) + .body(asset) + .post("/api/asset") + .then() + .statusCode(HTTP_OK) + .extract() + .as(Asset.class); + } + + public Asset getAssetById(AssetId assetId) { + return given().spec(requestSpec) + .get("/api/asset/{assetId}", assetId.getId()) + .then() + .statusCode(HTTP_OK) + .extract() + .as(Asset.class); + } + + public void deleteAsset(AssetId assetId) { + given().spec(requestSpec) + .delete("/api/asset/{assetId}", assetId.getId()) + .then() + .statusCode(HTTP_OK); + } + + public EntityView postEntityView(EntityView entityView) { + return given().spec(requestSpec) + .body(entityView) + .post("/api/entityView") + .then() + .statusCode(HTTP_OK) + .extract() + .as(EntityView.class); + } + + public EntityView getEntityViewById(EntityViewId entityViewId) { + return given().spec(requestSpec) + .get("/api/entityView/{entityViewId}", entityViewId.getId()) + .then() + .statusCode(HTTP_OK) + .extract() + .as(EntityView.class); + } + + public void deleteEntityView(EntityViewId entityViewId) { + given().spec(requestSpec) + .delete("/api/entityView/{entityViewId}", entityViewId.getId()) + .then() + .statusCode(HTTP_OK); + } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java index 85493f39a3..27e5e6b978 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java @@ -27,6 +27,7 @@ import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.html5.WebStorage; import org.openqa.selenium.remote.LocalFileDetector; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -38,6 +39,11 @@ import org.testng.annotations.BeforeMethod; import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.asset.AssetProfile; +import org.thingsboard.server.common.data.id.AlarmId; +import org.thingsboard.server.common.data.id.AssetId; +import org.thingsboard.server.common.data.id.CustomerId; +import org.thingsboard.server.common.data.id.DeviceId; +import org.thingsboard.server.common.data.id.EntityViewId; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.rule.RuleChain; import org.thingsboard.server.msa.AbstractContainerTest; @@ -70,6 +76,7 @@ abstract public class AbstractDriverBaseTest extends AbstractContainerTest { private JavascriptExecutor js; public static final long WAIT_TIMEOUT = TimeUnit.SECONDS.toMillis(10); private final Duration duration = Duration.ofMillis(WAIT_TIMEOUT); + private WebStorage webStorage; @BeforeClass public void startUp() throws MalformedURLException { @@ -210,4 +217,49 @@ abstract public class AbstractDriverBaseTest extends AbstractContainerTest { testRestClient.setRootRuleChain(ruleChains.stream().findFirst().get().getId()); } } + + public WebStorage getWebStorage() { + return webStorage = (WebStorage) driver; + } + + public void clearStorage() { + getWebStorage().getLocalStorage().clear(); + getWebStorage().getSessionStorage().clear(); + } + + public void deleteAlarmById(AlarmId alarmId) { + if (alarmId != null) { + testRestClient.deleteAlarm(alarmId); + } + } + + public void deleteAlarmsByIds(AlarmId... alarmIds) { + for (AlarmId alarmId : alarmIds) { + deleteAlarmById(alarmId); + } + } + + public void deleteCustomerById(CustomerId customerId) { + if (customerId != null) { + testRestClient.deleteCustomer(customerId); + } + } + + public void deleteDeviceById(DeviceId deviceId) { + if (deviceId != null) { + testRestClient.deleteDevice(deviceId); + } + } + + public void deleteAssetById(AssetId assetId) { + if (assetId != null) { + testRestClient.deleteAsset(assetId); + } + } + + public void deleteEntityView(EntityViewId entityViewId) { + if (entityViewId != null) { + testRestClient.deleteEntityView(entityViewId); + } + } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsEntityTabElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsEntityTabElements.java new file mode 100644 index 0000000000..65a8aeb1f1 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsEntityTabElements.java @@ -0,0 +1,78 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class AlarmDetailsEntityTabElements extends OtherPageElements { + public AlarmDetailsEntityTabElements(WebDriver driver) { + super(driver); + } + + private static final String ASSIGN_BTN = "//span[text() = '%s']/ancestor::mat-row//mat-icon[contains(text(),'keyboard_arrow_down')]/parent::button"; + private static final String USER_ASSIGN_DROPDOWN = "//div[@class='user-display-name']/span[text() = '%s']"; + protected static final String ASSIGN_USERS_DISPLAY_NAME = "//div[@class='user-display-name']/span"; + private static final String ASSIGN_USER_DISPLAY_NAME = "//span[@class='user-display-name'][contains(text(),'%s')]"; + private static final String SEARCH_FIELD = "//input[@placeholder='Search users']"; + private static final String UNASSIGNED_BTN = "//div[@role='listbox']//mat-icon[text() = 'account_circle']/following-sibling::span"; + private static final String UNASSIGNED = "//span[text() = '%s']/ancestor::mat-row//span[@class='assignee-cell']//mat-icon[text() = 'account_circle']/following-sibling::span"; + private static final String ALARM_DETAILS_BTN = "//span[text() = '%s']/ancestor::mat-row//mat-icon[contains(text(),'more_horiz')]/parent::button"; + private static final String ACCESS_FORBIDDEN_DIALOG_VIEW = "//h2[text() = 'Access Forbidden']/parent::tb-confirm-dialog"; + private static final String ALARM_ASSIGNEE_DROPDOWN = "//tb-alarm-assignee-panel"; + + public WebElement assignBtn(String type) { + return waitUntilElementToBeClickable(String.format(ASSIGN_BTN, type)); + } + + public WebElement userFromAssignDropDown(String userEmail) { + return waitUntilElementToBeClickable(String.format(USER_ASSIGN_DROPDOWN, userEmail)); + } + + public WebElement assignedUser(String userEmail) { + return waitUntilElementToBeClickable(String.format(ASSIGN_USER_DISPLAY_NAME, userEmail)); + } + + public List assignUsers() { + return waitUntilElementsToBeClickable(ASSIGN_USERS_DISPLAY_NAME); + } + + public WebElement searchUserField() { + return waitUntilElementToBeClickable(SEARCH_FIELD); + } + + public WebElement unassignedBtn() { + return waitUntilElementToBeClickable(UNASSIGNED_BTN); + } + + public WebElement unassigned(String alarmType) { + return waitUntilVisibilityOfElementLocated(String.format(UNASSIGNED, alarmType)); + } + + public WebElement alarmDetailsBtn(String alarmType) { + return waitUntilElementToBeClickable(String.format(ALARM_DETAILS_BTN, alarmType)); + } + + public WebElement accessForbiddenDialogView() { + return waitUntilVisibilityOfElementLocated(ACCESS_FORBIDDEN_DIALOG_VIEW); + } + + public WebElement alarmAssigneeDropdown() { + return waitUntilVisibilityOfElementLocated(ALARM_ASSIGNEE_DROPDOWN); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsEntityTabHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsEntityTabHelper.java new file mode 100644 index 0000000000..eac0ab889e --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsEntityTabHelper.java @@ -0,0 +1,61 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.List; +import java.util.stream.Collectors; + +public class AlarmDetailsEntityTabHelper extends AlarmDetailsEntityTabElements { + public AlarmDetailsEntityTabHelper(WebDriver driver) { + super(driver); + } + + public void assignAlarmTo(String alarmType, String user) { + jsClick(assignBtn(alarmType)); + userFromAssignDropDown(user).click(); + } + + public void unassignedAlarm(String alarmType) { + jsClick(assignBtn(alarmType)); + unassignedBtn().click(); + } + + public void searchAlarm(String alarmType, String emailOrName) { + jsClick(assignBtn(alarmType)); + searchUserField().sendKeys(emailOrName); + } + + private List users; + + public void setUsers() { + users = assignUsers() + .stream() + .map(WebElement::getText) + .collect(Collectors.toList()); + } + + public List getUsers() { + return users; + } + + public void assertUsersForAssignIsNotPresent() { + sleep(1); + elementsIsNotPresent(ASSIGN_USERS_DISPLAY_NAME); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsViewElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsViewElements.java new file mode 100644 index 0000000000..ced7ef43fc --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsViewElements.java @@ -0,0 +1,47 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.thingsboard.server.msa.ui.base.AbstractBasePage; + +public class AlarmDetailsViewElements extends AbstractBasePage { + public AlarmDetailsViewElements(WebDriver driver) { + super(driver); + } + + private static final String ASSIGN_FIELD = "//mat-label[text()='Assignee']/parent::label/parent::div//input"; + private static final String USER_FROM_DROP_DOWN = "//div[@class='user-display-name']/span[text() = '%s']"; + private static final String CLOSE_ALARM_DETAILS_VIEW_BTN = "//mat-dialog-container//mat-icon[contains(text(),'close')]/parent::button"; + private static final String UNASSIGNED_BTN = "//div[@role='listbox']//mat-icon[text() = 'account_circle']/following-sibling::span"; + + public WebElement assignField() { + return waitUntilElementToBeClickable(ASSIGN_FIELD); + } + + public WebElement userFromAssignDropdown(String emailOrName) { + return waitUntilElementToBeClickable(String.format(USER_FROM_DROP_DOWN, emailOrName)); + } + + public WebElement closeAlarmDetailsViewBtn() { + return waitUntilElementToBeClickable(CLOSE_ALARM_DETAILS_VIEW_BTN); + } + + public WebElement unassignedBtn() { + return waitUntilElementToBeClickable(UNASSIGNED_BTN); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsViewHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsViewHelper.java new file mode 100644 index 0000000000..63266804c1 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsViewHelper.java @@ -0,0 +1,34 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; + +public class AlarmDetailsViewHelper extends AlarmDetailsViewElements { + public AlarmDetailsViewHelper(WebDriver driver) { + super(driver); + } + + public void assignAlarmTo(String emailOrName) { + assignField().click(); + userFromAssignDropdown(emailOrName).click(); + } + + public void unassignedAlarm() { + assignField().click(); + unassignedBtn().click(); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AssetPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AssetPageElements.java new file mode 100644 index 0000000000..2c54cd4682 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AssetPageElements.java @@ -0,0 +1,37 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +public class AssetPageElements extends OtherPageElements { + public AssetPageElements(WebDriver driver) { + super(driver); + } + + private static final String ASSET_DETAILS_VIEW = "//tb-details-panel"; + private static final String ASSET_DETAILS_ALARMS = ASSET_DETAILS_VIEW + "//span[text()='Alarms']"; + + public WebElement assetDetailsView() { + return waitUntilPresenceOfElementLocated(ASSET_DETAILS_VIEW); + } + + public WebElement assetDetailsAlarmsBtn() { + return waitUntilElementToBeClickable(ASSET_DETAILS_ALARMS); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AssetPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AssetPageHelper.java new file mode 100644 index 0000000000..4e7a8c04e7 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AssetPageHelper.java @@ -0,0 +1,32 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; + +public class AssetPageHelper extends AssetPageElements { + public AssetPageHelper(WebDriver driver) { + super(driver); + } + + public void openAssetAlarms(String assetName) { + if (!assetDetailsView().isDisplayed()) { + entity(assetName).click(); + } + assetDetailsAlarmsBtn().click(); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java index 1d69ddd5fc..465c3d918e 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java @@ -32,14 +32,16 @@ public class CustomerPageElements extends OtherPageElementsHelper { private static final String TITLES = "//mat-cell[contains(@class,'cdk-column-title')]/span"; protected static final String EDIT_MENU_DASHBOARD_FIELD = "//input[@formcontrolname='dashboard']"; private static final String EDIT_MENU_DASHBOARD = "//div[@class='cdk-overlay-pane']//span/span[contains(text(),'%s')]"; - private static final String MANAGE_CUSTOMERS_USERS_BTN = ENTITY + "/ancestor::mat-row//mat-icon[contains(text(),' account_circle')]"; + private static final String MANAGE_CUSTOMERS_USERS_BTN = ENTITY + "/ancestor::mat-row//mat-icon[contains(text(),' account_circle')]/parent::button"; private static final String MANAGE_CUSTOMERS_ASSETS_BTN = ENTITY + "/ancestor::mat-row//mat-icon[contains(text(),' domain')]/parent::button"; private static final String MANAGE_CUSTOMERS_DEVICES_BTN = ENTITY + "/ancestor::mat-row//mat-icon[contains(text(),'devices_other')]/parent::button"; private static final String MANAGE_CUSTOMERS_DASHBOARDS_BTN = ENTITY + "/ancestor::mat-row//mat-icon[contains(text(),'dashboard')]/parent::button"; private static final String MANAGE_CUSTOMERS_EDGE_BTN = ENTITY + "/ancestor::mat-row//mat-icon[contains(text(),'router')]/parent::button"; private static final String ADD_USER_EMAIL = "//tb-add-user-dialog//input[@formcontrolname='email']"; private static final String ACTIVATE_WINDOW_OK_BTN = "//span[contains(text(),'OK')]"; - private static final String USER_LOGIN_BTN = "//mat-icon[@data-mat-icon-name='login']"; + private static final String USER_LOGIN_BTN = "//mat-icon[@data-mat-icon-name='login']/parent::button"; + private static final String USER_LOGIN_BTN_BY_EMAIL = "//mat-cell[contains(@class,'email')]/span[contains(text(),'%s')]" + + "/ancestor::mat-row//mat-icon[@data-mat-icon-name='login']/parent::button"; private static final String USERS_WIDGET = "//tb-widget"; private static final String SELECT_COUNTRY_MENU = "//mat-form-field//mat-select[@formcontrolname='country']"; private static final String COUNTRIES = "//span[@class='mdc-list-item__primary-text']"; @@ -71,6 +73,8 @@ public class CustomerPageElements extends OtherPageElementsHelper { private static final String MANAGE_CUSTOMERS_DASHBOARD_BTN_VIEW = "Manage dashboards"; private static final String MANAGE_CUSTOMERS_EDGE_BTN_VIEW = "Manage edges "; private static final String DELETE_FROM_VIEW_BTN = "//tb-customer//span[contains(text(),' Delete')]"; + private static final String CUSTOMER_DETAILS_VIEW = "//tb-details-panel"; + private static final String CUSTOMER_DETAILS_ALARMS = CUSTOMER_DETAILS_VIEW + "//span[text()='Alarms']"; public WebElement titleFieldAddEntityView() { return waitUntilElementToBeClickable(ADD_ENTITY_VIEW + String.format(INPUT_FIELD, INPUT_FIELD_NAME_TITLE)); @@ -148,6 +152,10 @@ public class CustomerPageElements extends OtherPageElementsHelper { return waitUntilElementToBeClickable(USER_LOGIN_BTN); } + public WebElement getUserLoginBtnByEmail(String email) { + return waitUntilElementToBeClickable(String.format(USER_LOGIN_BTN_BY_EMAIL, email)); + } + public WebElement usersWidget() { return waitUntilVisibilityOfElementLocated(USERS_WIDGET); } @@ -279,4 +287,12 @@ public class CustomerPageElements extends OtherPageElementsHelper { public WebElement customerViewDeleteBtn() { return waitUntilElementToBeClickable(DELETE_FROM_VIEW_BTN); } + + public WebElement customerDetailsView() { + return waitUntilPresenceOfElementLocated(CUSTOMER_DETAILS_VIEW); + } + + public WebElement customerDetailsAlarmsBtn() { + return waitUntilElementToBeClickable(CUSTOMER_DETAILS_ALARMS); + } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java index ba90361dc8..25b3aff7e1 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java @@ -161,4 +161,11 @@ public class CustomerPageHelper extends CustomerPageElements { phoneNumberEntityView().sendKeys(number); phoneNumberEntityView().sendKeys(Keys.TAB); } + + public void openCustomerAlarms(String customerName) { + if (!customerDetailsView().isDisplayed()) { + customer(customerName).click(); + } + customerDetailsAlarmsBtn().click(); + } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageElements.java new file mode 100644 index 0000000000..b8fbda5135 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageElements.java @@ -0,0 +1,67 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +public class DevicePageElements extends OtherPageElements { + public DevicePageElements(WebDriver driver) { + super(driver); + } + + private static final String DEVICE = "//table//span[text()='%s']"; + private static final String DEVICE_DETAILS_VIEW = "//tb-details-panel"; + private static final String DEVICE_DETAILS_ALARMS = DEVICE_DETAILS_VIEW + "//span[text()='Alarms']"; + private static final String ASSIGN_TO_CUSTOMER_BTN = "//mat-cell[contains(@class,'name')]/span[text()='%s']" + + "/ancestor::mat-row//mat-icon[contains(text(),'assignment_ind')]/parent::button"; + private static final String CHOOSE_CUSTOMER_FOR_ASSIGN_FIELD = "//input[@formcontrolname='entity']"; + private static final String CUSTOMER_FROM_ASSIGN_DROPDOWN = "//div[@role = 'listbox']//span[text() = '%s']"; + private static final String CLOSE_DEVICE_DETAILS_VIEW = "//header//mat-icon[contains(text(),'close')]/parent::button"; + private static final String SUBMIT_ASSIGN_TO_CUSTOMER_BTN = "//button[@type='submit']"; + + public WebElement device(String deviceName) { + return waitUntilElementToBeClickable(String.format(DEVICE, deviceName)); + } + + public WebElement deviceDetailsAlarmsBtn() { + return waitUntilElementToBeClickable(DEVICE_DETAILS_ALARMS); + } + + public WebElement deviceDetailsView() { + return waitUntilPresenceOfElementLocated(DEVICE_DETAILS_VIEW); + } + + public WebElement assignToCustomerBtn(String deviceName) { + return waitUntilElementToBeClickable(String.format(ASSIGN_TO_CUSTOMER_BTN, deviceName)); + } + + public WebElement chooseCustomerForAssignField() { + return waitUntilElementToBeClickable(CHOOSE_CUSTOMER_FOR_ASSIGN_FIELD); + } + + public WebElement customerFromAssignDropdown(String customerTitle) { + return waitUntilElementToBeClickable(String.format(CUSTOMER_FROM_ASSIGN_DROPDOWN, customerTitle)); + } + + public WebElement closeDeviceDetailsViewBtn() { + return waitUntilElementToBeClickable(CLOSE_DEVICE_DETAILS_VIEW); + } + + public WebElement submitAssignToCustomerBtn() { + return waitUntilElementToBeClickable(SUBMIT_ASSIGN_TO_CUSTOMER_BTN); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageHelper.java new file mode 100644 index 0000000000..19e85244cd --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageHelper.java @@ -0,0 +1,37 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; + +public class DevicePageHelper extends DevicePageElements { + public DevicePageHelper(WebDriver driver) { + super(driver); + } + + public void openDeviceAlarms(String deviceName) { + if (!deviceDetailsView().isDisplayed()) { + device(deviceName).click(); + } + deviceDetailsAlarmsBtn().click(); + } + + public void assignToCustomer(String customerTitle) { + chooseCustomerForAssignField().click(); + customerFromAssignDropdown(customerTitle).click(); + submitAssignToCustomerBtn().click(); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/EntityViewPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/EntityViewPageElements.java new file mode 100644 index 0000000000..0de6773bd1 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/EntityViewPageElements.java @@ -0,0 +1,37 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +public class EntityViewPageElements extends OtherPageElementsHelper { + public EntityViewPageElements(WebDriver driver) { + super(driver); + } + + private static final String ENTITY_VIEW_DETAILS_VIEW = "//tb-details-panel"; + private static final String ENTITY_VIEW_DETAILS_ALARMS = ENTITY_VIEW_DETAILS_VIEW + "//span[text()='Alarms']"; + + public WebElement entityViewDetailsView() { + return waitUntilPresenceOfElementLocated(ENTITY_VIEW_DETAILS_VIEW); + } + + public WebElement entityViewDetailsAlarmsBtn() { + return waitUntilElementToBeClickable(ENTITY_VIEW_DETAILS_ALARMS); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/EntityViewPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/EntityViewPageHelper.java new file mode 100644 index 0000000000..d5a17e8c1f --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/EntityViewPageHelper.java @@ -0,0 +1,32 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; + +public class EntityViewPageHelper extends EntityViewPageElements { + public EntityViewPageHelper(WebDriver driver) { + super(driver); + } + + public void openEntityViewAlarms(String customerName) { + if (!entityViewDetailsView().isDisplayed()) { + entity(customerName).click(); + } + entityViewDetailsAlarmsBtn().click(); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java index 38a4a50207..83666006c2 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java @@ -16,8 +16,6 @@ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.support.ui.ExpectedConditions; import org.thingsboard.server.msa.ui.utils.Const; public class LoginPageHelper extends LoginPageElements { diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java index ab8ee9bf55..54675bdc7a 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java @@ -30,6 +30,15 @@ public class SideBarMenuViewElements extends AbstractBasePage { private static final String PROFILES_BTN = "//mat-toolbar//mat-icon[text()='badge']/ancestor::tb-menu-toggle"; private static final String DEVICE_PROFILE_BTN = "//mat-toolbar//a[@href='/profiles/deviceProfiles']"; private static final String ASSET_PROFILE_BTN = "//mat-toolbar//a[@href='/profiles/assetProfiles']"; + private static final String ALARMS_BTN = "//mat-toolbar//a[@href='/alarms']"; + private static final String ENTITIES_DROPDOWN = "//mat-toolbar//mat-icon[text()='category']/ancestor::a//span[contains(@class,'pull-right')]"; + private static final String DEVICES_BTN = "//ul[@id='docs-menu-entity.entities']//span[text()='Devices']"; + private static final String ASSETS_BTN = "//ul[@id='docs-menu-entity.entities']//span[text()='Assets']"; + private static final String ENTITY_VIEWS_BTN = "//ul[@id='docs-menu-entity.entities']//span[text()='Entity Views']"; + + public WebElement entitiesDropdown() { + return waitUntilElementToBeClickable(ENTITIES_DROPDOWN); + } public WebElement ruleChainsBtn() { return waitUntilElementToBeClickable(RULE_CHAINS_BTN); @@ -54,4 +63,20 @@ public class SideBarMenuViewElements extends AbstractBasePage { public WebElement assetProfileBtn() { return waitUntilElementToBeClickable(ASSET_PROFILE_BTN); } + + public WebElement alarmsBtn() { + return waitUntilElementToBeClickable(ALARMS_BTN); + } + + public WebElement devicesBtn() { + return waitUntilElementToBeClickable(DEVICES_BTN); + } + + public WebElement assetsBtn() { + return waitUntilElementToBeClickable(ASSETS_BTN); + } + + public WebElement entityViewsBtn() { + return waitUntilElementToBeClickable(ENTITY_VIEWS_BTN); + } } \ No newline at end of file diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewHelper.java index 4d56689809..297438c193 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewHelper.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewHelper.java @@ -16,6 +16,7 @@ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; public class SideBarMenuViewHelper extends SideBarMenuViewElements { public SideBarMenuViewHelper(WebDriver driver) { @@ -31,4 +32,33 @@ public class SideBarMenuViewHelper extends SideBarMenuViewElements { profilesBtn().click(); assetProfileBtn().click(); } + + public void goToDevicesPage() { + openEntitiesDropdown(); + devicesBtn().click(); + } + + public void goToAssetsPage() { + openEntitiesDropdown(); + assetsBtn().click(); + } + + public void goToEntityViewsPage() { + openEntitiesDropdown(); + entityViewsBtn().click(); + } + + public void openEntitiesDropdown() { + if (entitiesDropdownIsClose()) { + entitiesDropdown().click(); + } + } + + public boolean entitiesDropdownIsClose() { + return dropdownIsClose(entitiesDropdown()); + } + + private boolean dropdownIsClose(WebElement dropdown) { + return !dropdown.getAttribute("class").contains("tb-toggled"); + } } \ No newline at end of file diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AbstractAssignTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AbstractAssignTest.java new file mode 100644 index 0000000000..1d13d16f4b --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AbstractAssignTest.java @@ -0,0 +1,105 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.tests.assignee; + +import io.qameta.allure.Epic; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.thingsboard.server.common.data.id.AlarmId; +import org.thingsboard.server.common.data.id.CustomerId; +import org.thingsboard.server.common.data.id.DeviceId; +import org.thingsboard.server.common.data.id.UserId; +import org.thingsboard.server.msa.ui.base.AbstractDriverBaseTest; +import org.thingsboard.server.msa.ui.pages.AlarmDetailsEntityTabHelper; +import org.thingsboard.server.msa.ui.pages.AlarmDetailsViewHelper; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.DevicePageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewHelper; +import org.thingsboard.server.msa.ui.utils.EntityPrototypes; + +import static org.thingsboard.server.msa.ui.base.AbstractBasePage.random; + +@Epic("Alarm assign") +abstract public class AbstractAssignTest extends AbstractDriverBaseTest { + + protected AlarmId alarmId; + protected AlarmId assignedAlarmId; + protected DeviceId deviceId; + protected UserId userId; + protected UserId userWithNameId; + protected CustomerId customerId; + protected String deviceName; + protected String userName; + protected String customerTitle; + protected String userEmail; + protected String userWithNameEmail; + protected String alarmType; + protected String assignedAlarmType; + protected SideBarMenuViewHelper sideBarMenuView; + protected AlarmDetailsEntityTabHelper alarmPage; + protected DevicePageHelper devicePage; + protected CustomerPageHelper customerPage; + protected AlarmDetailsViewHelper alarmDetailsView; + + @BeforeClass + public void generateCommonTestEntity() { + new LoginPageHelper(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewHelper(driver); + alarmPage = new AlarmDetailsEntityTabHelper(driver); + devicePage = new DevicePageHelper(driver); + customerPage = new CustomerPageHelper(driver); + alarmDetailsView = new AlarmDetailsViewHelper(driver); + + userName = "User " + random(); + customerTitle = "Customer " + random(); + userEmail = random() + "@thingsboard.org"; + userWithNameEmail = random() + "@thingsboard.org"; + alarmType = "Test alarm " + random(); + assignedAlarmType = "Test assigned alarm " + random(); + + customerId = testRestClient.postCustomer(EntityPrototypes.defaultCustomerPrototype(customerTitle)).getId(); + userId = testRestClient.postUser(EntityPrototypes.defaultUser(userEmail, getCustomerByName(customerTitle).getId())).getId(); + userWithNameId = testRestClient.postUser(EntityPrototypes.defaultUser(userWithNameEmail, getCustomerByName(customerTitle).getId(), userName)).getId(); + deviceName = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype("Device ", customerId)).getName(); + deviceId = testRestClient.getDeviceByName(deviceName).getId(); + } + + @AfterClass + public void deleteCommonEntities() { + deleteCustomerById(customerId); + deleteDeviceById(deviceId); + } + + @BeforeMethod + public void createCommonTestAlarms() { + alarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, alarmType)).getId(); + assignedAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, assignedAlarmType, userId)).getId(); + } + + @AfterMethod + public void deleteCommonCreatedAlarms() { + deleteAlarmsByIds(alarmId, assignedAlarmId); + } + + public void loginByUser(String userEmail) { + sideBarMenuView.customerBtn().click(); + customerPage.manageCustomersUserBtn(customerTitle).click(); + customerPage.getUserLoginBtnByEmail(userEmail).click(); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabAssignTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabAssignTest.java new file mode 100644 index 0000000000..9f90dddc90 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabAssignTest.java @@ -0,0 +1,253 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.tests.assignee; + +import io.qameta.allure.Description; +import io.qameta.allure.Feature; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.thingsboard.server.common.data.id.AlarmId; +import org.thingsboard.server.common.data.id.AssetId; +import org.thingsboard.server.common.data.id.EntityViewId; +import org.thingsboard.server.msa.ui.pages.AssetPageHelper; +import org.thingsboard.server.msa.ui.pages.EntityViewPageHelper; +import org.thingsboard.server.msa.ui.utils.Const; +import org.thingsboard.server.msa.ui.utils.EntityPrototypes; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.thingsboard.server.msa.ui.base.AbstractBasePage.random; + +@Feature("Assign from details tab of entity (by tenant)") +public class AssignDetailsTabAssignTest extends AbstractAssignTest { + + private AssetId assetId; + private AlarmId propageteAlarmId; + private AlarmId propageteAssigneAlarmId; + private AlarmId customerAlarmId; + private AlarmId assetAlarmId; + private AlarmId entityViewAlarmId; + private EntityViewId entityViewId; + private String assetName; + private String entityViewName; + private String propagateAlarmType; + private String propagateAssignedAlarmType; + private String customerAlarmType; + private String assetAlarmType; + private String entityViewAlarmType; + private AssetPageHelper assetPage; + private EntityViewPageHelper entityViewPage; + + @BeforeClass + public void generateTestEntities() { + assetPage = new AssetPageHelper(driver); + entityViewPage = new EntityViewPageHelper(driver); + + customerAlarmType = "Test customer alarm" + random(); + assetAlarmType = "Test asset alarm" + random(); + entityViewAlarmType = "Test entity view alarm" + random(); + propagateAlarmType = "Test propagated alarm " + random(); + propagateAssignedAlarmType = "Test propagated alarm " + random(); + + customerAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(customerId, customerAlarmType)).getId(); + assetId = testRestClient.postAsset(EntityPrototypes.defaultAssetPrototype("Asset", customerId)).getId(); + assetName = testRestClient.getAssetById(assetId).getName(); + assetAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(assetId, assetAlarmType)).getId(); + entityViewId = testRestClient.postEntityView(EntityPrototypes.defaultEntityViewPrototype("Entity view", "", "DEVICE")).getId(); + entityViewName = testRestClient.getEntityViewById(entityViewId).getName(); + entityViewAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(entityViewId, entityViewAlarmType)).getId(); + } + + @BeforeMethod + public void generateTestAlarms() { + propageteAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, propagateAlarmType, true)).getId(); + propageteAssigneAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, propagateAssignedAlarmType, userId, true)).getId(); + } + + @AfterClass + public void deleteTestEntities() { + deleteAlarmById(customerAlarmId); + deleteAlarmById(assetAlarmId); + deleteAlarmById(entityViewAlarmId); + deleteAssetById(assetId); + deleteEntityView(entityViewId); + } + + @AfterMethod + public void deleteTestAlarms() { + deleteAlarmsByIds(propageteAlarmId, propageteAssigneAlarmId); + } + + @DataProvider + public Object[][] alarms() { + return new Object[][]{ + {alarmType}, + {propagateAlarmType}}; + } + + @DataProvider + public Object[][] assignedAlarms() { + return new Object[][]{ + {assignedAlarmType}, + {propagateAssignedAlarmType}}; + } + + @Description("Can assign alarm to yourself/Can assign propagate alarm to yourself") + @Test(dataProvider = "alarms") + public void assignAlarmToYourself(String alarm) { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(alarm, Const.TENANT_EMAIL); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Description("Can assign alarm to another user/Can assign propagate alarm to another user") + @Test(dataProvider = "alarms") + public void assignAlarmToAnotherUser(String alarm) { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(alarm, userEmail); + + assertIsDisplayed(alarmPage.assignedUser(userEmail)); + } + + @Description("Can unassign alarm/Can unassign propagate alarm") + @Test(dataProvider = "assignedAlarms") + public void unassignedAlarm(String assignedAlarm) { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.unassignedAlarm(assignedAlarm); + + assertIsDisplayed(alarmPage.unassigned(assignedAlarm)); + } + + @Description("Can reassign alarm to another user/Can reassign propagate alarm to another user") + @Test(dataProvider = "assignedAlarms") + public void reassignAlarm(String assignedAlarm) { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(assignedAlarm, Const.TENANT_EMAIL); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Description("Search by email") + @Test + public void searchByEmail() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.searchAlarm(alarmType, Const.TENANT_EMAIL); + alarmPage.setUsers(); + + assertThat(alarmPage.getUsers()).hasSize(1).as("Search result contains search input").contains(Const.TENANT_EMAIL); + alarmPage.assignUsers().forEach(this::assertIsDisplayed); + } + + @Description("Search by name") + @Test(groups = "broken") + public void searchByName() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.searchAlarm(alarmType, userName); + alarmPage.setUsers(); + + assertThat(alarmPage.getUsers()).hasSize(1).as("Search result contains search input").contains(userName); + alarmPage.assignUsers().forEach(this::assertIsDisplayed); + } + + @Description("Assign alarm to yourself from details of alarm") + @Test + public void assignAlarmToYourselfFromDetails() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.alarmDetailsBtn(alarmType).click(); + alarmDetailsView.assignAlarmTo(Const.TENANT_EMAIL); + alarmDetailsView.closeAlarmDetailsViewBtn().click(); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Description("Assign alarm to another user from details of alarm") + @Test + public void assignAlarmToAnotherUserFromDetails() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.alarmDetailsBtn(alarmType).click(); + alarmDetailsView.assignAlarmTo(userEmail); + alarmDetailsView.closeAlarmDetailsViewBtn().click(); + + assertIsDisplayed(alarmPage.assignedUser(userEmail)); + } + + @Description("Unassign alarm from details of alarm") + @Test + public void unassignedAlarmFromDetails() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.alarmDetailsBtn(assignedAlarmType).click(); + alarmDetailsView.unassignedAlarm(); + alarmDetailsView.closeAlarmDetailsViewBtn().click(); + + assertIsDisplayed(alarmPage.unassigned(assignedAlarmType)); + } + + @Description("Reassign alarm to another user from details of alarm") + @Test + public void reassignAlarmFromDetails() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.alarmDetailsBtn(assignedAlarmType).click(); + alarmDetailsView.assignAlarmTo(Const.TENANT_EMAIL); + alarmDetailsView.closeAlarmDetailsViewBtn().click(); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Description("Assign alarm to yourself for Customer entity details") + @Test + public void assignCustomerAlarmToYourself() { + sideBarMenuView.customerBtn().click(); + customerPage.openCustomerAlarms(customerTitle); + alarmPage.assignAlarmTo(customerAlarmType, Const.TENANT_EMAIL); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Description("Assign alarm to yourself for Asset details") + @Test + public void assignAssetAlarmToYourself() { + sideBarMenuView.goToAssetsPage(); + assetPage.openAssetAlarms(assetName); + alarmPage.assignAlarmTo(assetAlarmType, Const.TENANT_EMAIL); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Description("Assign alarm to yourself for Entity view details") + @Test + public void assignEntityViewsAlarmToYourself() { + sideBarMenuView.goToEntityViewsPage(); + entityViewPage.openEntityViewAlarms(entityViewName); + alarmPage.assignAlarmTo(entityViewAlarmType, Const.TENANT_EMAIL); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabFromCustomerAssignTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabFromCustomerAssignTest.java new file mode 100644 index 0000000000..301a61fdf4 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabFromCustomerAssignTest.java @@ -0,0 +1,171 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.tests.assignee; + +import io.qameta.allure.Description; +import io.qameta.allure.Feature; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.common.data.id.AlarmId; +import org.thingsboard.server.common.data.id.DeviceId; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.utils.Const; +import org.thingsboard.server.msa.ui.utils.EntityPrototypes; + +import static org.thingsboard.server.msa.ui.base.AbstractBasePage.random; + +@Feature("Assign from details tab of entity (by customer)") +public class AssignDetailsTabFromCustomerAssignTest extends AbstractAssignTest { + + private AlarmId tenantAlarmId; + private DeviceId tenantDeviceId; + private String tenantDeviceName; + private String tenantAlarmType; + private AlarmId assignedTenantAlarmId; + + @BeforeMethod + public void generateTenantEntity() { + if (getJwtTokenFromLocalStorage() == null) { + new LoginPageHelper(driver).authorizationTenant(); + } + tenantAlarmType = "Test tenant alarm " + random(); + + tenantDeviceName = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype("")).getName(); + tenantDeviceId = testRestClient.getDeviceByName(tenantDeviceName).getId(); + tenantAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(tenantDeviceId, tenantAlarmType)).getId(); + } + + @AfterMethod + public void deleteTenantEntity() { + deleteAlarmsByIds(tenantAlarmId, assignedTenantAlarmId); + deleteDeviceById(tenantDeviceId); + clearStorage(); + } + + @Description("Can assign alarm to yourself") + @Test + public void assignAlarmToYourselfCustomer() { + loginByUser(userEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(alarmType, userEmail); + + assertIsDisplayed(alarmPage.assignedUser(userEmail)); + } + + @Description("Can reassign alarm from himself to another customer user") + @Test + public void reassignAlarmByCustomerFromAnotherCustomerUser() { + loginByUser(userWithNameEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(assignedAlarmType, userName); + + assertIsDisplayed(alarmPage.assignedUser(userName)); + } + + @Description("Can unassign alarm from himself") + @Test + public void unassignedAlarmFromCustomer() { + loginByUser(userEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.unassignedAlarm(assignedAlarmType); + + assertIsDisplayed(alarmPage.unassigned(assignedAlarmType)); + } + + @Description("Unassign alarm from any other customer user") + @Test + public void unassignedAlarmFromAnotherUserFromCustomer() { + loginByUser(userWithNameEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.unassignedAlarm(assignedAlarmType); + + assertIsDisplayed(alarmPage.unassigned(assignedAlarmType)); + } + + @Description("Unassign alarm from any tenant user") + @Test + public void unassignedAlarmFromTenant() { + String assignedTenantAlarmType = "Test tenant assigned alarm " + random(); + assignedTenantAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, assignedTenantAlarmType)).getId(); + + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(assignedTenantAlarmType, Const.TENANT_EMAIL); + devicePage.closeDeviceDetailsViewBtn().click(); + loginByUser(userWithNameEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.unassignedAlarm(assignedTenantAlarmType); + + assertIsDisplayed(alarmPage.unassigned(assignedTenantAlarmType)); + } + + @Description("Check the display of names (emails)") + @Test + public void checkTheDisplayOfNamesEmailsFromCustomer() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(tenantDeviceName); + alarmPage.assignAlarmTo(tenantAlarmType, Const.TENANT_EMAIL); + devicePage.closeDeviceDetailsViewBtn().click(); + devicePage.assignToCustomerBtn(tenantDeviceName).click(); + devicePage.assignToCustomer(customerTitle); + loginByUser(userEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(tenantDeviceName); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Description("Check the reassign tenant for old alarm on device") + @Test + public void reassignTenantForOldAlarm() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(tenantDeviceName); + alarmPage.assignAlarmTo(tenantAlarmType, Const.TENANT_EMAIL); + devicePage.closeDeviceDetailsViewBtn().click(); + devicePage.assignToCustomerBtn(tenantDeviceName).click(); + devicePage.assignToCustomer(customerTitle); + loginByUser(userEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(tenantDeviceName); + jsClick(alarmPage.assignBtn(tenantAlarmType)); + + assertIsDisplayed(alarmPage.accessForbiddenDialogView()); + } + + @Description("Check the reassign tenant for old alarm on device") + @Test + public void reassignTenantForOldAlarmFromDetails() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(tenantDeviceName); + alarmPage.assignAlarmTo(tenantAlarmType, Const.TENANT_EMAIL); + devicePage.closeDeviceDetailsViewBtn().click(); + devicePage.assignToCustomerBtn(tenantDeviceName).click(); + devicePage.assignToCustomer(customerTitle); + loginByUser(userEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(tenantDeviceName); + alarmPage.alarmDetailsBtn(tenantAlarmType).click(); + + + assertIsDisplayed(alarmPage.accessForbiddenDialogView()); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java index 23119e6d83..99f05e6f1d 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java @@ -15,18 +15,29 @@ */ package org.thingsboard.server.msa.ui.utils; +import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils; import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.server.common.data.Customer; +import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfileProvisionType; import org.thingsboard.server.common.data.DeviceProfileType; import org.thingsboard.server.common.data.DeviceTransportType; +import org.thingsboard.server.common.data.EntityView; +import org.thingsboard.server.common.data.User; +import org.thingsboard.server.common.data.alarm.Alarm; +import org.thingsboard.server.common.data.alarm.AlarmSeverity; +import org.thingsboard.server.common.data.asset.Asset; import org.thingsboard.server.common.data.asset.AssetProfile; import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration; import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration; import org.thingsboard.server.common.data.device.profile.DeviceProfileData; import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration; +import org.thingsboard.server.common.data.id.CustomerId; +import org.thingsboard.server.common.data.id.EntityId; +import org.thingsboard.server.common.data.id.UserId; import org.thingsboard.server.common.data.rule.RuleChain; +import org.thingsboard.server.common.data.security.Authority; public class EntityPrototypes { @@ -111,4 +122,88 @@ public class EntityPrototypes { assetProfile.setDescription(description); return assetProfile; } + + public static Alarm defaultAlarm(EntityId id, String type) { + Alarm alarm = new Alarm(); + alarm.setType(type); + alarm.setOriginator(id); + alarm.setSeverity(AlarmSeverity.CRITICAL); + return alarm; + } + + public static Alarm defaultAlarm(EntityId id, String type, boolean propagate) { + Alarm alarm = new Alarm(); + alarm.setType(type); + alarm.setOriginator(id); + alarm.setSeverity(AlarmSeverity.CRITICAL); + alarm.setPropagate(propagate); + return alarm; + } + + public static Alarm defaultAlarm(EntityId id, String type, UserId userId) { + Alarm alarm = new Alarm(); + alarm.setType(type); + alarm.setOriginator(id); + alarm.setSeverity(AlarmSeverity.CRITICAL); + alarm.setAssigneeId(userId); + return alarm; + } + + public static Alarm defaultAlarm(EntityId id, String type, UserId userId, boolean propagate) { + Alarm alarm = new Alarm(); + alarm.setType(type); + alarm.setOriginator(id); + alarm.setSeverity(AlarmSeverity.CRITICAL); + alarm.setAssigneeId(userId); + alarm.setPropagate(propagate); + return alarm; + } + + public static User defaultUser(String email, CustomerId customerId) { + User user = new User(); + user.setEmail(email); + user.setCustomerId(customerId); + user.setAuthority(Authority.CUSTOMER_USER); + return user; + } + + public static User defaultUser(String email, CustomerId customerId, String name) { + User user = new User(); + user.setEmail(email); + user.setFirstName(name); + user.setCustomerId(customerId); + user.setAuthority(Authority.CUSTOMER_USER); + return user; + } + + public static Device defaultDevicePrototype(String name) { + Device device = new Device(); + device.setName(name + RandomStringUtils.randomAlphanumeric(7)); + device.setType("DEFAULT"); + return device; + } + + public static Device defaultDevicePrototype(String name, CustomerId id) { + Device device = new Device(); + device.setName(name + RandomStringUtils.randomAlphanumeric(7)); + device.setCustomerId(id); + device.setType("DEFAULT"); + return device; + } + + public static Asset defaultAssetPrototype(String name, CustomerId id) { + Asset asset = new Asset(); + asset.setName(name + RandomStringUtils.randomAlphanumeric(7)); + asset.setCustomerId(id); + asset.setType("DEFAULT"); + return asset; + } + + public static EntityView defaultEntityViewPrototype(String name, String type, String entityType) { + EntityView entityView = new EntityView(); + entityView.setName(name + RandomStringUtils.randomAlphanumeric(7)); + entityView.setType(type + RandomStringUtils.randomAlphanumeric(7)); + entityView.setAdditionalInfo(JacksonUtil.newObjectNode().put("entityType", entityType)); + return entityView; + } } diff --git a/msa/black-box-tests/src/test/resources/assignee.xml b/msa/black-box-tests/src/test/resources/assignee.xml new file mode 100644 index 0000000000..49fe1aa195 --- /dev/null +++ b/msa/black-box-tests/src/test/resources/assignee.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file