Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-kennedy-ecs committed Aug 29, 2024
1 parent b2a4646 commit 06aacd9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
51 changes: 18 additions & 33 deletions src/registrar/assets/js/get-gov-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 => {
Expand Down Expand Up @@ -988,33 +985,21 @@ function initializeWidgetOnList(list, parentId) {
}

/**
* Dynamically update the portfolio type text in the dom to portfolioType
*/
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');
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
* 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 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');
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 = federalType !== null ? federalType : '-';
readonlyDiv.textContent = updateText !== null ? updateText : '-';
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/registrar/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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):
Expand Down Expand Up @@ -82,7 +83,7 @@ def setUp(self):
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")

Expand All @@ -100,3 +101,11 @@ def test_get_federal_and_portfolio_types_json_authenticated_superuser(self):
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)

0 comments on commit 06aacd9

Please sign in to comment.