From: David ‘Bombe’ Roden Date: Mon, 19 Jun 2017 09:09:36 +0000 (+0200) Subject: Convert image browser page test to use new web page test base X-Git-Tag: 0.9.7^2~136 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6d113a1ada8058fb26e82cd209b70c022fdab7ca;p=Sone.git Convert image browser page test to use new web page test base --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt index d64e475..d426845 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt @@ -13,9 +13,7 @@ import org.junit.Test /** * Unit test for [ImageBrowserPage]. */ -class ImageBrowserPageTest : WebPageTest() { - - private val page = ImageBrowserPage(template, webInterface) +class ImageBrowserPageTest: WebPageTest2(::ImageBrowserPage) { @Test fun `page returns correct path`() { @@ -39,10 +37,11 @@ class ImageBrowserPageTest : WebPageTest() { addAlbum("album-id", album) addHttpRequestParameter("album", "album-id") addHttpRequestParameter("page", "5") - page.processTemplate(freenetRequest, templateContext) - assertThat(templateContext["albumRequested"], equalTo(true)) - assertThat(templateContext["album"], equalTo(album)) - assertThat(templateContext["page"], equalTo("5")) + verifyNoRedirect { + assertThat(templateContext["albumRequested"], equalTo(true)) + assertThat(templateContext["album"], equalTo(album)) + assertThat(templateContext["page"], equalTo("5")) + } } @Test @@ -50,9 +49,10 @@ class ImageBrowserPageTest : WebPageTest() { val image = mock() addImage("image-id", image) addHttpRequestParameter("image", "image-id") - page.processTemplate(freenetRequest, templateContext) - assertThat(templateContext["imageRequested"], equalTo(true)) - assertThat(templateContext["image"], equalTo(image)) + verifyNoRedirect { + assertThat(templateContext["imageRequested"], equalTo(true)) + assertThat(templateContext["image"], equalTo(image)) + } } @Test @@ -60,9 +60,10 @@ class ImageBrowserPageTest : WebPageTest() { val sone = mock() addSone("sone-id", sone) addHttpRequestParameter("sone", "sone-id") - page.processTemplate(freenetRequest, templateContext) - assertThat(templateContext["soneRequested"], equalTo(true)) - assertThat(templateContext["sone"], equalTo(sone)) + verifyNoRedirect { + assertThat(templateContext["soneRequested"], equalTo(true)) + assertThat(templateContext["sone"], equalTo(sone)) + } } @Test @@ -72,15 +73,16 @@ class ImageBrowserPageTest : WebPageTest() { val secondSone = createSone("third album", "fourth album") addSone("sone2", secondSone) addHttpRequestParameter("mode", "gallery") - page.processTemplate(freenetRequest, templateContext) - assertThat(templateContext["galleryRequested"], equalTo(true)) - @Suppress("UNCHECKED_CAST") - assertThat(templateContext["albums"] as Iterable, contains( - firstSone.rootAlbum.albums[0], - secondSone.rootAlbum.albums[1], - firstSone.rootAlbum.albums[1], - secondSone.rootAlbum.albums[0] - )) + verifyNoRedirect { + assertThat(templateContext["galleryRequested"], equalTo(true)) + @Suppress("UNCHECKED_CAST") + assertThat(templateContext["albums"] as Iterable, contains( + firstSone.rootAlbum.albums[0], + secondSone.rootAlbum.albums[1], + firstSone.rootAlbum.albums[1], + secondSone.rootAlbum.albums[0] + )) + } } private fun createSone(firstAlbumTitle: String, secondAlbumTitle: String): Sone { @@ -101,9 +103,10 @@ class ImageBrowserPageTest : WebPageTest() { @Test fun `requesting nothing will show the albums of the current sone`() { - page.processTemplate(freenetRequest, templateContext) - assertThat(templateContext["soneRequested"], equalTo(true)) - assertThat(templateContext["sone"], equalTo(currentSone)) + verifyNoRedirect { + assertThat(templateContext["soneRequested"], equalTo(true)) + assertThat(templateContext["sone"], equalTo(currentSone)) + } } @Test