diff --git a/src/registrar/admin.py b/src/registrar/admin.py index ae925b5c3..e1b9bd5a9 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -896,6 +896,7 @@ class DomainInformationAdmin(ListHeaderAdmin): "no_other_contacts_rationale", "anything_else", "is_policy_acknowledged", + "other_contacts", ] # For each filter_horizontal, init in admin js extendFilterHorizontalWidgets diff --git a/src/registrar/templates/django/admin/includes/domain_information_fieldset.html b/src/registrar/templates/django/admin/includes/domain_information_fieldset.html index 564415f24..b42873c3c 100644 --- a/src/registrar/templates/django/admin/includes/domain_information_fieldset.html +++ b/src/registrar/templates/django/admin/includes/domain_information_fieldset.html @@ -1,5 +1,2 @@ {% extends "django/admin/includes/detail_table_fieldset.html" %} - -{% block after_help_text %} -
TESTING123
-{% endblock after_help_text %} \ No newline at end of file +{# Stubbed file for future expansion #} diff --git a/src/registrar/templates/django/admin/includes/domain_request_fieldset.html b/src/registrar/templates/django/admin/includes/domain_request_fieldset.html index c694eb353..b42873c3c 100644 --- a/src/registrar/templates/django/admin/includes/domain_request_fieldset.html +++ b/src/registrar/templates/django/admin/includes/domain_request_fieldset.html @@ -1 +1,2 @@ -{% extends "django/admin/includes/detail_table_fieldset.html" %} \ No newline at end of file +{% extends "django/admin/includes/detail_table_fieldset.html" %} +{# Stubbed file for future expansion #} diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index 04eb4c82d..655fda02b 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -116,6 +116,31 @@ class GenericTestHelper(TestCase): self.url = url self.client = client + def assert_response_contains_distinct_values(self, response, expected_values): + """ + Asserts that each specified value appears exactly once in the response. + + This method iterates over a list of tuples, where each tuple contains a field name + and its expected value. It then performs an assertContains check for each value, + ensuring that each value appears exactly once in the response. + + Parameters: + - response: The HttpResponse object to inspect. + - expected_values: A list of tuples, where each tuple contains: + - field: The name of the field (used for subTest identification). + - value: The expected value to check for in the response. + + Example usage: + expected_values = [ + ("title", "Treat inspector"), + ("email", "meoward.jones@igorville.gov"), + ] + self.assert_response_contains_distinct_values(response, expected_values) + """ + for field, value in expected_values: + with self.subTest(field=field, expected_value=value): + self.assertContains(response, value, count=1) + def assert_table_sorted(self, o_index, sort_fields): """ This helper function validates the sorting functionality of a Django Admin table view. diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index b29776f81..042c7261b 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -1247,31 +1247,6 @@ class TestDomainRequestAdmin(MockEppLib): expected_url = 'city.com' self.assertContains(response, expected_url) - def assert_response_contains_distinct_values(self, response, expected_values): - """ - Asserts that each specified value appears exactly once in the response. - - This method iterates over a list of tuples, where each tuple contains a field name - and its expected value. It then performs an assertContains check for each value, - ensuring that each value appears exactly once in the response. - - Parameters: - - response: The HttpResponse object to inspect. - - expected_values: A list of tuples, where each tuple contains: - - field: The name of the field (used for subTest identification). - - value: The expected value to check for in the response. - - Example usage: - expected_values = [ - ("title", "Treat inspector"), - ("email", "meoward.jones@igorville.gov"), - ] - self.assert_response_contains_distinct_values(response, expected_values) - """ - for field, value in expected_values: - with self.subTest(field=field, expected_value=value): - self.assertContains(response, value, count=1) - @less_console_noise_decorator def test_contact_fields_have_detail_table(self): """Tests if the contact fields have the detail table which displays title, email, and phone""" @@ -1318,7 +1293,7 @@ class TestDomainRequestAdmin(MockEppLib): ("email", "meoward.jones@igorville.gov"), ("phone", "(555) 123 12345"), ] - self.assert_response_contains_distinct_values(response, expected_creator_fields) + self.test_helper.assert_response_contains_distinct_values(response, expected_creator_fields) # Check for the field itself self.assertContains(response, "Meoward Jones") @@ -1330,7 +1305,7 @@ class TestDomainRequestAdmin(MockEppLib): ("email", "mayor@igorville.gov"), ("phone", "(555) 555 5556"), ] - self.assert_response_contains_distinct_values(response, expected_submitter_fields) + self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields) self.assertContains(response, "Testy2 Tester2") # == Check for the authorizing_official == # @@ -1340,7 +1315,7 @@ class TestDomainRequestAdmin(MockEppLib): ("email", "testy@town.com"), ("phone", "(555) 555 5555"), ] - self.assert_response_contains_distinct_values(response, expected_ao_fields) + self.test_helper.assert_response_contains_distinct_values(response, expected_ao_fields) # count=4 because the underlying domain has two users with this name. # The dropdown has 3 of these. @@ -1365,7 +1340,7 @@ class TestDomainRequestAdmin(MockEppLib): ("email", "testy2@town.com"), ("phone", "(555) 555 5557"), ] - self.assert_response_contains_distinct_values(response, expected_other_employees_fields) + self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields) # count=1 as only one should exist in a table self.assertContains(response, "Testy Tester", count=1) @@ -1965,6 +1940,139 @@ class TestDomainInformationAdmin(TestCase): Contact.objects.all().delete() User.objects.all().delete() + @less_console_noise_decorator + def test_other_contacts_has_readonly_link(self): + """Tests if the readonly other_contacts field has links""" + + # Create a fake domain request and domain + domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW) + domain_request.approve() + domain_info = DomainInformation.objects.filter(domain=domain_request.approved_domain).get() + + # Get the other contact + other_contact = domain_info.other_contacts.all().first() + + p = "userpass" + self.client.login(username="staffuser", password=p) + response = self.client.get( + "/admin/registrar/domaininformation/{}/change/".format(domain_info.pk), + follow=True, + ) + + # Make sure the page loaded, and that we're on the right page + self.assertEqual(response.status_code, 200) + self.assertContains(response, domain_info.domain.name) + + # Check that the page contains the url we expect + expected_href = reverse("admin:registrar_contact_change", args=[other_contact.id]) + self.assertContains(response, expected_href) + + # Check that the page contains the link we expect. + # Since the url is dynamic (populated by JS), we can test for its existence + # by checking for the end tag. + expected_url = "Testy Tester" + self.assertContains(response, expected_url) + + @less_console_noise_decorator + def test_contact_fields_have_detail_table(self): + """Tests if the contact fields have the detail table which displays title, email, and phone""" + + # Create fake creator + _creator = User.objects.create( + username="MrMeoward", + first_name="Meoward", + last_name="Jones", + ) + + # Due to the relation between User <==> Contact, + # the underlying contact has to be modified this way. + _creator.contact.email = "meoward.jones@igorville.gov" + _creator.contact.phone = "(555) 123 12345" + _creator.contact.title = "Treat inspector" + _creator.contact.save() + + # Create a fake domain request + domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW, user=_creator) + domain_request.approve() + domain_info = DomainInformation.objects.filter(domain=domain_request.approved_domain).get() + + p = "userpass" + self.client.login(username="staffuser", password=p) + response = self.client.get( + "/admin/registrar/domaininformation/{}/change/".format(domain_info.pk), + follow=True, + ) + + # Make sure the page loaded, and that we're on the right page + self.assertEqual(response.status_code, 200) + self.assertContains(response, domain_info.domain.name) + + # Check that the modal has the right content + # Check for the header + + # == Check for the creator == # + + # Check for the right title, email, and phone number in the response. + # We only need to check for the end tag + # (Otherwise this test will fail if we change classes, etc) + expected_creator_fields = [ + # Field, expected value + ("title", "Treat inspector"), + ("email", "meoward.jones@igorville.gov"), + ("phone", "(555) 123 12345"), + ] + self.test_helper.assert_response_contains_distinct_values(response, expected_creator_fields) + + # Check for the field itself + self.assertContains(response, "Meoward Jones") + + # == Check for the submitter == # + expected_submitter_fields = [ + # Field, expected value + ("title", "Admin Tester"), + ("email", "mayor@igorville.gov"), + ("phone", "(555) 555 5556"), + ] + self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields) + self.assertContains(response, "Testy2 Tester2") + + # == Check for the authorizing_official == # + expected_ao_fields = [ + # Field, expected value + ("title", "Chief Tester"), + ("email", "testy@town.com"), + ("phone", "(555) 555 5555"), + ] + self.test_helper.assert_response_contains_distinct_values(response, expected_ao_fields) + + # count=4 because the underlying domain has two users with this name. + # The dropdown has 3 of these. + self.assertContains(response, "Testy Tester", count=4) + + # Check for table titles. We only need to check for the end tag + # (Otherwise this test will fail if we change classes, etc) + + # Title. Count=3 because this table appears on three records. + self.assertContains(response, "Title", count=3) + + # Email. Count=3 because this table appears on three records. + self.assertContains(response, "Email", count=3) + + # Phone. Count=3 because this table appears on three records. + self.assertContains(response, "Phone", count=3) + + # == Test the other_employees field == # + expected_other_employees_fields = [ + # Field, expected value + ("title", "Another Tester"), + ("email", "testy2@town.com"), + ("phone", "(555) 555 5557"), + ] + self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields) + + # count=1 as only one should exist in a table + self.assertContains(response, "Testy Tester", count=1) + def test_readonly_fields_for_analyst(self): """Ensures that analysts have their permissions setup correctly""" with less_console_noise(): @@ -1983,6 +2091,7 @@ class TestDomainInformationAdmin(TestCase): "no_other_contacts_rationale", "anything_else", "is_policy_acknowledged", + "other_contacts", ] self.assertEqual(readonly_fields, expected_fields)