-
Notifications
You must be signed in to change notification settings - Fork 0
Create a simple object to hold interview steps #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
035c4a7
Add central filing workflow registry
nonprofittechy dbfed91
Add workflow context to options page
nonprofittechy 87d01cb
Add workflow context to upload-first page
nonprofittechy 7aca569
Add workflow context to case information page
nonprofittechy eb1f209
Add workflow context to payment page
nonprofittechy c5bd6c6
Fix workflow lint imports
nonprofittechy 7a4b93d
Add workflow registry tests
nonprofittechy 99b9ad1
Address workflow typing review comments
nonprofittechy 4fc3182
Add workflow context to document upload page
nonprofittechy 826e12a
Add workflow context to confirmation page
nonprofittechy 1ab8d77
Add workflow context to review page
nonprofittechy 3030492
Document workflow step maintenance
nonprofittechy 54b7aca
Merge branch 'main' into workflow-registry
nonprofittechy 8bed869
Use enum keys for workflow steps
nonprofittechy 1b7fd8a
Use workflow enum in options view
nonprofittechy 03e77f4
Use workflow enum in lead upload view
nonprofittechy dc8dc7f
Use workflow enum in case information view
nonprofittechy 98af822
Use workflow enum in document upload view
nonprofittechy deeaa61
Use workflow enum in payment view
nonprofittechy a8bdbb1
Use workflow enum in review view
nonprofittechy 1ad9a0d
Use workflow enum in confirmation view
nonprofittechy f031f59
Use workflow enum in workflow tests
nonprofittechy 9bf8a3c
Fix workflow test lint issues
nonprofittechy ecd148b
Sort workflow test imports
nonprofittechy e40b17e
fix ruff
nonprofittechy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import pytest | ||
| from django.urls import reverse | ||
|
|
||
| from efile.workflow import ( | ||
| FILING_WORKFLOW, | ||
| WorkflowStepKey, | ||
| get_next_step, | ||
| get_previous_step, | ||
| get_step, | ||
| get_step_url, | ||
| get_workflow_context, | ||
| get_workflow_steps, | ||
| ) | ||
|
|
||
| EXPECTED_WORKFLOW_KEYS = [ | ||
| WorkflowStepKey.OPTIONS, | ||
| WorkflowStepKey.UPLOAD_FIRST, | ||
| WorkflowStepKey.CASE_INFORMATION, | ||
| WorkflowStepKey.DOCUMENTS, | ||
| WorkflowStepKey.PAYMENT, | ||
| WorkflowStepKey.REVIEW, | ||
| WorkflowStepKey.CONFIRMATION, | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("step_key", "label"), | ||
| [ | ||
| (WorkflowStepKey.OPTIONS, "Options"), | ||
| (WorkflowStepKey.UPLOAD_FIRST, "Upload lead document"), | ||
| (WorkflowStepKey.CASE_INFORMATION, "Case information"), | ||
| (WorkflowStepKey.DOCUMENTS, "Documents"), | ||
| (WorkflowStepKey.PAYMENT, "Payment"), | ||
| (WorkflowStepKey.REVIEW, "Review"), | ||
| (WorkflowStepKey.CONFIRMATION, "Confirmation"), | ||
| ], | ||
| ) | ||
| def test_get_step_returns_registered_step(step_key, label): | ||
| step = get_step(step_key) | ||
|
|
||
| assert step.key == step_key | ||
| assert step.label == label | ||
|
|
||
|
|
||
| def test_get_workflow_steps_returns_ordered_workflow(): | ||
| assert get_workflow_steps() == FILING_WORKFLOW | ||
| assert [step.key for step in get_workflow_steps()] == EXPECTED_WORKFLOW_KEYS | ||
|
|
||
|
|
||
| def test_get_step_raises_key_error_for_invalid_step(): | ||
| with pytest.raises(KeyError): | ||
| get_step("invalid_step") | ||
|
|
||
|
|
||
| def test_get_previous_step_returns_none_for_first_step(): | ||
| assert get_previous_step(WorkflowStepKey.OPTIONS) is None | ||
|
|
||
|
|
||
| def test_get_previous_step_returns_prior_step(): | ||
| previous_step = get_previous_step(WorkflowStepKey.CASE_INFORMATION) | ||
|
|
||
| assert previous_step.key == WorkflowStepKey.UPLOAD_FIRST | ||
|
|
||
|
|
||
| def test_get_next_step_returns_following_step(): | ||
| next_step = get_next_step(WorkflowStepKey.CASE_INFORMATION) | ||
|
|
||
| assert next_step.key == WorkflowStepKey.DOCUMENTS | ||
|
|
||
|
|
||
| def test_get_next_step_returns_none_for_last_step(): | ||
| assert get_next_step(WorkflowStepKey.CONFIRMATION) is None | ||
|
|
||
|
|
||
| def test_get_step_url_reverses_workflow_route(): | ||
| expected_url = reverse("payment", kwargs={"jurisdiction": "illinois"}) | ||
|
|
||
| assert get_step_url(WorkflowStepKey.PAYMENT, "illinois") == expected_url | ||
|
|
||
|
|
||
| def test_get_workflow_context_includes_current_previous_and_next_urls(): | ||
| context = get_workflow_context(WorkflowStepKey.PAYMENT, "illinois") | ||
| previous_url = reverse("upload", kwargs={"jurisdiction": "illinois"}) | ||
| next_url = reverse("case_review", kwargs={"jurisdiction": "illinois"}) | ||
|
|
||
| assert context["workflow_current_step"].key == WorkflowStepKey.PAYMENT | ||
| assert context["workflow_previous_step"].key == WorkflowStepKey.DOCUMENTS | ||
| assert context["workflow_next_step"].key == WorkflowStepKey.REVIEW | ||
| assert context["workflow_previous_url"] == previous_url | ||
| assert context["workflow_next_url"] == next_url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| """Central filing workflow registry. | ||
|
|
||
| Use FILING_WORKFLOW as the single high-level map of the filing flow. | ||
|
|
||
| To add a step: | ||
| 1. Add a WorkflowStepKey member for the new step. | ||
| 2. Add the URL route and view. | ||
| 3. Add a WorkflowStep entry in the desired position below. | ||
| 4. Add get_workflow_context(WorkflowStepKey.YOUR_STEP, jurisdiction) to that view's context. | ||
| 5. Update any navigation copy that mentions the surrounding steps. | ||
| 6. Update efile/tests/test_workflow.py. | ||
|
|
||
| To rearrange steps: | ||
| 1. Reorder FILING_WORKFLOW. | ||
| 2. Update affected labels, navigation copy, and workflow tests. | ||
|
|
||
| This registry is intentionally linear for now. Future branching should be added | ||
| here after the durable filing draft model exists as the workflow state source. | ||
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
| from enum import StrEnum | ||
|
|
||
| from django.urls import reverse | ||
|
|
||
|
|
||
| class WorkflowStepKey(StrEnum): | ||
| """Stable identifiers for filing workflow steps.""" | ||
|
|
||
| OPTIONS = "options" | ||
| UPLOAD_FIRST = "upload_first" | ||
| CASE_INFORMATION = "case_information" | ||
| DOCUMENTS = "documents" | ||
| PAYMENT = "payment" | ||
| REVIEW = "review" | ||
| CONFIRMATION = "confirmation" | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class WorkflowStep: | ||
| """A single screen in the filing workflow.""" | ||
|
|
||
| key: WorkflowStepKey | ||
| label: str | ||
| url_name: str | ||
|
|
||
|
|
||
| FILING_WORKFLOW: tuple[WorkflowStep, ...] = ( | ||
| WorkflowStep(WorkflowStepKey.OPTIONS, "Options", "efile_options"), | ||
| WorkflowStep(WorkflowStepKey.UPLOAD_FIRST, "Upload lead document", "upload_first"), | ||
| WorkflowStep(WorkflowStepKey.CASE_INFORMATION, "Case information", "expert_form"), | ||
| WorkflowStep(WorkflowStepKey.DOCUMENTS, "Documents", "upload"), | ||
| WorkflowStep(WorkflowStepKey.PAYMENT, "Payment", "payment"), | ||
| WorkflowStep(WorkflowStepKey.REVIEW, "Review", "case_review"), | ||
| WorkflowStep(WorkflowStepKey.CONFIRMATION, "Confirmation", "filing_confirmation"), | ||
| ) | ||
|
|
||
|
|
||
| def get_workflow_steps() -> tuple[WorkflowStep, ...]: | ||
| return FILING_WORKFLOW | ||
|
|
||
|
|
||
| def get_step(step_key: WorkflowStepKey | str) -> WorkflowStep: | ||
| try: | ||
| return next(step for step in FILING_WORKFLOW if step.key == step_key) | ||
| except StopIteration as exc: | ||
| raise KeyError(f"Unknown workflow step: {step_key}") from exc | ||
|
|
||
|
|
||
| def get_step_index(step_key: WorkflowStepKey | str) -> int: | ||
| for index, step in enumerate(FILING_WORKFLOW): | ||
| if step.key == step_key: | ||
| return index | ||
| raise KeyError(f"Unknown workflow step: {step_key}") | ||
|
|
||
|
|
||
| def get_previous_step(step_key: WorkflowStepKey | str) -> WorkflowStep | None: | ||
| index = get_step_index(step_key) | ||
| if index == 0: | ||
| return None | ||
| return FILING_WORKFLOW[index - 1] | ||
|
|
||
|
|
||
| def get_next_step(step_key: WorkflowStepKey | str) -> WorkflowStep | None: | ||
| index = get_step_index(step_key) | ||
| try: | ||
| return FILING_WORKFLOW[index + 1] | ||
| except IndexError: | ||
| return None | ||
|
|
||
|
|
||
| def get_step_url(step_key: WorkflowStepKey | str, jurisdiction: str) -> str: | ||
| step = get_step(step_key) | ||
| return reverse(step.url_name, kwargs={"jurisdiction": jurisdiction}) | ||
|
|
||
|
|
||
| def get_workflow_context(current_step: WorkflowStepKey | str, jurisdiction: str) -> dict: | ||
| previous_step = get_previous_step(current_step) | ||
| next_step = get_next_step(current_step) | ||
| previous_url = None | ||
| next_url = None | ||
|
|
||
| if previous_step: | ||
| previous_url = get_step_url(previous_step.key, jurisdiction) | ||
| if next_step: | ||
| next_url = get_step_url(next_step.key, jurisdiction) | ||
|
|
||
| return { | ||
| "workflow_steps": get_workflow_steps(), | ||
| "workflow_current_step": get_step(current_step), | ||
| "workflow_previous_step": previous_step, | ||
| "workflow_next_step": next_step, | ||
| "workflow_previous_url": previous_url, | ||
| "workflow_next_url": next_url, | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.