From d73b576b8c1f372206bd404c5ea65b94b8f513b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 9 Sep 2017 10:32:37 +0200 Subject: [PATCH] Add test for edit profile field ajax page --- .../sone/web/ajax/EditProfileFieldAjaxPageTest.kt | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPageTest.kt 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 + } + +} -- 2.7.4