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