Skip to content

Commit

Permalink
Merge pull request #207 from digital-land/test/nationalMap
Browse files Browse the repository at this point in the history
National map acceptance tests
  • Loading branch information
GeorgeGoodall authored Oct 12, 2023
2 parents f8facec + b30f5b3 commit 208e6d3
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 55 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ jobs:
echo "## Accessibility Tests" >> $GITHUB_STEP_SUMMARY
cat accessibility-tests.md >> $GITHUB_STEP_SUMMARY
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

detect-environments:
runs-on: ubuntu-latest
needs: [test, lint]
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ postgresql::
sudo service postgresql start

insertBaseData::
python -c 'from tests.utils.database import reset_database; reset_database()'
python -c 'from tests.utils.database import *; add_base_entities_to_database(); add_base_datasets_to_database(); add_base_typology_to_database()'

emptyDatabase::
Expand Down
2 changes: 1 addition & 1 deletion application/templates/components/entity-value/macro.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{%- if field in ["dataset"] %}
<a class="govuk-link" href="{{ '/' + field + '/' + value }}">{{ value|replace("-", " ")|capitalize }}</a>
{%- elif field in ["geometry","point"] %}
<div class="app-code-block">{{ value }}</div>
<div class="app-code-block" tabindex="0">{{ value }}</div>
{%- elif field in ["local-resilience-forum","local-authority-type","ownership-status","planning-permission-type","planning-permission-type","planning-permission-status","green-belt-core","ancient-woodland-status","design-code-category","design-code-status","listed-building-grade","park-and-garden-grade"] %}
<a class ="govuk-link" href="{{ '/prefix/' + field + "/reference/" + value }}">{{ value }}</a>
{%- elif field in ["combined-authority","local-authority"] %}
Expand Down
4 changes: 2 additions & 2 deletions application/templates/entity.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ <h1 class="govuk-heading-xl">{{ row_name }}</h1>
{% endcall %}

{% set jsonHTML %}
<pre class="govuk-!-margin-0"><code class="language-json app-code-block app-code-block-overflow">{{row|digital_land_to_json}}</code></pre>
<pre class="govuk-!-margin-0"><code class="language-json app-code-block app-code-block-overflow" tabindex="0">{{row|digital_land_to_json}}</code></pre>
{% endset %}
{% set geojsonHTML %}
<pre class="govuk-!-margin-0"><code class="language-json app-code-block app-code-block-overflow">{{geojson|digital_land_to_json}}</code></pre>
<pre class="govuk-!-margin-0"><code class="language-json app-code-block app-code-block-overflow" tabindex="0">{{geojson|digital_land_to_json}}</code></pre>
{% endset %}

