Daves refactor cleanup

This commit is contained in:
Rachid Mrad 2024-02-02 11:58:51 -05:00
parent da3dfd487e
commit 06a66cc5b0
No known key found for this signature in database
3 changed files with 21 additions and 50 deletions

View file

@ -4,27 +4,26 @@
<nav aria-label="Form steps,">
<ul class="usa-sidenav">
{% for this_step in steps.all %}
{% if this_step in visited %}
<li class="usa-sidenav__item sidenav__step--locked">
{% if this_step == steps.current %}
<span>
{% if not this_step == steps.current %}
{% if this_step != "review" %}
<svg class="usa-icon text-green" aria-hidden="true" focsuable="false" role="img" width="24" height="24">
<title id="checked-step__{{forloop.counter}}">Checked mark</title>
<use xlink:href="{%static 'img/sprite.svg'%}#check_circle"></use>
</svg>
{% endif %}
{% endif %}
<a href="{% namespaced_url 'application' this_step %}"
{% if this_step == steps.current %}
class="usa-current"
>
{% else %}
class="link_usa-checked"
{% endif%}>
{{ form_titles|get_item:this_step }}
</a>
{% elif this_step in visited %}
<span>
{% if this_step != "review" %}
<svg class="usa-icon text-green" aria-hidden="true" focsuable="false" role="img" width="24" height="24">
<title id="checked-step__{{forloop.counter}}">Checked mark</title>
<use xlink:href="{%static 'img/sprite.svg'%}#check_circle"></use>
</svg>
{% endif %}
<a href="{% namespaced_url 'application' this_step %}"
class="link_usa-checked"
>
{{ form_titles|get_item:this_step }}
</a>
</span>
</span>
{% else %}
<li class="usa-sidenav__item sidenav__step--locked">
<span>
@ -40,4 +39,4 @@
{% endfor %}
</ul>
</nav>
</div>
</div>

View file

@ -2387,23 +2387,7 @@ class TestWizardUnlockingSteps(TestWithUser, WebTest):
def test_unlocked_steps_empty_application(self):
"""Test when all fields in the application are empty."""
unlocked_steps = self.wizard.db_check_for_unlocking_steps()
expected_dict = {
"about_your_organization": False,
"anything_else": False,
"authorizing_official": False,
"current_sites": False,
"dotgov_domain": False,
"organization_contact": False,
"organization_election": False,
"organization_federal": False,
"organization_type": False,
"other_contacts": False,
"purpose": False,
"requirements": False,
"review": False,
"tribal_government": False,
"your_contact": False,
}
expected_dict = []
self.assertEqual(unlocked_steps, expected_dict)
def test_unlocked_steps_full_application(self):

View file

@ -215,6 +215,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
if current_url == self.EDIT_URL_NAME and "id" in kwargs:
del self.storage
self.storage["application_id"] = kwargs["id"]
self.storage["step_history"] = self.db_check_for_unlocking_steps()
# if accessing this class directly, redirect to the first step
# in other words, if `ApplicationWizard` is called as view
@ -338,7 +339,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
"""Helper for get_context_data
Queries the DB for an application and returns a dict for unlocked steps."""
return {
history_dict = {
"organization_type": bool(self.application.organization_type),
"tribal_government": bool(self.application.tribe_name),
"organization_federal": bool(self.application.federal_type),
@ -367,6 +368,7 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
"requirements": bool(self.application.is_policy_acknowledged),
"review": bool(self.application.is_policy_acknowledged),
}
return [key for key, value in history_dict.items() if value]
def get_context_data(self):
"""Define context for access on all wizard pages."""
@ -378,25 +380,11 @@ class ApplicationWizard(ApplicationWizardPermissionView, TemplateView):
else:
modal_heading = "You are about to submit an incomplete request"
unlocked_steps_list = [key for key, value in self.db_check_for_unlocking_steps().items() if value]
# History captures the ephemeral activation of the current step
# We want to add that to our unlocked steps so that users can navigate to another
# step than back to the empty form step.
step_history_set = set(self.storage.get("step_history", []))
unlocked_steps_set = set(unlocked_steps_list)
# Find the elements in step_history_set that are not in unlocked_steps_set
new_elements = step_history_set - unlocked_steps_set
# Add the new elements to unlocked_steps_list
unlocked_steps_list.extend(new_elements)
return {
"form_titles": self.TITLES,
"steps": self.steps,
# Add information about which steps should be unlocked
"visited": unlocked_steps_list,
"visited": self.storage.get("step_history", []),
"is_federal": self.application.is_federal(),
"modal_button": modal_button,
"modal_heading": modal_heading,