package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.test.*
import net.pterodactylus.sone.web.*
import net.pterodactylus.sone.web.page.*
/**
* Unit test for [EditProfilePage].
*/
-class EditProfilePageTest: WebPageTest(::EditProfilePage) {
+class EditProfilePageTest : WebPageTest(::EditProfilePage) {
private val profile = Profile(currentSone)
private val firstField = profile.addField("First Field")
@Before
fun setupProfile() {
- val avatar = mock<Image>()
- whenever(avatar.id).thenReturn("image-id")
- whenever(avatar.sone).thenReturn(currentSone)
profile.firstName = "First"
profile.middleName = "Middle"
profile.lastName = "Last"
profile.birthDay = 31
profile.birthMonth = 12
profile.birthYear = 1999
- profile.setAvatar(avatar)
+ profile.setAvatar(ImageImpl("image-id").modify().setSone(currentSone).update())
whenever(currentSone.profile).thenReturn(profile)
}
@Test
fun `page returns correct path`() {
- assertThat(page.path, equalTo("editProfile.html"))
+ assertThat(page.path, equalTo("editProfile.html"))
}
@Test
fun `page requires login`() {
- assertThat(page.requiresLogin(), equalTo(true))
+ assertThat(page.requiresLogin(), equalTo(true))
}
@Test
fun `page returns correct title`() {
- whenever(l10n.getString("Page.EditProfile.Title")).thenReturn("edit profile page title")
+ addTranslation("Page.EditProfile.Title", "edit profile page title")
assertThat(page.getPageTitle(soneRequest), equalTo("edit profile page title"))
}
@Test
fun `post request with new avatar ID and save profile saves the profile and redirects back to profile edit page`() {
- val newAvatar = mock<Image>()
- whenever(newAvatar.sone).thenReturn(currentSone)
- whenever(newAvatar.id).thenReturn("avatar-id")
+ val newAvatar = ImageImpl("avatar-id").modify().setSone(currentSone).update()
addImage("avatar-id", newAvatar)
verifySingleFieldCanBeChanged("avatarId", "avatar-id") { profile.avatar }
}
@Test
fun `page can be created by dependency injection`() {
- assertThat(baseInjector.getInstance<EditProfilePage>(), notNullValue())
+ assertThat(baseInjector.getInstance<EditProfilePage>(), notNullValue())
}
@Test
fun `page is annotated with correct menuname`() {
- assertThat(page.menuName, equalTo("EditProfile"))
+ assertThat(page.menuName, equalTo("EditProfile"))
}
@Test
fun `page is annotated with correct template path`() {
- assertThat(page.templatePath, equalTo("/templates/editProfile.html"))
+ assertThat(page.templatePath, equalTo("/templates/editProfile.html"))
}
}