1 package net.pterodactylus.sone.web
3 import net.pterodactylus.sone.data.Album
4 import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty
5 import net.pterodactylus.sone.data.Sone
6 import net.pterodactylus.sone.test.mock
7 import net.pterodactylus.sone.test.mockBuilder
8 import net.pterodactylus.sone.test.whenever
9 import net.pterodactylus.util.web.Method.GET
10 import net.pterodactylus.util.web.Method.POST
11 import org.junit.Before
13 import org.mockito.Mockito.verify
16 * Unit test for [EditAlbumPage].
18 class EditAlbumPageTest : WebPageTest() {
20 private val page = EditAlbumPage(template, webInterface)
22 private val album = mock<Album>()
23 private val parentAlbum = mock<Album>()
24 private val modifier = mockBuilder<Album.Modifier>()
25 private val sone = mock<Sone>()
27 override fun getPage() = page
31 whenever(album.id).thenReturn("album-id")
32 whenever(album.sone).thenReturn(sone)
33 whenever(album.parent).thenReturn(parentAlbum)
34 whenever(album.modify()).thenReturn(modifier)
35 whenever(modifier.update()).thenReturn(album)
36 whenever(parentAlbum.id).thenReturn("parent-id")
37 whenever(sone.isLocal).thenReturn(true)
38 addHttpRequestHeader("Host", "www.te.st")
42 fun `get request does not redirect`() {
44 page.handleRequest(freenetRequest, templateContext)
48 fun `post request with invalid album redirects to invalid page`() {
50 verifyRedirect("invalid.html")
54 fun `post request with album of non-local sone redirects to no permissions page`() {
56 whenever(sone.isLocal).thenReturn(false)
57 addAlbum("album-id", album)
58 addHttpRequestParameter("album", "album-id")
59 verifyRedirect("noPermission.html")
63 fun `post request with move left requested moves album to the left and redirects to album browser`() {
65 addAlbum("album-id", album)
66 addHttpRequestParameter("album", "album-id")
67 addHttpRequestParameter("moveLeft", "true")
68 verifyRedirect("imageBrowser.html?album=parent-id") {
69 verify(parentAlbum).moveAlbumUp(album)
70 verify(core).touchConfiguration()
75 fun `post request with move right requested moves album to the left and redirects to album browser`() {
77 addAlbum("album-id", album)
78 addHttpRequestParameter("album", "album-id")
79 addHttpRequestParameter("moveRight", "true")
80 verifyRedirect("imageBrowser.html?album=parent-id") {
81 verify(parentAlbum).moveAlbumDown(album)
82 verify(core).touchConfiguration()
87 fun `post request with empty album title redirects to empty album title page`() {
89 addAlbum("album-id", album)
90 addHttpRequestParameter("album", "album-id")
91 whenever(modifier.setTitle("")).thenThrow(AlbumTitleMustNotBeEmpty())
92 verifyRedirect("emptyAlbumTitle.html")
96 fun `post request with non-empty album title and description redirects to album browser`() {
98 addAlbum("album-id", album)
99 addHttpRequestParameter("album", "album-id")
100 addHttpRequestParameter("title", "title")
101 addHttpRequestParameter("description", "description")
102 verifyRedirect("imageBrowser.html?album=album-id") {
103 verify(modifier).setTitle("title")
104 verify(modifier).setDescription("description")
105 verify(modifier).update()
106 verify(core).touchConfiguration()