1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.data.Album.*
5 import net.pterodactylus.sone.data.Album.Modifier.*
6 import net.pterodactylus.sone.test.*
7 import net.pterodactylus.sone.web.*
8 import net.pterodactylus.util.web.Method.*
9 import org.hamcrest.MatcherAssert.*
10 import org.hamcrest.Matchers.*
12 import org.mockito.Mockito.*
15 * Unit test for [EditAlbumPage].
17 class EditAlbumPageTest : WebPageTest(::EditAlbumPage) {
19 private val album = mock<Album>()
20 private val parentAlbum = mock<Album>()
21 private val modifier = mockBuilder<Modifier>()
22 private val sone = mock<Sone>()
26 whenever(album.id).thenReturn("album-id")
27 whenever(album.sone).thenReturn(sone)
28 whenever(album.parent).thenReturn(parentAlbum)
29 whenever(album.modify()).thenReturn(modifier)
30 whenever(modifier.update()).thenReturn(album)
31 whenever(parentAlbum.id).thenReturn("parent-id")
32 whenever(sone.isLocal).thenReturn(true)
33 addHttpRequestHeader("Host", "www.te.st")
37 fun `page returns correct path`() {
38 assertThat(page.path, equalTo("editAlbum.html"))
42 fun `page requires login`() {
43 assertThat(page.requiresLogin(), equalTo(true))
47 fun `page returns correct title`() {
48 addTranslation("Page.EditAlbum.Title", "edit album page")
49 assertThat(page.getPageTitle(soneRequest), equalTo("edit album page"))
53 fun `get request does not redirect`() {
54 page.processTemplate(freenetRequest, templateContext)
58 fun `post request with invalid album redirects to invalid page`() {
60 verifyRedirect("invalid.html")
64 fun `post request with album of non-local sone redirects to no permissions page`() {
66 whenever(sone.isLocal).thenReturn(false)
67 addAlbum("album-id", album)
68 addHttpRequestPart("album", "album-id")
69 verifyRedirect("noPermission.html")
73 fun `post request with move left requested moves album to the left and redirects to album browser`() {
75 addAlbum("album-id", album)
76 addHttpRequestPart("album", "album-id")
77 addHttpRequestPart("moveLeft", "true")
78 verifyRedirect("imageBrowser.html?album=parent-id") {
79 verify(parentAlbum).moveAlbumUp(album)
80 verify(core).touchConfiguration()
85 fun `post request with move right requested moves album to the left and redirects to album browser`() {
87 addAlbum("album-id", album)
88 addHttpRequestPart("album", "album-id")
89 addHttpRequestPart("moveRight", "true")
90 verifyRedirect("imageBrowser.html?album=parent-id") {
91 verify(parentAlbum).moveAlbumDown(album)
92 verify(core).touchConfiguration()
97 fun `post request with empty album title redirects to empty album title page`() {
99 addAlbum("album-id", album)
100 addHttpRequestPart("album", "album-id")
101 whenever(modifier.setTitle("")).thenThrow(AlbumTitleMustNotBeEmpty())
102 verifyRedirect("emptyAlbumTitle.html")
106 fun `post request with non-empty album title and description redirects to album browser`() {
108 addAlbum("album-id", album)
109 addHttpRequestPart("album", "album-id")
110 addHttpRequestPart("title", "title")
111 addHttpRequestPart("description", "description")
112 verifyRedirect("imageBrowser.html?album=album-id") {
113 verify(modifier).setTitle("title")
114 verify(modifier).setDescription("description")
115 verify(modifier).update()
116 verify(core).touchConfiguration()
121 fun `page can be created by dependency injection`() {
122 assertThat(baseInjector.getInstance<EditAlbumPage>(), notNullValue())