diff options
-rw-r--r-- | juick-core/src/test/java/com/juick/test/util/MockUtils.java | 8 | ||||
-rw-r--r-- | juick-www/src/test/java/com/juick/www/WebAppTests.java | 32 |
2 files changed, 40 insertions, 0 deletions
diff --git a/juick-core/src/test/java/com/juick/test/util/MockUtils.java b/juick-core/src/test/java/com/juick/test/util/MockUtils.java index 72204cfe..8426cde8 100644 --- a/juick-core/src/test/java/com/juick/test/util/MockUtils.java +++ b/juick-core/src/test/java/com/juick/test/util/MockUtils.java @@ -38,6 +38,14 @@ public class MockUtils { return msg; } + public static Message mockReply(Integer mid, Integer rid, final User user, Integer replyTo, final String messageText) { + Message msg = mockMessage(mid, user, messageText); + + msg.setRid(rid); + msg.setReplyto(replyTo); + return msg; + } + public static User mockUser(final int uid, final String name, final String password) { User user = new User(); 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<Message> 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)); + + } } |