From ecda92326be467704b9e4e51128ee4440bc4ba45 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 16:04:51 +0400 Subject: [PATCH 1/9] #103 create blank classes --- src/test/java/grant/GrantPage.java | 10 ++++++++++ src/test/java/grant/GrantsDashboardPage.java | 10 ++++++++++ src/test/java/grant/GrantsPage.java | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/test/java/grant/GrantPage.java create mode 100644 src/test/java/grant/GrantsDashboardPage.java create mode 100644 src/test/java/grant/GrantsPage.java diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java new file mode 100644 index 0000000..a0eee3c --- /dev/null +++ b/src/test/java/grant/GrantPage.java @@ -0,0 +1,10 @@ +package grant; + +import core.PageObject; + +public class GrantPage extends PageObject { + @Override + public String getSubTitle() { + return null; + } +} diff --git a/src/test/java/grant/GrantsDashboardPage.java b/src/test/java/grant/GrantsDashboardPage.java new file mode 100644 index 0000000..02939e1 --- /dev/null +++ b/src/test/java/grant/GrantsDashboardPage.java @@ -0,0 +1,10 @@ +package grant; + +import core.PageObject; + +public class GrantsDashboardPage extends PageObject { + @Override + public String getSubTitle() { + return null; + } +} diff --git a/src/test/java/grant/GrantsPage.java b/src/test/java/grant/GrantsPage.java new file mode 100644 index 0000000..9d8d6cf --- /dev/null +++ b/src/test/java/grant/GrantsPage.java @@ -0,0 +1,10 @@ +package grant; + +import core.PageObject; + +public class GrantsPage extends PageObject { + @Override + public String getSubTitle() { + return null; + } +} From b1c090b0eaf5411ab8d75cb209e2f3143bedecb2 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 23:11:06 +0400 Subject: [PATCH 2/9] #103 add selenium-support library --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 38de2c7..bd3f6e8 100644 --- a/build.gradle +++ b/build.gradle @@ -127,5 +127,6 @@ dependencies { testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1' + compile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.3.1' } \ No newline at end of file From 16885cc94f41a50fb9dae5ce7e1de64dfd68e575 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 23:12:30 +0400 Subject: [PATCH 3/9] #103 update overriding method --- src/test/java/grant/GrantsDashboardPage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/grant/GrantsDashboardPage.java b/src/test/java/grant/GrantsDashboardPage.java index 02939e1..036e785 100644 --- a/src/test/java/grant/GrantsDashboardPage.java +++ b/src/test/java/grant/GrantsDashboardPage.java @@ -1,10 +1,11 @@ package grant; import core.PageObject; +import org.openqa.selenium.By; public class GrantsDashboardPage extends PageObject { @Override public String getSubTitle() { - return null; + return driver.findElement(By.tagName("h2")).getText(); } } From 3e9bbb35840e11c06176be961109df1e55d2bcbe Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 22 May 2019 23:15:04 +0400 Subject: [PATCH 4/9] #103 create tests for create, update and delete functions --- src/test/java/IndexGrantTest.java | 92 +++++++++++++++++++++++++++++ src/test/java/grant/GrantPage.java | 40 ++++++++++++- src/test/java/grant/GrantsPage.java | 30 +++++++++- 3 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 src/test/java/IndexGrantTest.java diff --git a/src/test/java/IndexGrantTest.java b/src/test/java/IndexGrantTest.java new file mode 100644 index 0000000..064b2c7 --- /dev/null +++ b/src/test/java/IndexGrantTest.java @@ -0,0 +1,92 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import core.PageObject; +import core.TestTemplate; +import grant.GrantPage; +import grant.GrantsDashboardPage; +import grant.GrantsPage; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import ru.ulstu.NgTrackerApplication; +import ru.ulstu.configuration.ApplicationProperties; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@RunWith(SpringRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class IndexGrantTest extends TestTemplate { + private final Map> navigationHolder = ImmutableMap.of( + new GrantsPage(), Arrays.asList("ГРАНТЫ", "/grants/grants"), + new GrantPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ГРАНТА", "/grants/grant?id=0"), + new GrantsDashboardPage(), Arrays.asList("Гранты", "/grants/dashboard") + ); + + @Autowired + private ApplicationProperties applicationProperties; + + @Test + public void createNewGrant() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + + String newGrantName = "test grant" + (new Date()); + grantPage.setTitle(newGrantName); + String deadlineDate = new Date().toString(); + String deadlineDescription = "test deadline description"; + grantPage.setDeadline(deadlineDate, 0, deadlineDescription); + grantPage.setLeader(); + grantPage.saveGrant(); + + Assert.assertTrue(grantsPage.findGrantByTitle(newGrantName)); + } + + @Test + public void createBlankGrant() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); + + grantPage.saveGrant(); + + Assert.assertTrue(grantPage.checkBlankFields()); + } + + @Test + public void updateGrantTitle() { + 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 newGrantTitle = "test " + (new Date()); + grantPage.setTitle(newGrantTitle); + grantPage.saveGrant(); + + Assert.assertTrue(grantsPage.findGrantByTitle(newGrantTitle)); + } + + @Test + public void deleteGrant() throws InterruptedException { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + + Integer size = grantsPage.getGrantsList().size(); + grantsPage.deleteFirst(); + Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); + } +} diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index a0eee3c..1754db5 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -1,10 +1,48 @@ package grant; import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; public class GrantPage extends PageObject { @Override public String getSubTitle() { - return null; + return driver.findElement(By.tagName("h2")).getText(); + } + + public String getId() { + return driver.findElement(By.id("id")).getAttribute("value"); + } + + public void setTitle(String name) { + driver.findElement(By.id("title")).clear(); + driver.findElement(By.id("title")).sendKeys(name); + } + + public String getTitle() { + return driver.findElement(By.id("title")).getAttribute("value"); + } + + public void setDeadline(String date, Integer i, String description) { + driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); + driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); + } + + public void setLeader() { + WebElement webElement = driver.findElement(By.id("leaderId")); + Select selectLeader = new Select(webElement); + selectLeader.selectByVisibleText("Романов"); + } + + public void saveGrant() { + driver.findElement(By.id("sendMessageButton")).click(); + } + + public boolean checkBlankFields() { + if (driver.findElements(By.className("alert-danger")).size() > 0) { + return true; + } + return false; } } diff --git a/src/test/java/grant/GrantsPage.java b/src/test/java/grant/GrantsPage.java index 9d8d6cf..68f50db 100644 --- a/src/test/java/grant/GrantsPage.java +++ b/src/test/java/grant/GrantsPage.java @@ -1,10 +1,38 @@ package grant; import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; public class GrantsPage extends PageObject { @Override public String getSubTitle() { - return null; + return driver.findElement(By.tagName("h2")).getText(); + } + + public List getGrantsList() { + return driver.findElements(By.cssSelector("span.h6")); + } + + public boolean findGrantByTitle(String grantTitle) { + return getGrantsList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(grantTitle)); + } + + public void deleteFirst() throws InterruptedException { + WebElement findDeleteButton = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div")); + findDeleteButton.click(); + Thread.sleep(3000); + WebElement grant = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[2]")); + grant.click(); + WebElement ok = driver.findElement(By.id("dataConfirmOK")); + ok.click(); + } + + public void getFirstGrant() { + driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[1]")).click(); } } From 47131f1fb777c3ecbf087dbf67bbc9dcb8948046 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 23 May 2019 13:43:18 +0400 Subject: [PATCH 5/9] #103 add tests for papers --- src/test/java/IndexGrantTest.java | 30 ++++++++++++++++++++++- src/test/java/grant/GrantPage.java | 38 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/test/java/IndexGrantTest.java b/src/test/java/IndexGrantTest.java index 064b2c7..c633cfa 100644 --- a/src/test/java/IndexGrantTest.java +++ b/src/test/java/IndexGrantTest.java @@ -81,7 +81,6 @@ public class IndexGrantTest extends TestTemplate { @Test public void deleteGrant() throws InterruptedException { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -89,4 +88,33 @@ public class IndexGrantTest extends TestTemplate { grantsPage.deleteFirst(); Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); } + + @Test + public void attachPaper() { + 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(); + Integer countPapers = grantPage.getAttachedPapers().size(); + + Assert.assertEquals(countPapers + 1, grantPage.attachPaper().size()); + } + + @Test + public void deletePaper() { + 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(); + Integer oldCountPapers = grantPage.getAttachedPapers().size(); + if (oldCountPapers == 0) { + oldCountPapers = grantPage.attachPaper().size(); + } + + Assert.assertEquals(oldCountPapers - 1, grantPage.deletePaper().size()); + } } diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index 1754db5..809e22f 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -5,6 +5,8 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.Select; +import java.util.List; + public class GrantPage extends PageObject { @Override public String getSubTitle() { @@ -45,4 +47,40 @@ public class GrantPage extends PageObject { } return false; } + + public List getAttachedPapers() { + try { + return driver.findElement(By.className("div-selected-papers")).findElements(By.tagName("div")); + } catch (Exception ex) { + return null; + } + } + + public List attachPaper() { + WebElement selectPapers = driver.findElement(By.id("allPapers")); + Select select = new Select(selectPapers); + List selectedOptions = select.getAllSelectedOptions(); + List allOptions = select.getOptions(); + if (selectedOptions.size() >= allOptions.size()) { + for (int i = 0; i < allOptions.size(); i++) { + if (!allOptions.get(i).equals(selectedOptions.get(i))) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + return selectedOptions; + } + } + } else { + select.selectByVisibleText(allOptions.get(0).getText()); + selectedOptions.add(allOptions.get(0)); + return selectedOptions; + } + return null; + } + + public List deletePaper() { + WebElement selectPapers = driver.findElement(By.id("allPapers")); + Select select = new Select(selectPapers); + select.deselectByVisibleText(select.getFirstSelectedOption().getText()); + return select.getAllSelectedOptions(); + } } From 0cd8003dd79c95dc8fd826b4f523171d201911d5 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 4 Jun 2019 16:26:42 +0400 Subject: [PATCH 6/9] #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(); + } } From 1ff38fc80e83f781688247ffffa487de09a7678d Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 5 Jun 2019 09:36:29 +0400 Subject: [PATCH 7/9] #103 merge with dev --- .../ru/ulstu/conference/service/ConferenceService.java | 2 +- src/main/java/ru/ulstu/grant/service/GrantService.java | 1 - .../ru/ulstu/project/controller/ProjectController.java | 1 - src/main/java/ru/ulstu/project/model/Project.java | 10 +++++----- src/main/java/ru/ulstu/students/model/Task.java | 5 ----- .../java/ru/ulstu/students/service/TaskService.java | 6 +++--- .../java/ru/ulstu/timeline/service/EventService.java | 1 - .../java/ru/ulstu/user/controller/UserController.java | 2 -- .../ru/ulstu/user/controller/UserMvcController.java | 2 +- src/main/java/ru/ulstu/user/service/UserService.java | 2 +- .../ru/ulstu/utils/timetable/TimetableService.java | 8 ++++---- src/main/java/ru/ulstu/utils/timetable/model/Day.java | 2 +- .../java/ru/ulstu/utils/timetable/model/Lesson.java | 2 +- .../ulstu/utils/timetable/model/TimetableResponse.java | 2 +- .../templates/grants/fragments/grantLineFragment.html | 6 ++++-- .../templates/papers/fragments/paperLineFragment.html | 6 ++++-- src/main/resources/templates/papers/paper.html | 1 + src/main/resources/templates/projects/project.html | 6 ++++-- src/main/resources/templates/resetRequest.html | 5 +++-- src/main/resources/templates/users/dashboard.html | 1 + .../users/fragments/userDashboardFragment.html | 10 +++++++--- .../ru/ulstu/project/service/ProjectServiceTest.java | 5 ++++- 22 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index f742139..d877232 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -25,9 +25,9 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Collections; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 27841e3..542965a 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -1,6 +1,5 @@ package ru.ulstu.grant.service; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 87ae8df..a991e35 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 07f0141..6b5f925 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -12,16 +12,16 @@ import ru.ulstu.grant.model.Grant; import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; +import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.OneToMany; -import javax.persistence.CascadeType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; import javax.persistence.FetchType; -import javax.persistence.ManyToMany; +import javax.persistence.JoinColumn; import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/ru/ulstu/students/model/Task.java b/src/main/java/ru/ulstu/students/model/Task.java index 2e63a3c..c3f195b 100644 --- a/src/main/java/ru/ulstu/students/model/Task.java +++ b/src/main/java/ru/ulstu/students/model/Task.java @@ -6,13 +6,8 @@ import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.EventSource; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.deadline.service.DeadlineService; -import ru.ulstu.students.repository.SchedulerRepository; -import ru.ulstu.students.repository.TaskRepository; import ru.ulstu.tags.model.Tag; -import ru.ulstu.tags.service.TagService; import ru.ulstu.timeline.model.Event; -import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index f78f8f7..548e899 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -18,15 +18,15 @@ import ru.ulstu.tags.service.TagService; import ru.ulstu.timeline.service.EventService; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Set; import java.util.Map; +import java.util.Set; import java.util.TreeMap; -import java.util.ArrayList; -import java.util.Arrays; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index c22b9a3..868d576 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -18,7 +18,6 @@ import ru.ulstu.timeline.repository.EventRepository; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.service.UserService; -import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index c40ed8f..407986f 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -3,7 +3,6 @@ package ru.ulstu.user.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.access.annotation.Secured; -import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -33,7 +32,6 @@ import ru.ulstu.user.service.UserSessionService; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.validation.Valid; - import java.util.Map; import static ru.ulstu.user.controller.UserController.URL; diff --git a/src/main/java/ru/ulstu/user/controller/UserMvcController.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java index 044bde8..7f1c1b8 100644 --- a/src/main/java/ru/ulstu/user/controller/UserMvcController.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -9,8 +9,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import ru.ulstu.configuration.Constants; import ru.ulstu.odin.controller.OdinController; -import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.User; +import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserListDto; import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserSessionService; diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 217215b..b731c1e 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -252,7 +252,7 @@ public class UserService implements UserDetailsService { mailService.sendChangePasswordMail(user); } - public boolean requestUserPasswordReset(String email) { + public boolean requestUserPasswordReset(String email) { User user = userRepository.findOneByEmailIgnoreCase(email); if (user == null) { throw new UserNotFoundException(email); diff --git a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java index d65e276..78a1c66 100644 --- a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java +++ b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java @@ -18,7 +18,7 @@ public class TimetableService { private static final String TIMETABLE_URL = "http://timetable.athene.tech/api/1.0/timetable?filter=%s"; private SimpleDateFormat lessonTimeFormat = new SimpleDateFormat("hh:mm"); - private long[] lessonsStarts = new long[] { + private long[] lessonsStarts = new long[]{ lessonTimeFormat.parse("8:00:00").getTime(), lessonTimeFormat.parse("9:40:00").getTime(), lessonTimeFormat.parse("11:30:00").getTime(), @@ -58,8 +58,8 @@ public class TimetableService { firstJan.set(Calendar.MONTH, 0); firstJan.set(Calendar.DAY_OF_MONTH, 1); - return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000) - + DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2)); + return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000) + + DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2)); } private TimetableResponse getTimetableForUser(String userFIO) throws RestClientException { @@ -67,7 +67,7 @@ public class TimetableService { return restTemplate.getForObject(String.format(TIMETABLE_URL, userFIO), TimetableResponse.class); } - public Lesson getCurrentLesson(String userFio) { + public Lesson getCurrentLesson(String userFio) { TimetableResponse response; try { response = getTimetableForUser(userFio); diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Day.java b/src/main/java/ru/ulstu/utils/timetable/model/Day.java index e4e37f9..211165d 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/Day.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/Day.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; -public class Day { +public class Day { private Integer day; private List> lessons = new ArrayList<>(); diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java b/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java index b1b1707..9c855bd 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java @@ -1,6 +1,6 @@ package ru.ulstu.utils.timetable.model; -public class Lesson { +public class Lesson { private String group; private String nameOfLesson; private String teacher; diff --git a/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java b/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java index 925d9a8..118c979 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java @@ -1,6 +1,6 @@ package ru.ulstu.utils.timetable.model; -public class TimetableResponse { +public class TimetableResponse { private Response response; private String error; diff --git a/src/main/resources/templates/grants/fragments/grantLineFragment.html b/src/main/resources/templates/grants/fragments/grantLineFragment.html index 877f1d7..3a2a683 100644 --- a/src/main/resources/templates/grants/fragments/grantLineFragment.html +++ b/src/main/resources/templates/grants/fragments/grantLineFragment.html @@ -8,8 +8,10 @@
- - + + diff --git a/src/main/resources/templates/papers/fragments/paperLineFragment.html b/src/main/resources/templates/papers/fragments/paperLineFragment.html index 40d9c34..1975dc0 100644 --- a/src/main/resources/templates/papers/fragments/paperLineFragment.html +++ b/src/main/resources/templates/papers/fragments/paperLineFragment.html @@ -8,8 +8,10 @@
- - + + diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 2fbfa3a..e77ccbb 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -530,6 +530,7 @@ } } + @@ -35,7 +35,8 @@
- +
diff --git a/src/main/resources/templates/users/fragments/userDashboardFragment.html b/src/main/resources/templates/users/fragments/userDashboardFragment.html index 267bbf8..3095cca 100644 --- a/src/main/resources/templates/users/fragments/userDashboardFragment.html +++ b/src/main/resources/templates/users/fragments/userDashboardFragment.html @@ -7,9 +7,13 @@
-

