Refactor JS tests for page titles to test against classes instead

This commit is contained in:
Rachid Mrad 2024-01-11 15:49:29 -05:00
parent c226babfdf
commit 31d80cc91d
No known key found for this signature in database
GPG key ID: EF38E4CEC4A8F3CF
4 changed files with 13 additions and 14 deletions

View file

@ -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) {
formIdentifier = "other_contacts";
// 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";

View file

@ -29,7 +29,7 @@
</fieldset>
<div id="other-employees">
<div id="other-employees" class="other-contacts-form">
{% include "includes/required_fields.html" %}
{{ forms.1.management_form }}
{# forms.1 is a formset and this iterates over its forms #}

View file

@ -24,7 +24,7 @@
{% include "includes/required_fields.html" %}
<form class="usa-form usa-form--extra-large" method="post" novalidate id="form-container">
<form class="usa-form usa-form--extra-large ds-data-form" method="post" novalidate id="form-container">
{% csrf_token %}
{{ formset.management_form }}

View file

@ -24,7 +24,7 @@
{% include "includes/required_fields.html" %}
<form class="usa-form usa-form--extra-large" method="post" novalidate id="form-container">
<form class="usa-form usa-form--extra-large nameservers-form" method="post" novalidate id="form-container">
{% csrf_token %}
{{ formset.management_form }}