From 0cd8003dd79c95dc8fd826b4f523171d201911d5 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 4 Jun 2019 16:26:42 +0400 Subject: [PATCH] #103 add tests for deadline --- .../resources/templates/grants/grant.html | 2 +- src/test/java/IndexGrantTest.java | 52 +++++++++++++++++++ src/test/java/grant/GrantPage.java | 26 ++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 38047bf..2699fa6 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -49,7 +49,7 @@
-
+
> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + String grantId = grantPage.getId(); + Integer deadlineCount = grantPage.getDeadlineCount(); + + String description = "deadline test"; + String date = "09.09.2019"; + String dateValue = "2019-09-09"; + grantPage.addDeadline(); + grantPage.setDeadline(date, deadlineCount, description); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + + Assert.assertTrue(grantPage.checkDeadline(description, dateValue)); + } + + @Test + public void deleteDeadline() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + String grantId = grantPage.getId(); + Integer deadlineCount = grantPage.getDeadlineCount(); + + String description = "deadline test"; + String date = "09.09.2019"; + String dateValue = "2019-09-09"; + grantPage.addDeadline(); + grantPage.setDeadline(date, deadlineCount, description); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + deadlineCount = grantPage.getDeadlineCount(); + + grantPage.deleteDeadline(); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + Integer newDeadlineCount = grantPage.getDeadlineCount(); + Assert.assertEquals(deadlineCount - 1, (int) newDeadlineCount); + } } diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index 809e22f..9fd1986 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -83,4 +83,30 @@ public class GrantPage extends PageObject { select.deselectByVisibleText(select.getFirstSelectedOption().getText()); return select.getAllSelectedOptions(); } + + public List getDeadlineList() { + return driver.findElements(By.id("deadlines")); + } + + public Integer getDeadlineCount() { + return getDeadlineList().size(); + } + + public void addDeadline() { + driver.findElement(By.id("addDeadline")).click(); + } + + public boolean checkDeadline(String description, String dateValue) { + return getDeadlineList() + .stream() + .anyMatch(webElement -> { + return webElement.findElement(By.className("div-deadline-description")).findElement( + By.tagName("input")).getAttribute("value").equals(description) + && webElement.findElement(By.className("form-deadline-date")).getAttribute("value").equals(dateValue); + }); + } + + public void deleteDeadline() { + driver.findElements(By.className("btn-delete-deadline")).get(0).click(); + } }