-

-

+

+
+

+
+

+

Онлайн

diff --git a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java index 4015f3b..25a201b 100644 --- a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java +++ b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java @@ -20,7 +20,10 @@ import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; From acd58005deaec61bc99d664abffe4c48463d3c57 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 5 Jun 2019 15:52:29 +0400 Subject: [PATCH 8/9] #103 merge with 44 --- .../templates/conferences/conference.html | 6 ++++-- .../grants/fragments/grantLineFragment.html | 4 ++++ .../grants/fragments/grantStatusFragment.html | 2 +- .../resources/templates/grants/grant.html | 2 ++ .../fragments/paperDashboardFragment.html | 3 ++- .../papers/fragments/paperLineFragment.html | 4 ++-- .../papers/fragments/paperStatusFragment.html | 21 ++++++++++--------- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 201aa01..106f014 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -156,14 +156,16 @@ - + Имя статьи - + Имя статьи diff --git a/src/main/resources/templates/grants/fragments/grantLineFragment.html b/src/main/resources/templates/grants/fragments/grantLineFragment.html index 3a2a683..821cf89 100644 --- a/src/main/resources/templates/grants/fragments/grantLineFragment.html +++ b/src/main/resources/templates/grants/fragments/grantLineFragment.html @@ -14,6 +14,10 @@ th:title="${grant.title}"/> + + + diff --git a/src/main/resources/templates/grants/fragments/grantStatusFragment.html b/src/main/resources/templates/grants/fragments/grantStatusFragment.html index 569f5ee..bf866d2 100644 --- a/src/main/resources/templates/grants/fragments/grantStatusFragment.html +++ b/src/main/resources/templates/grants/fragments/grantStatusFragment.html @@ -25,7 +25,7 @@
- + \ No newline at end of file diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 10d21e0..04a86a7 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -191,6 +191,7 @@
+
diff --git a/src/main/resources/templates/papers/fragments/paperDashboardFragment.html b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html index 62d2466..48b6bae 100644 --- a/src/main/resources/templates/papers/fragments/paperDashboardFragment.html +++ b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html @@ -7,7 +7,8 @@
- +

