mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-29 17:00:02 +02:00
minor improvements
This commit is contained in:
parent
b2a464668b
commit
06aacd91ce
2 changed files with 28 additions and 34 deletions
|
@ -908,10 +908,6 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
return;
|
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
|
// Determine if any changes are necessary to the display of portfolio type or federal type
|
||||||
// based on changes to the Federal Agency
|
// based on changes to the Federal Agency
|
||||||
let federalPortfolioApi = document.getElementById("federal_and_portfolio_types_from_agency_json_url").value;
|
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);
|
console.error("Error in AJAX call: " + data.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
updateReadOnly(data.federal_type, '.field-federal_type');
|
||||||
let federal_type = data.federal_type;
|
updateReadOnly(data.portfolio_type, '.field-portfolio_type');
|
||||||
let portfolio_type = data.portfolio_type;
|
|
||||||
updateFederalType(data.federal_type);
|
|
||||||
updatePortfolioType(data.portfolio_type);
|
|
||||||
})
|
})
|
||||||
.catch(error => console.error("Error fetching federal and portfolio types: ", error));
|
.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;
|
let seniorOfficialApi = document.getElementById("senior_official_from_agency_json_url").value;
|
||||||
fetch(`${seniorOfficialApi}?agency_name=${selectedText}`)
|
fetch(`${seniorOfficialApi}?agency_name=${selectedText}`)
|
||||||
.then(response => {
|
.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) {
|
function updateReadOnly(updateText, selectorString) {
|
||||||
// Find the div with class 'field-portfolio_type'
|
// find the div by selectorString
|
||||||
const portfolioTypeDiv = document.querySelector('.field-portfolio_type');
|
const selectedDiv = document.querySelector(selectorString);
|
||||||
if (portfolioTypeDiv) {
|
if (selectedDiv) {
|
||||||
// Find the nested div with class 'readonly' inside 'field-portfolio_type'
|
// find the nested div with class 'readonly' inside the selectorString div
|
||||||
const readonlyDiv = portfolioTypeDiv.querySelector('.readonly');
|
const readonlyDiv = selectedDiv.querySelector('.readonly');
|
||||||
if (readonlyDiv) {
|
if (readonlyDiv) {
|
||||||
// Update the text content of the readonly div
|
// Update the text content of the readonly div
|
||||||
readonlyDiv.textContent = portfolioType !== null ? portfolioType : '-';
|
readonlyDiv.textContent = updateText !== null ? updateText : '-';
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 : '-';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ from django.contrib.auth import get_user_model
|
||||||
from registrar.tests.common import create_superuser, create_user
|
from registrar.tests.common import create_superuser, create_user
|
||||||
|
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
|
from registrar.utility.constants import BranchChoices
|
||||||
|
|
||||||
|
|
||||||
class GetSeniorOfficialJsonTest(TestCase):
|
class GetSeniorOfficialJsonTest(TestCase):
|
||||||
|
@ -82,7 +83,7 @@ class GetFederalPortfolioTypeJsonTest(TestCase):
|
||||||
self.superuser = create_superuser()
|
self.superuser = create_superuser()
|
||||||
self.analyst_user = create_user()
|
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")
|
self.api_url = reverse("get-federal-and-portfolio-types-from-federal-agency-json")
|
||||||
|
|
||||||
|
@ -100,3 +101,11 @@ class GetFederalPortfolioTypeJsonTest(TestCase):
|
||||||
data = response.json()
|
data = response.json()
|
||||||
self.assertEqual(data["federal_type"], "Judicial")
|
self.assertEqual(data["federal_type"], "Judicial")
|
||||||
self.assertEqual(data["portfolio_type"], "Federal - 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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue