From 31d80cc91df8950699a2807dff34350e937c1cd6 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Thu, 11 Jan 2024 15:49:29 -0500 Subject: [PATCH] Refactor JS tests for page titles to test against classes instead --- src/registrar/assets/js/get-gov.js | 21 +++++++++---------- .../templates/application_other_contacts.html | 2 +- src/registrar/templates/domain_dsdata.html | 2 +- .../templates/domain_nameservers.html | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 1dd7f6bc9..68e8af69c 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -358,14 +358,12 @@ function markForm(e, formLabel){ */ function prepareNewDeleteButton(btn, formLabel) { let formIdentifier = "form" - let isNameserversForm = document.title.includes("DNS name servers |"); - let isOtherContactsForm = document.title.includes("Other employees from your organization"); + let isNameserversForm = document.querySelector(".nameservers-form"); + let isOtherContactsForm = document.querySelector(".other-contacts-form"); let addButton = document.querySelector("#add-form"); + if (isOtherContactsForm) { formIdentifier = "other_contacts"; - } - - if (isOtherContactsForm) { // We will mark the forms for deletion btn.addEventListener('click', function(e) { markForm(e, formLabel); @@ -386,8 +384,8 @@ function prepareNewDeleteButton(btn, formLabel) { function prepareDeleteButtons(formLabel) { let formIdentifier = "form" let deleteButtons = document.querySelectorAll(".delete-record"); - let isNameserversForm = document.title.includes("DNS name servers |"); - let isOtherContactsForm = document.title.includes("Other employees from your organization"); + let isNameserversForm = document.querySelector(".nameservers-form"); + let isOtherContactsForm = document.querySelector(".other-contacts-form"); let addButton = document.querySelector("#add-form"); if (isOtherContactsForm) { formIdentifier = "other_contacts"; @@ -443,15 +441,16 @@ function hideDeletedForms() { let addButton = document.querySelector("#add-form"); let cloneIndex = 0; let formLabel = ''; - let isNameserversForm = document.title.includes("DNS name servers |"); - let isOtherContactsForm = document.title.includes("Other employees from your organization"); + let isNameserversForm = document.querySelector(".nameservers-form"); + let isOtherContactsForm = document.querySelector(".other-contacts-form"); + let isDsDataForm = document.querySelector(".ds-data-form"); // The Nameservers formset features 2 required and 11 optionals if (isNameserversForm) { cloneIndex = 2; formLabel = "Name server"; // DNSSEC: DS Data - } else if (document.title.includes("DS Data |")) { - formLabel = "DS Data record"; + } else if (isDsDataForm) { + formLabel = "DS data record"; // The Other Contacts form } else if (isOtherContactsForm) { formLabel = "Organization contact"; diff --git a/src/registrar/templates/application_other_contacts.html b/src/registrar/templates/application_other_contacts.html index 351fba0fc..b14458bcc 100644 --- a/src/registrar/templates/application_other_contacts.html +++ b/src/registrar/templates/application_other_contacts.html @@ -29,7 +29,7 @@ -
+
{% include "includes/required_fields.html" %} {{ forms.1.management_form }} {# forms.1 is a formset and this iterates over its forms #} diff --git a/src/registrar/templates/domain_dsdata.html b/src/registrar/templates/domain_dsdata.html index 1ec4c1f93..b62ad7ec5 100644 --- a/src/registrar/templates/domain_dsdata.html +++ b/src/registrar/templates/domain_dsdata.html @@ -24,7 +24,7 @@ {% include "includes/required_fields.html" %} -
+ {% csrf_token %} {{ formset.management_form }} diff --git a/src/registrar/templates/domain_nameservers.html b/src/registrar/templates/domain_nameservers.html index 15b810193..d60be2de8 100644 --- a/src/registrar/templates/domain_nameservers.html +++ b/src/registrar/templates/domain_nameservers.html @@ -24,7 +24,7 @@ {% include "includes/required_fields.html" %} - + {% csrf_token %} {{ formset.management_form }}