+ {% if licence.licensing_grounds_legal_advisory %}
+
Licensing grounds (excluding legal advisory)
diff --git a/tests/conftest.py b/tests/conftest.py
index 3c3a4dd3..ecbf9ecf 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -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
@@ -36,12 +37,15 @@ def vl_client(db) -> Client:
@pytest.fixture()
def staff_user(db):
- return User.objects.create_user(
- "staff",
- "staff@example.com",
- is_active=True,
- is_staff=True,
- )
+ try:
+ return User.objects.create_user(
+ "staff",
+ "staff@example.com",
+ is_active=True,
+ is_staff=True,
+ )
+ except IntegrityError:
+ return User.objects.get(username="staff")
@pytest.fixture()
diff --git a/tests/test_frontend/test_apply_for_a_licence/test_cya_change/__init__.py b/tests/test_frontend/test_apply_for_a_licence/test_cya/__init__.py
similarity index 100%
rename from tests/test_frontend/test_apply_for_a_licence/test_cya_change/__init__.py
rename to tests/test_frontend/test_apply_for_a_licence/test_cya/__init__.py
diff --git a/tests/test_frontend/test_apply_for_a_licence/test_cya_change/test_cya_change.py b/tests/test_frontend/test_apply_for_a_licence/test_cya/test_cya_change.py
similarity index 100%
rename from tests/test_frontend/test_apply_for_a_licence/test_cya_change/test_cya_change.py
rename to tests/test_frontend/test_apply_for_a_licence/test_cya/test_cya_change.py
diff --git a/tests/test_frontend/test_apply_for_a_licence/test_cya_change/test_cya_remove.py b/tests/test_frontend/test_apply_for_a_licence/test_cya/test_cya_remove.py
similarity index 100%
rename from tests/test_frontend/test_apply_for_a_licence/test_cya_change/test_cya_remove.py
rename to tests/test_frontend/test_apply_for_a_licence/test_cya/test_cya_remove.py
diff --git a/tests/test_frontend/test_view_a_licence/__init__.py b/tests/test_frontend/test_view_a_licence/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/test_frontend/test_view_a_licence/conftest.py b/tests/test_frontend/test_view_a_licence/conftest.py
new file mode 100644
index 00000000..ea03bf79
--- /dev/null
+++ b/tests/test_frontend/test_view_a_licence/conftest.py
@@ -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
diff --git a/tests/test_frontend/test_view_a_licence/test_views/__init__.py b/tests/test_frontend/test_view_a_licence/test_views/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/test_frontend/test_view_a_licence/test_views/test_view_a_licence_application_view.py b/tests/test_frontend/test_view_a_licence/test_views/test_view_a_licence_application_view.py
new file mode 100644
index 00000000..1c49a499
--- /dev/null
+++ b/tests/test_frontend/test_view_a_licence/test_views/test_view_a_licence_application_view.py
@@ -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