Skip to content

Commit

Permalink
DST-876 - Licensing - licensing grounds legal advisory not showing (#160
Browse files Browse the repository at this point in the history
)

* Adding front end tests

* comments

* Rebecca comments

* circleci fixing
  • Loading branch information
chris-pettinga authored Dec 30, 2024
1 parent 8d466c3 commit 432e5b8
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 10 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:
# we don't run frontend tests with coverage as only unit tests should affect coverage
command: |
sudo tee -a /etc/hosts \<<<'127.0.0.1 apply-for-a-licence'
sudo tee -a /etc/hosts \<<<'127.0.0.1 view-a-licence'
pipenv run playwright install --with-deps firefox
pipenv run pytest tests/test_frontend --browser firefox --junitxml=test-results/frontend/results.xml --create-db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ <h2 class="govuk-heading-m">Purpose of the services</h2>
<dl class="govuk-summary-list">
{% if form_data.licensing_grounds %}
<div class="govuk-summary-list__row">
{% if form_data.professional_or_business_services.professional_or_business_service|length == 1 and form_data.professional_or_business_services.professional_or_business_service|first == 'legal_advisory' %}
{% if form_data.professional_or_business_services.professional_or_business_services|length == 1 and form_data.professional_or_business_services.professional_or_business_services|first == 'legal_advisory' %}
<dt class="govuk-summary-list__key govuk-!-font-weight-regular">Licensing grounds for the relevant activity</dt>
{% else %}
<dt class="govuk-summary-list__key govuk-!-font-weight-regular">Licensing grounds</dt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ <h3 class="govuk-heading-s">Recipient {{ forloop.counter }}</h3>
<h2 class="govuk-heading-m">Purpose of the services</h2>
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key govuk-!-font-weight-regular">
<dt class="govuk-summary-list__key govuk-!-font-weight-regular" data-testid="">
Licensing grounds
</dt>
<dd class="govuk-summary-list__value">
Expand All @@ -276,8 +276,8 @@ <h2 class="govuk-heading-m">Purpose of the services</h2>
{% endfor %}
</dd>
</div>
{% if form_data.licensing_grounds_legal_advisory %}
<div class="govuk-summary-list__row">
{% if licence.licensing_grounds_legal_advisory %}
<div class="govuk-summary-list__row" data-testid="licensing-grounds-legal-advisory-box">
<dt class="govuk-summary-list__key govuk-!-font-weight-regular">
Licensing grounds (excluding legal advisory)
</dt>
Expand Down
16 changes: 10 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.db import IntegrityError
from django.test import Client, RequestFactory
from django.utils import timezone

Expand Down Expand Up @@ -36,12 +37,15 @@ def vl_client(db) -> Client:

@pytest.fixture()
def staff_user(db):
return User.objects.create_user(
"staff",
"[email protected]",
is_active=True,
is_staff=True,
)
try:
return User.objects.create_user(
"staff",
"[email protected]",
is_active=True,
is_staff=True,
)
except IntegrityError:
return User.objects.get(username="staff")


@pytest.fixture()
Expand Down
Empty file.
25 changes: 25 additions & 0 deletions tests/test_frontend/test_view_a_licence/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
from django.conf import settings

from tests.test_frontend.conftest import PlaywrightTestBase as BasePlaywrightTestBase


class PlaywrightTestBase(BasePlaywrightTestBase):
@property
def base_host(self) -> str:
return settings.VIEW_A_LICENCE_DOMAIN.split(":")[0]


@pytest.fixture(autouse=True, scope="function")
def bypass_login(monkeypatch, staff_user):
"""Overrides the get_user function to always return the staff user without authentication.
Effectively bypasses the login process for all frontend tests.
"""

def patched_get_user(request):
return staff_user

monkeypatch.setattr("django.contrib.auth.get_user", patched_get_user)

yield
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from apply_for_a_licence.choices import (
LicensingGroundsChoices,
ProfessionalOrBusinessServicesChoices,
TypeOfServicesChoices,
WhoDoYouWantTheLicenceToCoverChoices,
)
from django.urls import reverse
from playwright.sync_api import expect

from tests.factories import LicenceFactory
from tests.test_frontend.test_view_a_licence.conftest import PlaywrightTestBase


class TestViewALicenceApplicationView(PlaywrightTestBase):
def test_legal_grounds_legal_advisory(self):
licence = LicenceFactory.create(
who_do_you_want_the_licence_to_cover=WhoDoYouWantTheLicenceToCoverChoices.business.value,
type_of_service=TypeOfServicesChoices.professional_and_business.value,
professional_or_business_services=[
ProfessionalOrBusinessServicesChoices.legal_advisory.value,
ProfessionalOrBusinessServicesChoices.architectural.value,
],
licensing_grounds=[LicensingGroundsChoices.energy.value],
licensing_grounds_legal_advisory=[LicensingGroundsChoices.food.value, LicensingGroundsChoices.safety.value],
)
licence.assign_reference()
licence.save()
self.page.goto(self.base_url + reverse("view_a_licence:view_application", kwargs={"reference": licence.reference}))

conditional_box = self.page.get_by_test_id("licensing-grounds-legal-advisory-box")
expect(conditional_box).to_be_visible()
assert "Licensing grounds (excluding legal advisory)" in conditional_box.text_content()
assert LicensingGroundsChoices.food.label in conditional_box.text_content()
assert LicensingGroundsChoices.safety.value in conditional_box.text_content()

# now checking without legal advisory
licence = LicenceFactory.create(
who_do_you_want_the_licence_to_cover=WhoDoYouWantTheLicenceToCoverChoices.business.value,
type_of_service=TypeOfServicesChoices.professional_and_business.value,
professional_or_business_services=[ProfessionalOrBusinessServicesChoices.architectural.value],
licensing_grounds=[LicensingGroundsChoices.energy.value],
licensing_grounds_legal_advisory=None,
)
licence.assign_reference()
licence.save()
self.page.goto(self.base_url + reverse("view_a_licence:view_application", kwargs={"reference": licence.reference}))

assert self.page.get_by_test_id("licensing-grounds-legal-advisory-box").count() == 0

0 comments on commit 432e5b8

Please sign in to comment.