minor improvements

This commit is contained in:
David Kennedy 2024-08-29 10:58:19 -04:00
parent b2a464668b
commit 06aacd91ce
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 28 additions and 34 deletions

View file

@ -908,10 +908,6 @@ function initializeWidgetOnList(list, parentId) {
return;
}
// Hide the contactList initially.
// If we can update the contact information, it'll be shown again.
hideElement(contactList.parentElement);
// Determine if any changes are necessary to the display of portfolio type or federal type
// based on changes to the Federal Agency
let federalPortfolioApi = document.getElementById("federal_and_portfolio_types_from_agency_json_url").value;
@ -925,14 +921,15 @@ function initializeWidgetOnList(list, parentId) {
console.error("Error in AJAX call: " + data.error);
return;
}
let federal_type = data.federal_type;
let portfolio_type = data.portfolio_type;
updateFederalType(data.federal_type);
updatePortfolioType(data.portfolio_type);
updateReadOnly(data.federal_type, '.field-federal_type');
updateReadOnly(data.portfolio_type, '.field-portfolio_type');
})
.catch(error => console.error("Error fetching federal and portfolio types: ", error));
// Hide the contactList initially.
// If we can update the contact information, it'll be shown again.
hideElement(contactList.parentElement);
let seniorOfficialApi = document.getElementById("senior_official_from_agency_json_url").value;
fetch(`${seniorOfficialApi}?agency_name=${selectedText}`)
.then(response => {
@ -988,33 +985,21 @@ function initializeWidgetOnList(list, parentId) {
}
/**
* Dynamically update the portfolio type text in the dom to portfolioType
* Utility that selects a div from the DOM using selectorString,
* and updates a div within that div which has class of 'readonly'
* so that the text of the div is updated to updateText
* @param {*} updateText
* @param {*} selectorString
*/
function updatePortfolioType(portfolioType) {
// Find the div with class 'field-portfolio_type'
const portfolioTypeDiv = document.querySelector('.field-portfolio_type');
if (portfolioTypeDiv) {
// Find the nested div with class 'readonly' inside 'field-portfolio_type'
const readonlyDiv = portfolioTypeDiv.querySelector('.readonly');
function updateReadOnly(updateText, selectorString) {
// find the div by selectorString
const selectedDiv = document.querySelector(selectorString);
if (selectedDiv) {
// find the nested div with class 'readonly' inside the selectorString div
const readonlyDiv = selectedDiv.querySelector('.readonly');
if (readonlyDiv) {
// Update the text content of the readonly div
readonlyDiv.textContent = portfolioType !== null ? portfolioType : '-';
}
}
}
/**
* Dynamically update the federal type text in the dom to federalType
*/
function updateFederalType(federalType) {
// Find the div with class 'field-federal_type'
const federalTypeDiv = document.querySelector('.field-federal_type');
if (federalTypeDiv) {
// Find the nested div with class 'readonly' inside 'field-federal_type'
const readonlyDiv = federalTypeDiv.querySelector('.readonly');
if (readonlyDiv) {
// Update the text content of the readonly div
readonlyDiv.textContent = federalType !== null ? federalType : '-';
readonlyDiv.textContent = updateText !== null ? updateText : '-';
}
}
}

View file

@ -5,6 +5,7 @@ from django.contrib.auth import get_user_model
from registrar.tests.common import create_superuser, create_user
from api.tests.common import less_console_noise_decorator
from registrar.utility.constants import BranchChoices
class GetSeniorOfficialJsonTest(TestCase):
@ -82,7 +83,7 @@ class GetFederalPortfolioTypeJsonTest(TestCase):
self.superuser = create_superuser()
self.analyst_user = create_user()
self.agency = FederalAgency.objects.create(agency="Test Agency", federal_type="judicial")
self.agency = FederalAgency.objects.create(agency="Test Agency", federal_type=BranchChoices.JUDICIAL)
self.api_url = reverse("get-federal-and-portfolio-types-from-federal-agency-json")
@ -100,3 +101,11 @@ class GetFederalPortfolioTypeJsonTest(TestCase):
data = response.json()
self.assertEqual(data["federal_type"], "Judicial")
self.assertEqual(data["portfolio_type"], "Federal - Judicial")
@less_console_noise_decorator
def test_get_federal_and_portfolio_types_json_authenticated_regularuser(self):
"""Test that a regular user receives a 403 with an error message."""
p = "password"
self.client.login(username="testuser", password=p)
response = self.client.get(self.api_url, {"agency_name": "Test Agency", "organization_type": "federal"})
self.assertEqual(response.status_code, 302)