From 6edcf8f5940fa3b3c0a0179d6910189412b8d230 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 21:15:49 +0400 Subject: [PATCH] #103 add sort and filter test, fixed delete conference, if it has fk with event --- .../conference/service/ConferenceService.java | 1 + .../ulstu/timeline/service/EventService.java | 5 ++ src/test/java/IndexConferenceTest.java | 57 +++++++++++++++---- src/test/java/conference/ConferencePage.java | 15 +++-- src/test/java/conference/ConferencesPage.java | 10 ++++ 5 files changed, 71 insertions(+), 17 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 38de435..e0662a2 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -127,6 +127,7 @@ public class ConferenceService { @Transactional public void delete(Integer conferenceId) { if (conferenceRepository.exists(conferenceId)) { + eventService.removeConferencesEvent(conferenceRepository.findOne(conferenceId)); conferenceRepository.delete(conferenceId); } } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index b935f16..cd56a52 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -203,4 +203,9 @@ public class EventService { eventRepository.delete(eventRepository.findAllByGrant(grant)); createFromGrant(grant); } + + public void removeConferencesEvent(Conference conference) { + List eventList = eventRepository.findAllByConference(conference); + eventList.forEach(event -> eventRepository.delete(event.getId())); + } } diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index b3314ff..47af27f 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -159,22 +159,22 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getPaperCount(); + Integer paperCount = conferencePage.getArticlesCount(); conferencePage.showAllowToAttachArticles(); - WebElement paper = conferencePage.selectPaper(); + WebElement paper = conferencePage.selectArticle(); String paperName = paper.findElement(By.className("text")).getText(); conferencePage.clickSaveBut(); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(paperCount + 1 == conferencePage.getPaperCount() - && conferencePage.getPapers() + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.getArticles() .stream() .anyMatch(webElement -> webElement - .findElement(By.className("paper-name")) - .findElements(By.tagName("span")) - .get(1).getText().equals(paperName))); + .findElements(By.tagName("input")) + .get(1).getAttribute("value") + .equals(paperName))); } @Test @@ -187,17 +187,17 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getPaperCount(); + Integer paperCount = conferencePage.getArticlesCount(); conferencePage.clickAddPaperBut(); - List webElements = conferencePage.getPapers(); + List webElements = conferencePage.getArticles(); String paperName = webElements.get(webElements.size() - 1).findElements(By.tagName("input")).get(1).getAttribute("value"); conferencePage.clickSaveBut(); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(paperCount + 1 == conferencePage.getPaperCount() - && conferencePage.getPapers() + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.getArticles() .stream() .anyMatch(webElement -> webElement .findElements(By.tagName("input")) @@ -215,11 +215,44 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); - WebElement paper = conferencePage.getPapers().get(0); + WebElement paper = conferencePage.getArticles().get(0); String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); paper.findElement(By.tagName("a")).click(); Assertions.assertThat(conferencePage.getName()) .isEqualTo(paperName); } + + @Test + public void testUndockArticle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getArticlesCount(); + + conferencePage.clickUndockArticleBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(paperCount - 1 == conferencePage.getArticlesCount()); + } + + @Test + public void testSortAndFilterConferenceList() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + + conferencesPage.selectMember(); + conferencesPage.selectYear(); + + Assert.assertEquals(1, conferencesPage.getConferencesList().size()); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 1a4a1df..50e545e 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -72,21 +72,26 @@ public class ConferencePage extends PageObject { driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click(); } - public List getPapers() { + public void clickAddPaperBut() { + driver.findElement(By.id("add-paper")).click(); + } + + + public List getArticles() { return driver.findElements(By.className("paper")); } - public Integer getPaperCount() { + public Integer getArticlesCount() { return driver.findElements(By.className("paper")).size(); } - public WebElement selectPaper() { + public WebElement selectArticle() { WebElement webElement = driver.findElement(By.xpath("//*[@id=\"conference-form\"]/div/div[2]/div[5]/div/div/div[2]/ul/li[1]/a")); webElement.click(); return webElement; } - public void clickAddPaperBut() { - driver.findElement(By.id("add-paper")).click(); + public void clickUndockArticleBut() { + driver.findElement(By.name("removePaper")).click(); } } \ No newline at end of file diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index b258420..795ccf3 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -19,4 +19,14 @@ public class ConferencesPage extends PageObject { public void getConferenceFirst() { driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/a")).click(); } + + public void selectMember() { + driver.findElements(By.className("bootstrap-select")).get(0).findElement(By.className("btn")).click(); + driver.findElements(By.className("bootstrap-select")).get(0).findElements(By.className("dropdown-item")).get(1).click(); + } + + public void selectYear() { + driver.findElements(By.className("bootstrap-select")).get(1).findElement(By.className("btn")).click(); + driver.findElements(By.className("bootstrap-select")).get(1).findElements(By.className("dropdown-item")).get(1).click(); + } } \ No newline at end of file