{% if geojson %}
Expand Down
2 changes: 1 addition & 1 deletion application/templates/pages/guidance/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Planning Data collects [data about a range of subjects](https://www.digital-land

There are 4 main data subjects that are needed for the RIPA service:

- [Article 4 direction data](specifications/article-4-direction)
- [Conservation area data](specifications/conservation-area)
- [Listed building data](specifications/listed-building)
- [Article 4 direction data](specifications/article-4-direction)
- [Tree preservation order data](specifications/tree-preservation-order)

We recommend publishing at least this data to benefit from RIPA and to allow developers to use it in your area.
Expand Down
2 changes: 1 addition & 1 deletion application/templates/partials/search-facets.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2 class="govuk-heading-m">Filters</h2>
{% call dlFilterGroup({
"title": "Period",
"is_open": False,
"selected": 1
"selected": query.params.get('period')|length if query.params.get('period') else 0
}) %}
{{ dlFilterCheckboxes({
"uniqueID": random_int(5),
Expand Down
12 changes: 12 additions & 0 deletions changeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
# ChangeLog
<br>

## 11-10-2023
### What's new
- Updated the map testing code to use the new map page object model
- Added commented test for the map page, to be fixed at a later date
### Why was this change made?
- because this user journey was documented as part of a recent group session we did
### Additional changes
- Added an additional entity to the test data, and fixed tests to account for this
- Fixed some accessibility issues with the entity page
- Period selected value not based of how many checkboxes checked instead of hardcoded to be 1
- Make sure datasets are in alphabetical order on the guidance pages

## 10-10-2023
### What's new
- Added an acceptance test that tests navigation to a dataset page
Expand Down
82 changes: 82 additions & 0 deletions tests/acceptance/pageObjectModels/mapPOM.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
pauseDuration = 1000


class MapPOM:
def __init__(self, page, base_url) -> None:
self.page = page
self.base_url = base_url

def navigate(self, urlParam=""):
response = self.page.goto(self.base_url + "/map/" + urlParam)
self.page.wait_for_timeout(
pauseDuration
) # wait for some time to make sure the map code has loaded
return response

def check_layer_checkbox(self, layerName):
self.page.get_by_label(layerName).check()
self.page.wait_for_timeout(
pauseDuration
) # wait for some time to make sure the data loads

def zoom_map(self, zoomLevel):
result = self.page.evaluate(
"() => {try{mapControllers.map.map.setZoom("
+ str(zoomLevel)
+ ")} catch(e){return e.message}}"
)
print(result)

def centre_map_over(self, x, y):
result = self.page.evaluate(
"() => {try{mapControllers.map.map.setCenter(["
+ str(x)
+ ","
+ str(y)
+ "])} catch(e){return e.message}}"
)
print(result)

def click_map_centre(self):
mapWidth = self.page.evaluate("() => mapControllers.map.map.getCanvas().width")
mapHeight = self.page.evaluate(
"() => mapControllers.map.map.getCanvas().height"
)
self.page.get_by_label("Map").click(
position={"x": mapWidth / 2, "y": mapHeight / 2}
)
self.page.wait_for_timeout(pauseDuration) # wait for potential popup

def wait_for_map_layer(self, layer, attempts=10, check_interval=10):
for i in range(attempts):
isHidden = self.page.evaluate(
f'() => mapControllers.map.map.getLayer("{layer}").isHidden()'
)
if isHidden is False:
return True
self.page.wait_for_timeout(check_interval)
assert False, f"Layer {layer} did not appear on the map"

def wait_for_popup(self, attempts=10, check_interval=100):
for i in range(attempts):
isHidden = (
self.page.get_by_test_id("map").locator("div.app-popup").is_hidden()
)
if isHidden is False:
return True
self.page.wait_for_timeout(check_interval)
zoom = self.page.evaluate("() => mapControllers.map.map.getZoom()")
center = self.page.evaluate("() => mapControllers.map.map.getCenter()")
assert False, f"Popup did not appear on the map as {center} at zoom {zoom}"

def wait_for_layer_controls_to_load(self, attempts=10, check_interval=500):
for i in range(attempts):
isHidden = (
self.page.get_by_test_id("map")
.locator("button.dl-map__close-btn")
.is_hidden()
)
if isHidden is False:
return True
self.page.wait_for_timeout(check_interval)
assert False, "layer controls did not load"
20 changes: 5 additions & 15 deletions tests/acceptance/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,9 @@ def test_give_feedback_on_a_dataset(
page.get_by_role("link", name="Datasets", exact=True).click()
page.get_by_role("link", name="Geography").click()
page.get_by_role("link", name="Brownfield site").click()
page.get_by_role("link", name="Give feedback on this dataset").click()
linkHref = page.get_by_role(
"link", name="Give feedback on this dataset"
).get_attribute("href")

# ensure that the page has redirected to the google form
assert "docs.google.com" in page.url
assert page.get_by_role("heading", name="Give feedback on this dataset")

# had to add this as it seems to take some time for Google forms to auto populate this field
page.wait_for_timeout(500)

# ensure the form has the correct dataset name
assert (
page.get_by_role(
"textbox", name="Which dataset were you looking at?"
).input_value()
== "Brownfield site"
)
assert "google.com/forms" in linkHref
assert "Brownfield site" in linkHref
87 changes: 69 additions & 18 deletions tests/acceptance/test_map.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,89 @@
from tests.acceptance.pageObjectModels.mapPOM import MapPOM


def test_map_page_loads_ok(server_process, BASE_URL, page):
mapPage = MapPOM(page, BASE_URL)
mapPage.navigate()
response = page.goto(BASE_URL + "/map/")
assert response.ok
heading = page.get_by_role(
"heading",
name="Map of planning data for England",
)
assert heading.is_visible()


def wait_for_map_layer(page, layer, attempts=10, check_interval=10):
for i in range(attempts):
isHidden = page.evaluate(
f'() => mapControllers.map.map.getLayer("{layer}").isHidden()'
)
if isHidden is False:
return True
page.wait_for_timeout(check_interval)
assert False, f"Layer {layer} did not appear on the map"
page.screenshot(path="playwright-report/test_map_page_loads_ok/map.png")


def test_toggle_layers_on_the_national_map_correctly_shows_entity(
server_process,
page,
context,
add_base_entities_to_database_yield_reset,
skip_if_not_supportsGL,
test_settings,
BASE_URL,
):
# as the map xy coords are dependent on the viewport size, we need to set it to make sure the tests are consistent
page.set_viewport_size({"width": 800, "height": 600})
mapPage = MapPOM(page, BASE_URL)
mapPage.navigate("#50.88865897214836,-2.260771340418273,11.711391365982688z")
mapPage.check_layer_checkbox("Conservation area")
mapPage.wait_for_map_layer("conservation-area-source-fill-extrusion")

page.goto(
BASE_URL + "/map/#50.88865897214836,-2.260771340418273,11.711391365982688z"
)
page.get_by_label("Conservation area").check()
wait_for_map_layer(page, "conservation-area-source-fill-extrusion")

# the map doesn't seem to be properly loading on the cicd. so for now I'm going to put this test on hold

# def forwardLog(content, filename="playwright-report/log.txt"):
# if not os.path.exists("playwright-report"):
# os.makedirs("playwright-report")
# with open(filename, "a+") as f:
# current_time = time.strftime("%H:%M:%S", time.localtime())
# f.write(current_time + ": " + content + "\n")


# def test_using_the_map_to_find_an_entity(
# server_process,
# page,
# add_base_entities_to_database_yield_reset,
# skip_if_not_supportsGL,
# test_settings,
# BASE_URL,
# ):

# page.on("console", lambda msg: forwardLog(msg.text))

# page.goto(BASE_URL)
# page.get_by_role("link", name="Map", exact=True).click()

# page.wait_for_timeout(1000)

# mapPage = MapPOM(page, BASE_URL)

# mapPage.wait_for_layer_controls_to_load()

# mapPage.zoom_map(12)
# mapPage.centre_map_over(-2.2294632745091576, 50.88634078931207)

# mapPage.check_layer_checkbox("Conservation area")
# mapPage.wait_for_map_layer("conservation-area-source-fill-extrusion")

# page.wait_for_timeout(5000)

# mapPage.click_map_centre()

# page.screenshot(path="playwright-report/map.png")

# mapPage.wait_for_popup()

# with page.expect_navigation() as navigation_info:
# page.get_by_role("link", name="1").click()

# assert navigation_info.value.ok
# assert page.url == BASE_URL + "/entity/44002322"

# datasetHeading = page.locator("span").filter(has_text="Conservation area")
# assert datasetHeading.is_visible()

# ReferenceHeading = page.get_by_role(
# "heading",
# name="Historic England",
# )
# assert ReferenceHeading.is_visible()
4 changes: 3 additions & 1 deletion tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def test_app_returns_valid_populated_geojson_list(client, test_data):
assert len(
[
e
for e in test_data["entities"]
for e in test_data["entities"][
:10
] # only first 10 entities as we limit in the query
if e.get("geometry", None) is not None or e.get("point", None) is not None
]
) == len(data["features"])
Expand Down
Loading

0 comments on commit 208e6d3

Please sign in to comment.