From 9031366d618a23237a8b7cb35ed65a8a953c48d7 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 8 Aug 2017 15:31:18 +0300 Subject: thread test --- .../src/test/java/com/juick/www/WebAppTests.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'juick-www/src/test/java/com/juick/www') diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java index 6aa55165..98df3660 100644 --- a/juick-www/src/test/java/com/juick/www/WebAppTests.java +++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java @@ -19,6 +19,7 @@ package com.juick.www; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.css.StyleElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.juick.Message; import com.juick.User; @@ -44,7 +45,11 @@ import org.springframework.web.context.WebApplicationContext; import javax.inject.Inject; import java.io.IOException; import java.util.Collections; +import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.StreamSupport; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -146,4 +151,31 @@ public class WebAppTests { assertThat(blogPage.getWebResponse().getStatusCode(), equalTo(404)); assertThat(threadPage.getWebResponse().getStatusCode(), equalTo(404)); } + @Test + public void repliesTree() throws IOException { + User ugnich = MockUtils.mockUser(1, "ugnich", "secret"); + User freefd = MockUtils.mockUser(3, "freefd", "secret"); + Message hello = MockUtils.mockMessage(1, ugnich, null); + List replies = IntStream.range(1, 15).mapToObj(i -> + MockUtils.mockReply(hello.getMid(), i, freefd, i-1, null )).collect(Collectors.toList()); + + when(userService.getUIDbyName("ugnich")).thenReturn(1); + when(userService.getUIDbyName("freefd")).thenReturn(3); + when(userService.getUserByName("ugnich")).thenReturn(ugnich); + when(userService.getUserByName("freefd")).thenReturn(freefd); + + when(messagesService.canViewThread(1, 0)).thenReturn(true); + when(messagesService.getMessage(1)).thenReturn(hello); + when(messagesService.getReplies(1)).thenReturn(replies); + + HtmlPage threadPage = webClient.getPage("http://localhost:8080/ugnich/1"); + assertThat(threadPage.getWebResponse().getStatusCode(), equalTo(200)); + Long visibleItems = StreamSupport.stream(threadPage.getHtmlElementById("replies") + .getChildElements().spliterator(), false).filter(e -> { + StyleElement display = e.getStyleElement("display"); + return display == null || !display.getValue().equals("none"); + }).count(); + assertThat(visibleItems, equalTo(1L)); + + } } -- cgit v1.2.3