- - + + - +
- +
- +
- +
- +
- +
- +
- +
- +
- +
\ No newline at end of file From fddc15af5a7e1331c69580c6907a4ce1aac7e14a Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 5 Jun 2019 23:14:52 +0400 Subject: [PATCH 9/9] #103 add tests for authors and description --- .../{IndexGrantTest.java => GrantTest.java} | 115 +++++++++++++----- src/test/java/grant/GrantPage.java | 45 ++++++- src/test/java/grant/GrantsPage.java | 30 ++++- 3 files changed, 154 insertions(+), 36 deletions(-) rename src/test/java/{IndexGrantTest.java => GrantTest.java} (68%) diff --git a/src/test/java/IndexGrantTest.java b/src/test/java/GrantTest.java similarity index 68% rename from src/test/java/IndexGrantTest.java rename to src/test/java/GrantTest.java index e1560a9..b824852 100644 --- a/src/test/java/IndexGrantTest.java +++ b/src/test/java/GrantTest.java @@ -10,6 +10,7 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; +import org.openqa.selenium.WebElement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -24,7 +25,7 @@ import java.util.Map; @RunWith(SpringRunner.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class IndexGrantTest extends TestTemplate { +public class GrantTest extends TestTemplate { private final Map> navigationHolder = ImmutableMap.of( new GrantsPage(), Arrays.asList("ГРАНТЫ", "/grants/grants"), new GrantPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ГРАНТА", "/grants/grant?id=0"), @@ -35,7 +36,7 @@ public class IndexGrantTest extends TestTemplate { private ApplicationProperties applicationProperties; @Test - public void createNewGrant() { + public void aCreateNewGrant() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); @@ -53,7 +54,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void createBlankGrant() { + public void bCreateBlankGrant() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); @@ -64,7 +65,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void updateGrantTitle() { + public void cUpdateGrantTitle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -79,18 +80,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void deleteGrant() throws InterruptedException { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); - - Integer size = grantsPage.getGrantsList().size(); - grantsPage.deleteFirst(); - Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); - } - - @Test - public void attachPaper() { + public void dAttachPaper() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -103,7 +93,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void deletePaper() { + public void eDeletePaper() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -119,7 +109,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void addDeadline() { + public void fAddDeadline() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -130,8 +120,8 @@ public class IndexGrantTest extends TestTemplate { Integer deadlineCount = grantPage.getDeadlineCount(); String description = "deadline test"; - String date = "09.09.2019"; - String dateValue = "2019-09-09"; + String date = "08.08.2019"; + String dateValue = "2019-08-08"; grantPage.addDeadline(); grantPage.setDeadline(date, deadlineCount, description); grantPage.saveGrant(); @@ -142,7 +132,7 @@ public class IndexGrantTest extends TestTemplate { } @Test - public void deleteDeadline() { + public void gDeleteDeadline() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); @@ -152,16 +142,6 @@ public class IndexGrantTest extends TestTemplate { 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(); @@ -169,4 +149,77 @@ public class IndexGrantTest extends TestTemplate { Integer newDeadlineCount = grantPage.getDeadlineCount(); Assert.assertEquals(deadlineCount - 1, (int) newDeadlineCount); } + + @Test + public void hAddAuthor() { + 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()); + + WebElement grant = grantsPage.getFirstGrantWithoutClick(); + String grantTitle = grantsPage.getGrantTitle(grant); + Integer authorsCount = grantsPage.getAuthorsCount(grant); + + grantsPage.getFirstGrant(); + grantPage.addAuthor(); + grantPage.saveGrant(); + + grant = grantsPage.getGrantByTitle(grantTitle); + Integer newAuthorsCount = grantsPage.getAuthorsCount(grant); + + Assert.assertEquals(authorsCount + 1, (int) newAuthorsCount); + } + + @Test + public void iDeleteAuthor() { + 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()); + + WebElement grant = grantsPage.getFirstGrantWithoutClick(); + String grantTitle = grantsPage.getGrantTitle(grant); + Integer authorsCount = grantsPage.getAuthorsCount(grant); + + grantsPage.getFirstGrant(); + grantPage.deleteAuthor(); + grantPage.saveGrant(); + + grant = grantsPage.getGrantByTitle(grantTitle); + Integer newAuthorsCount = grantsPage.getAuthorsCount(grant); + + authorsCount = (authorsCount == 0) ? 0 : authorsCount - 1; + + Assert.assertEquals((int) authorsCount, (int) newAuthorsCount); + } + + @Test + public void jUpdateGrantDescription() { + 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()); + + String description = "newDescriptionForGrant"; + grantsPage.getFirstGrant(); + String grantId = grantPage.getId(); + grantPage.setDescription(description); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + + Assert.assertTrue(description.equals(grantPage.getDescription())); + } + + @Test + public void kDeleteGrant() throws InterruptedException { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + + Integer size = grantsPage.getGrantsList().size(); + grantsPage.deleteFirst(); + Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); + } } diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java index 9fd1986..fe13956 100644 --- a/src/test/java/grant/GrantPage.java +++ b/src/test/java/grant/GrantPage.java @@ -42,10 +42,7 @@ public class GrantPage extends PageObject { } public boolean checkBlankFields() { - if (driver.findElements(By.className("alert-danger")).size() > 0) { - return true; - } - return false; + return driver.findElements(By.className("alert-danger")).size() > 0; } public List getAttachedPapers() { @@ -109,4 +106,44 @@ public class GrantPage extends PageObject { public void deleteDeadline() { driver.findElements(By.className("btn-delete-deadline")).get(0).click(); } + + public List addAuthor() { + WebElement selectAuthors = driver.findElement(By.id("authors")); + Select select = new Select(selectAuthors); + List selectedOptions = select.getAllSelectedOptions(); + List allOptions = select.getOptions(); + int i = 0; + while (i < selectedOptions.size()) { + if (!allOptions.get(i).equals(selectedOptions.get(i))) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + return selectedOptions; + } else { + i++; + } + } + if (selectedOptions.size() != allOptions.size()) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + } + return selectedOptions; + } + + public void deleteAuthor() { + WebElement selectAuthors = driver.findElement(By.id("authors")); + Select select = new Select(selectAuthors); + List selectedOptions = select.getAllSelectedOptions(); + if (selectedOptions.size() != 0) { + select.deselectByVisibleText(selectedOptions.get(0).getText()); + } + } + + public void setDescription(String description) { + driver.findElement(By.id("comment")).clear(); + driver.findElement(By.id("comment")).sendKeys(description); + } + + public String getDescription() { + return driver.findElement(By.id("comment")).getText(); + } } diff --git a/src/test/java/grant/GrantsPage.java b/src/test/java/grant/GrantsPage.java index 68f50db..33c388d 100644 --- a/src/test/java/grant/GrantsPage.java +++ b/src/test/java/grant/GrantsPage.java @@ -13,12 +13,13 @@ public class GrantsPage extends PageObject { } public List getGrantsList() { - return driver.findElements(By.cssSelector("span.h6")); + return driver.findElements(By.className("grant-row")); } public boolean findGrantByTitle(String grantTitle) { return getGrantsList() .stream() + .map(el -> el.findElement(By.cssSelector("span.h6"))) .anyMatch(webElement -> webElement.getText().equals(grantTitle)); } @@ -35,4 +36,31 @@ public class GrantsPage extends PageObject { public void getFirstGrant() { driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[1]")).click(); } + + public WebElement getFirstGrantWithoutClick() { + return driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]")); + } + + public String getGrantTitle(WebElement webElement) { + return webElement.findElement(By.cssSelector("span.h6")).getText(); + } + + public WebElement getGrantByTitle(String title) { + List list = getGrantsList(); + for (int i = 0; i < list.size(); i++) { + if (getGrantTitle(list.get(i)).equals(title)) { + return list.get(i); + } + } + return null; + } + + public Integer getAuthorsCount(WebElement webElement) { + String authors = webElement.findElement(By.className("text-muted")).getText(); + if (!authors.equals("")) { + String[] mas = authors.split(","); + return mas.length; + } + return 0; + } }