🔀 Merge branch 'release/v82'
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / DeleteProfileFieldAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.test.*
4 import net.pterodactylus.sone.web.*
5 import org.hamcrest.MatcherAssert.*
6 import org.hamcrest.Matchers.*
7 import org.junit.*
8 import org.mockito.Mockito.*
9
10 /**
11  * Unit test for [DeleteProfileFieldAjaxPage].
12  */
13 class DeleteProfileFieldAjaxPageTest : JsonPageTest("deleteProfileField.ajax", pageSupplier = ::DeleteProfileFieldAjaxPage) {
14
15         @Test
16         fun `request without field id results in invalid field id error`() {
17                 assertThatJsonFailed("invalid-field-id")
18         }
19
20         @Test
21         fun `request with valid field id results in field deletion`() {
22                 profile.addField("foo")
23                 val fieldId = profile.getFieldByName("foo")!!.id
24                 addRequestParameter("field", fieldId)
25                 assertThatJsonIsSuccessful()
26                 assertThat(profile.getFieldByName("foo"), nullValue())
27                 verify(currentSone).profile = profile
28                 verify(core).touchConfiguration()
29         }
30
31         @Test
32         fun `page can be created by dependency injection`() {
33             assertThat(baseInjector.getInstance<DeleteProfileFieldAjaxPage>(), notNullValue())
34         }
35
36 }