From: David ‘Bombe’ Roden Date: Sat, 9 Sep 2017 08:32:37 +0000 (+0200) Subject: Add test for edit profile field ajax page X-Git-Tag: 0.9.7^2~81 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d73b576b8c1f372206bd404c5ea65b94b8f513b2;p=Sone.git Add test for edit profile field ajax page --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPageTest.kt new file mode 100644 index 0000000..5116090 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPageTest.kt @@ -0,0 +1,49 @@ +package net.pterodactylus.sone.web.ajax + +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Test +import org.mockito.Mockito.verify + +/** + * Unit test for [EditProfileFieldAjaxPage]. + */ +class EditProfileFieldAjaxPageTest : JsonPageTest("editProfileField.ajax", pageSupplier = ::EditProfileFieldAjaxPage) { + + @Test + fun `request without field id results in invalid-field-id`() { + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-field-id")) + } + + @Test + fun `request with empty new name results in invalid-parameter-name`() { + val field = currentSone.profile.addField("test-field") + addRequestParameter("field", field.id) + addRequestParameter("name", " \t ") + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-parameter-name")) + } + + @Test + fun `request with duplicate new name results in duplicate-field-name`() { + currentSone.profile.addField("other-field") + val field = currentSone.profile.addField("test-field") + addRequestParameter("field", field.id) + addRequestParameter("name", "other-field") + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("duplicate-field-name")) + } + + @Test + fun `request with valid field name changes field name`() { + val profile = currentSone.profile + val field = profile.addField("test-field") + addRequestParameter("field", field.id) + addRequestParameter("name", " new name ") + assertThat(json.isSuccess, equalTo(true)) + assertThat(field.name, equalTo("new name")) + verify(currentSone).profile = profile + } + +}