Add test utilities and state machine diagrams for FSM models

- Introduced reusable test utilities in `backend/tests/utils` for FSM transitions, HTMX interactions, and common scenarios.
- Added factory functions for creating test submissions, parks, rides, and photo submissions.
- Implemented assertion helpers for verifying state changes, toast notifications, and transition logs.
- Created comprehensive state machine diagrams for all FSM-enabled models in `docs/STATE_DIAGRAMS.md`, detailing states, transitions, and guard conditions.
This commit is contained in:
pacnpal
2025-12-22 08:55:39 -05:00
parent b508434574
commit 45d97b6e68
71 changed files with 8608 additions and 633 deletions

View File

@@ -0,0 +1,30 @@
{# Park header status badge partial - refreshes via HTMX on park-status-changed #}
<span id="park-header-badge"
hx-get="{% url 'parks:park_header_badge' park.slug %}"
hx-trigger="park-status-changed from:body"
hx-swap="outerHTML">
{% if perms.parks.change_park %}
<!-- Clickable status badge for moderators -->
<button type="button"
onclick="document.getElementById('park-status-section').scrollIntoView({behavior: 'smooth'})"
class="status-badge text-sm font-medium py-1 px-3 transition-all hover:ring-2 hover:ring-blue-500 cursor-pointer
{% if park.status == 'OPERATING' %}status-operating
{% elif park.status == 'CLOSED_TEMP' or park.status == 'CLOSED_PERM' %}status-closed
{% elif park.status == 'UNDER_CONSTRUCTION' %}status-construction
{% elif park.status == 'DEMOLISHED' %}status-demolished
{% elif park.status == 'RELOCATED' %}status-relocated{% endif %}">
{{ park.get_status_display }}
<i class="fas fa-chevron-down ml-1 text-xs"></i>
</button>
{% else %}
<!-- Static status badge for non-moderators -->
<span class="status-badge text-sm font-medium py-1 px-3
{% if park.status == 'OPERATING' %}status-operating
{% elif park.status == 'CLOSED_TEMP' or park.status == 'CLOSED_PERM' %}status-closed
{% elif park.status == 'UNDER_CONSTRUCTION' %}status-construction
{% elif park.status == 'DEMOLISHED' %}status-demolished
{% elif park.status == 'RELOCATED' %}status-relocated{% endif %}">
{{ park.get_status_display }}
</span>
{% endif %}
</span>

View File

@@ -0,0 +1,23 @@
{% comment %}
Park FSM History Partial Template
Displays FSM transition history for a specific park.
Loaded via HTMX when the history section is expanded.
Required context:
- park: The Park model instance
{% endcomment %}
<div class="mt-4">
<div id="park-history-container"
hx-get="{% url 'moderation:moderation-reports-all-history' %}?model_type=park&object_id={{ park.id }}"
hx-trigger="load"
hx-swap="innerHTML"
hx-indicator="#park-history-loading">
<!-- Loading State -->
<div id="park-history-loading" class="flex items-center justify-center py-8">
<i class="mr-2 text-blue-500 fas fa-spinner fa-spin"></i>
<span class="text-gray-600 dark:text-gray-400">Loading history...</span>
</div>
</div>
</div>

View File

@@ -0,0 +1,19 @@
{% load fsm_tags %}
{# This partial is loaded via HTMX into #park-status-section. It must include the container #}
{# element with the same id and hx-* attributes to preserve targeting for subsequent transitions. #}
<div id="park-status-section"
data-park-status-actions
hx-get="{% url 'parks:park_status_actions' park.slug %}"
hx-trigger="park-status-changed from:body"
hx-swap="outerHTML">
{% if user.is_authenticated and perms.parks.change_park %}
<div class="mb-6 p-4 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg">
<h3 class="text-sm font-semibold text-blue-900 dark:text-blue-100 mb-3">
<i class="fas fa-cog mr-2"></i>Status Management
</h3>
{% include "htmx/status_with_actions.html" with object=park user=user target_id="park-status-section" %}
</div>
{% endif %}
</div>