Skip to content

Commit

Permalink
PRSD-649: Landlord Search Page Integration Tests (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
isobel-softwire authored Jan 14, 2025
1 parent 1464fa6 commit 5e1cb39
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 23 deletions.
46 changes: 24 additions & 22 deletions src/main/resources/templates/searchLandlord.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@ <h1 class="govuk-heading-l" th:text="#{landlordSearch.heading}">landlordSearch.h
<th:block th:replace="~{fragments/searchBar :: searchBar(
#{landlordSearch.searchBar.label}, #{landlordSearch.searchBar.hint}, ${searchWrapperModel})}">
</th:block>
<h2 class="govuk-heading-m" th:text="#{landlordSearch.table.heading}">landlordSearch.table.heading</h2>
<table th:if="${searchResults != null}" th:replace="~{fragments/tables/table :: table(
${ {'landlordSearch.table.heading.landlord','landlordSearch.table.heading.address','landlordSearch.table.heading.info'} },
~{::tbody}
)}">
<tbody class="govuk-table__body">
<tr class="govuk_table__row" th:each="landlord: ${searchResults}">
<td class="govuk-table__cell">
<a class="govuk-link" th:href="@{${baseLandlordDetailsURL + '/' + landlord.id}}"
th:text="${landlord.name}"></a>
<br>
<span th:remove="tag" th:text="${landlord.registrationNumber}"></span>
</td>
<td class="govuk-table__cell" th:text="${landlord.contactAddress}"></td>
<td class="govuk-table__cell">
<span th:remove="tag" th:text="${landlord.phoneNumber}"></span>
<br>
<span th:remove="tag" th:text="${landlord.email}"></span>
</td>
</tr>
</tbody>
</table>
<th:block th:if="${searchResults != null}">
<h2 class="govuk-heading-m" th:text="#{landlordSearch.table.heading}">landlordSearch.table.heading</h2>
<table th:replace="~{fragments/tables/table :: table(
${ {'landlordSearch.table.heading.landlord','landlordSearch.table.heading.address','landlordSearch.table.heading.info'} },
~{::tbody}
)}">
<tbody class="govuk-table__body">
<tr class="govuk_table__row" th:each="landlord: ${searchResults}">
<td class="govuk-table__cell">
<a class="govuk-link" th:href="@{${baseLandlordDetailsURL + '/' + landlord.id}}"
th:text="${landlord.name}"></a>
<br>
<span th:remove="tag" th:text="${landlord.registrationNumber}"></span>
</td>
<td class="govuk-table__cell" th:text="${landlord.contactAddress}"></td>
<td class="govuk-table__cell">
<span th:remove="tag" th:text="${landlord.phoneNumber}"></span>
<br>
<span th:remove="tag" th:text="${landlord.email}"></span>
</td>
</tr>
</tbody>
</table>
</th:block>
<details id="details-content"
th:replace="~{fragments/details :: details(#{landlordSearch.details.heading},~{::#details-content/content()})}">
<div class="govuk-details__text" th:text="#{landlordSearch.details.body}">landlordSearch.details.body</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AssertionFailedError> { searchLandlordRegisterPage.getResultTable() }
assertContains(exception.message!!, "Expected 1 instance of [email protected], 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\n[email protected]")
}

@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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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<String, Any?>(
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
57 changes: 57 additions & 0 deletions src/test/resources/data-landlord-search.sql
Original file line number Diff line number Diff line change
@@ -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', '[email protected]', '09/13/24', '09/13/24'),
('urn:fdc:gov.uk:2022:FGHIJ', 'Anne Other', '[email protected]', '09/13/24', '09/13/24'),
('urn:fdc:gov.uk:2022:KLMNO', 'Ford Prefect', '[email protected]', '10/07/24', '10/07/24'),
('urn:fdc:gov.uk:2022:UVWXY', 'Mock User', '[email protected]', '10/14/24', '10/14/24'),
('urn:fdc:gov.uk:2022:PQRST', 'Arthur Dent', '[email protected]', '10/09/24', '10/09/24'),
('urn:fdc:gov.uk:2022:07lXHJeQwE0k5PZO7w_PQF425vT8T7e63MrvyPYNSoI', 'Jasmin Conterio',
'[email protected]', '10/07/24', '10/07/24'),
('urn:fdc:gov.uk:2022:mwfvbb5GgiDh0acjz9EDDQ7zwskWZzUSnWfavL70f6s', 'Isobel Ibironke',
'[email protected]', '10/02/24', '10/02/24'),
('urn:fdc:gov.uk:2022:mGHDySEVfCsvfvc6lVWf6Qt9Dv0ZxPQWKoEzcjnBlUo', 'PRSDB Landlord',
'[email protected]', '10/15/24', '10/15/24'),
('urn:fdc:gov.uk:2022:n93slCXHsxJ9rU6-AFM0jFIctYQjYf0KN9YVuJT-cao', 'PRSDB LA Admin',
'[email protected]', '10/15/24', '10/15/24'),
('urn:fdc:gov.uk:2022:cgVX2oJWKHMwzm8Gzx25CSoVXixVS0rw32Sar4Om8vQ', 'PRSDB La User',
'[email protected]', '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', '[email protected]');

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', '[email protected]'),
(2, '09/13/24', '09/13/24', 2, 2, '08/13/2001', true, 07111111111, 'urn:fdc:gov.uk:2022:ABCDE',
'Alexandra Davies', '[email protected]'),
(3, '09/13/24', '09/13/24', 3, 3, '07/13/1997', true, 07111111111, 'urn:fdc:gov.uk:2022:PQRST',
'Evan Alexandrescu', '[email protected]'),
(4, '09/13/24', '09/13/24', 4, 4, '06/13/1989', true, 07111111111,
'urn:fdc:gov.uk:2022:07lXHJeQwE0k5PZO7w_PQF425vT8T7e63MrvyPYNSoI', 'Tobias Evans', '[email protected]'),
(5, '09/13/24', '09/13/24', 5, 5, '05/13/1950', true, 07111111111,
'urn:fdc:gov.uk:2022:mwfvbb5GgiDh0acjz9EDDQ7zwskWZzUSnWfavL70f6s', 'Margaret Mary Smith',
'[email protected]'),
(6, '12/19/24', '12/19/24', 7, 5, '06/13/1989', true, 07111111111,
'urn:fdc:gov.uk:2022:mGHDySEVfCsvfvc6lVWf6Qt9Dv0ZxPQWKoEzcjnBlUo', 'PRSDB Landlord',
'[email protected]');

0 comments on commit 5e1cb39

Please sign in to comment.