From 5e1cb3976fd0f7d8b6199056f0dee39552d25489 Mon Sep 17 00:00:00 2001 From: Isobel Ibironke Date: Tue, 14 Jan 2025 14:20:26 +0000 Subject: [PATCH] PRSD-649: Landlord Search Page Integration Tests (#136) --- .../resources/templates/searchLandlord.html | 46 +++++++------- .../webapp/integration/SearchRegisterTests.kt | 63 +++++++++++++++++++ .../integration/pageObjects/Navigator.kt | 8 ++- .../pageObjects/components/SearchBar.kt | 17 +++++ .../pages/SearchLandlordRegisterPage.kt | 23 +++++++ src/test/resources/data-landlord-search.sql | 57 +++++++++++++++++ 6 files changed, 191 insertions(+), 23 deletions(-) create mode 100644 src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/SearchRegisterTests.kt create mode 100644 src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/components/SearchBar.kt create mode 100644 src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/pages/SearchLandlordRegisterPage.kt create mode 100644 src/test/resources/data-landlord-search.sql diff --git a/src/main/resources/templates/searchLandlord.html b/src/main/resources/templates/searchLandlord.html index c3866186..e3a05c64 100644 --- a/src/main/resources/templates/searchLandlord.html +++ b/src/main/resources/templates/searchLandlord.html @@ -9,28 +9,30 @@

landlordSearch.h -

landlordSearch.table.heading

- - - - - - - - -
- -
- -
- -
- -
+ +

landlordSearch.table.heading

+ + + + + + + + +
+ +
+ +
+ +
+ +
+
landlordSearch.details.body
diff --git a/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/SearchRegisterTests.kt b/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/SearchRegisterTests.kt new file mode 100644 index 00000000..73dac370 --- /dev/null +++ b/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/SearchRegisterTests.kt @@ -0,0 +1,63 @@ +package uk.gov.communities.prsdb.webapp.integration + +import com.microsoft.playwright.Page +import com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.opentest4j.AssertionFailedError +import org.springframework.test.context.jdbc.Sql +import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.ErrorPage +import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.SearchLandlordRegisterPage.Companion.ADDRESS_COL_INDEX +import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.SearchLandlordRegisterPage.Companion.CONTACT_INFO_COL_INDEX +import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.SearchLandlordRegisterPage.Companion.LANDLORD_COL_INDEX +import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.basePages.BasePage.Companion.assertPageIs +import kotlin.test.assertContains + +@Sql("/data-landlord-search.sql") +class SearchRegisterTests : IntegrationTest() { + @Test + fun `results table does not show before search has been requested`() { + val searchLandlordRegisterPage = navigator.goToSearchLandlordRegister() + + val exception = assertThrows { searchLandlordRegisterPage.getResultTable() } + assertContains(exception.message!!, "Expected 1 instance of Locator@.govuk-table, found 0") + } + + @Test + fun `results table shows after search has been requested`() { + val searchLandlordRegisterPage = navigator.goToSearchLandlordRegister() + searchLandlordRegisterPage.searchBar.search("L-CKSQ-3SX9") + val resultTable = searchLandlordRegisterPage.getResultTable() + + assertThat(resultTable.getHeaderCell(LANDLORD_COL_INDEX)).containsText("Landlord") + assertThat(resultTable.getCell(0, LANDLORD_COL_INDEX)).containsText("Alexander Smith\nL-CKSQ-3SX9") + + assertThat(resultTable.getHeaderCell(ADDRESS_COL_INDEX)).containsText("Contact address") + assertThat(resultTable.getCell(0, ADDRESS_COL_INDEX)).containsText("1 Fictional Road") + + assertThat(resultTable.getHeaderCell(CONTACT_INFO_COL_INDEX)).containsText("Contact information") + assertThat(resultTable.getCell(0, CONTACT_INFO_COL_INDEX)).containsText("7111111111\nalex.surname@example.com") + } + + @Test + fun `fuzzy search functionality works`() { + val searchLandlordRegisterPage = navigator.goToSearchLandlordRegister() + searchLandlordRegisterPage.searchBar.search("Alex") + val resultTable = searchLandlordRegisterPage.getResultTable() + + assertThat(resultTable.getCell(0, LANDLORD_COL_INDEX)).containsText("Alexander Smith") + assertThat(resultTable.getCell(1, LANDLORD_COL_INDEX)).containsText("Alexandra Davies") + assertThat(resultTable.getCell(2, LANDLORD_COL_INDEX)).containsText("Evan Alexandrescu") + } + + @Test + fun `landlord links goes to landlord details page`(page: Page) { + val searchLandlordRegisterPage = navigator.goToSearchLandlordRegister() + searchLandlordRegisterPage.searchBar.search("L-CKSQ-3SX9") + searchLandlordRegisterPage.getLandlordLink(rowIndex = 0).click() + + // TODO PRSD-656: Replace with landlord details page assertion + assertPageIs(page, ErrorPage::class) + assertContains(page.url(), "/landlord-details/1") + } +} diff --git a/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/Navigator.kt b/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/Navigator.kt index f17a2fdb..306b3150 100644 --- a/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/Navigator.kt +++ b/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/Navigator.kt @@ -14,6 +14,7 @@ import uk.gov.communities.prsdb.webapp.forms.steps.LandlordRegistrationStepId import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.ErrorPage import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.InviteNewLaUserPage import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.ManageLaUsersPage +import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.SearchLandlordRegisterPage import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.basePages.BasePage.Companion.createValidPage import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.laUserRegistrationJourneyPages.CheckAnswersPageLaUserRegistration import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.laUserRegistrationJourneyPages.EmailFormPageLaUserRegistration @@ -62,7 +63,7 @@ class Navigator( private val identityService: OneLoginIdentityService, ) { fun goToManageLaUsers(authorityId: Int): ManageLaUsersPage { - navigate("local-authority/$authorityId/manage-users")?.url() + navigate("local-authority/$authorityId/manage-users") return createValidPage(page, ManageLaUsersPage::class) } @@ -71,6 +72,11 @@ class Navigator( return createValidPage(page, InviteNewLaUserPage::class) } + fun goToSearchLandlordRegister(): SearchLandlordRegisterPage { + navigate("search/landlord") + return createValidPage(page, SearchLandlordRegisterPage::class) + } + fun goToLandlordRegistrationConfirmIdentityFormPage(): ConfirmIdentityFormPageLandlordRegistration { val verifiedIdentityMap = mutableMapOf( diff --git a/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/components/SearchBar.kt b/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/components/SearchBar.kt new file mode 100644 index 00000000..d31bdb88 --- /dev/null +++ b/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/components/SearchBar.kt @@ -0,0 +1,17 @@ +package uk.gov.communities.prsdb.webapp.integration.pageObjects.components + +import com.microsoft.playwright.Locator +import com.microsoft.playwright.Page + +class SearchBar( + private val page: Page, + locator: Locator = page.locator(".moj-search"), +) : BaseComponent(locator) { + private val form = Form(page) + private val searchInput = form.getTextInput() + + fun search(query: String) { + searchInput.fill(query) + form.submit() + } +} diff --git a/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/pages/SearchLandlordRegisterPage.kt b/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/pages/SearchLandlordRegisterPage.kt new file mode 100644 index 00000000..482056c5 --- /dev/null +++ b/src/test/kotlin/uk/gov/communities/prsdb/webapp/integration/pageObjects/pages/SearchLandlordRegisterPage.kt @@ -0,0 +1,23 @@ +package uk.gov.communities.prsdb.webapp.integration.pageObjects.pages + +import com.microsoft.playwright.Page +import uk.gov.communities.prsdb.webapp.integration.pageObjects.components.BaseComponent.Companion.getChildComponent +import uk.gov.communities.prsdb.webapp.integration.pageObjects.components.SearchBar +import uk.gov.communities.prsdb.webapp.integration.pageObjects.components.Table +import uk.gov.communities.prsdb.webapp.integration.pageObjects.pages.basePages.BasePage + +class SearchLandlordRegisterPage( + page: Page, +) : BasePage(page, "/search/landlord") { + val searchBar = SearchBar(page) + + fun getResultTable() = Table(page) + + fun getLandlordLink(rowIndex: Int) = getChildComponent(getResultTable().getCell(rowIndex, LANDLORD_COL_INDEX), "a") + + companion object { + const val LANDLORD_COL_INDEX: Int = 0 + const val ADDRESS_COL_INDEX: Int = 1 + const val CONTACT_INFO_COL_INDEX: Int = 2 + } +} diff --git a/src/test/resources/data-landlord-search.sql b/src/test/resources/data-landlord-search.sql new file mode 100644 index 00000000..d7904ec6 --- /dev/null +++ b/src/test/resources/data-landlord-search.sql @@ -0,0 +1,57 @@ +INSERT INTO one_login_user (id, name, email, created_date, last_modified_date) +VALUES ('urn:fdc:gov.uk:2022:ABCDE', 'Bob T Builder', 'bobthebuilder@gmail.com', '09/13/24', '09/13/24'), + ('urn:fdc:gov.uk:2022:FGHIJ', 'Anne Other', 'Anne.Other@hotmail.com', '09/13/24', '09/13/24'), + ('urn:fdc:gov.uk:2022:KLMNO', 'Ford Prefect', 'Ford.Prefect@hotmail.com', '10/07/24', '10/07/24'), + ('urn:fdc:gov.uk:2022:UVWXY', 'Mock User', 'test@example.com', '10/14/24', '10/14/24'), + ('urn:fdc:gov.uk:2022:PQRST', 'Arthur Dent', 'Arthur.Dent@hotmail.com', '10/09/24', '10/09/24'), + ('urn:fdc:gov.uk:2022:07lXHJeQwE0k5PZO7w_PQF425vT8T7e63MrvyPYNSoI', 'Jasmin Conterio', + 'jasmin.conterio@softwire.com', '10/07/24', '10/07/24'), + ('urn:fdc:gov.uk:2022:mwfvbb5GgiDh0acjz9EDDQ7zwskWZzUSnWfavL70f6s', 'Isobel Ibironke', + 'isobel.ibironke@softwire.com', '10/02/24', '10/02/24'), + ('urn:fdc:gov.uk:2022:mGHDySEVfCsvfvc6lVWf6Qt9Dv0ZxPQWKoEzcjnBlUo', 'PRSDB Landlord', + 'Team-PRSDB+landlord@softwire.com', '10/15/24', '10/15/24'), + ('urn:fdc:gov.uk:2022:n93slCXHsxJ9rU6-AFM0jFIctYQjYf0KN9YVuJT-cao', 'PRSDB LA Admin', + 'Team-PRSDB+laadmin@softwire.com', '10/15/24', '10/15/24'), + ('urn:fdc:gov.uk:2022:cgVX2oJWKHMwzm8Gzx25CSoVXixVS0rw32Sar4Om8vQ', 'PRSDB La User', + 'Team-PRSDB+lauser@softwire.com', '10/15/24', '10/15/24'); + +INSERT INTO local_authority (id, name, created_date, last_modified_date) +VALUES (1, 'Betelgeuse', '09/13/24', '09/13/24'); + +INSERT INTO local_authority_user (subject_identifier, is_manager, local_authority_id, created_date, last_modified_date, + name, email) +VALUES ('urn:fdc:gov.uk:2022:UVWXY', true, 1, '10/14/24', '10/14/24', 'Mock User', 'test@la.com'); + +INSERT INTO registration_number (id, created_date, number, type) +VALUES (1, '09/13/24', 2001001001, 1), + (2, '09/13/24', 3002001002, 1), + (3, '10/07/24', 4003001003, 1), + (4, '10/14/24', 5004001004, 1), + (5, '10/09/24', 6005001005, 1), + (6, '12/10/24', 7006001006, 0), + (7, '12/19/24', 8005001005, 1); + +INSERT INTO address (id, created_date, last_modified_date, uprn, single_line_address) +VALUES (1, '09/13/24', '09/13/24', 1, '1 Fictional Road'), + (2, '09/13/24', '09/13/24', 2, '2 Fake Way'), + (3, '09/13/24', '09/13/24', 3, '3 Imaginary Street'), + (4, '09/13/24', '09/13/24', 4, '4 Pretend Crescent'), + (5, '09/13/24', '09/13/24', 5, '5 Mythical Place'), + (6, '12/10/2024', '12/10/2024', 1123456, '1, Example Road, EG'); + +INSERT INTO landlord (id, created_date, last_modified_date, registration_number_id, address_id, date_of_birth, + is_active, phone_number, subject_identifier, name, email) +VALUES (1, '09/13/24', '09/13/24', 1, 1, '09/13/2000', true, 07111111111, 'urn:fdc:gov.uk:2022:UVWXY', + 'Alexander Smith', 'alex.surname@example.com'), + (2, '09/13/24', '09/13/24', 2, 2, '08/13/2001', true, 07111111111, 'urn:fdc:gov.uk:2022:ABCDE', + 'Alexandra Davies', 'alexandra.q.davies@example.com'), + (3, '09/13/24', '09/13/24', 3, 3, '07/13/1997', true, 07111111111, 'urn:fdc:gov.uk:2022:PQRST', + 'Evan Alexandrescu', 'unrelatedemail@completelydifferentdomain.com'), + (4, '09/13/24', '09/13/24', 4, 4, '06/13/1989', true, 07111111111, + 'urn:fdc:gov.uk:2022:07lXHJeQwE0k5PZO7w_PQF425vT8T7e63MrvyPYNSoI', 'Tobias Evans', 'tobyevans@importantco.com'), + (5, '09/13/24', '09/13/24', 5, 5, '05/13/1950', true, 07111111111, + 'urn:fdc:gov.uk:2022:mwfvbb5GgiDh0acjz9EDDQ7zwskWZzUSnWfavL70f6s', 'Margaret Mary Smith', + 'mm.smith@importantco.com'), + (6, '12/19/24', '12/19/24', 7, 5, '06/13/1989', true, 07111111111, + 'urn:fdc:gov.uk:2022:mGHDySEVfCsvfvc6lVWf6Qt9Dv0ZxPQWKoEzcjnBlUo', 'PRSDB Landlord', + 'Team-PRSDB+landlord@softwire.com'); \ No newline at end of file