From 821a61710c4fac50ca7224024a8cb6ab273ab310 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 22 Oct 2020 10:44:13 +0100 Subject: writing code to control the swimlane template --- .../compliance/templates/compliance/overview.html | 2 +- ctrack/register/tests/test_css.py | 132 +++++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 ctrack/register/tests/test_css.py diff --git a/ctrack/compliance/templates/compliance/overview.html b/ctrack/compliance/templates/compliance/overview.html index a7054e0..13c835e 100644 --- a/ctrack/compliance/templates/compliance/overview.html +++ b/ctrack/compliance/templates/compliance/overview.html @@ -83,7 +83,7 @@ ORG NAME 1 - CAF Initial Submitted + CAF Initial Submitted CAF Reviewed OES Revisions Submitted Validation Agreed diff --git a/ctrack/register/tests/test_css.py b/ctrack/register/tests/test_css.py new file mode 100644 index 0000000..da16bfe --- /dev/null +++ b/ctrack/register/tests/test_css.py @@ -0,0 +1,132 @@ +from dataclasses import dataclass +from typing import NamedTuple, List + +import pytest + +from ctrack.register.models import CAFSingleDateEvent, EventType, EventBase + +pytestmark = pytest.mark.django_db + + +class TagAttributes(NamedTuple): + inline_style: str + id_str: str + + +def tag_attrs(event) -> TagAttributes: + if event.type_descriptor == EventType.CAF_INITIAL_CAF_RECEIVED.name: + return TagAttributes( + inline_style="background-color: green; color: white;", + id_str="caf-initial-received-event", + ) + + +@pytest.mark.parametrize( + "e_type,css_str,id_str", + [ + ( + EventType.CAF_INITIAL_CAF_RECEIVED.name, + "background-color: green; color: white;", + "caf-initial-received-event", + ) + ], +) +def test_can_get_class_string(caf, user, e_type, css_str, id_str): + event = CAFSingleDateEvent.objects.create( + type_descriptor=e_type, related_caf=caf, date="2020-10-20", user=user + ) + assert tag_attrs(event).inline_style == css_str + assert tag_attrs(event).id_str == id_str + + +class Swimlane: + def __init__(self, events: List[EventBase]): + self.events = events + self.slots = [] + + +class CAFSwimlaneSlots: + """ + The pre-compliance stages we expect. + """ + + def __init__(self, events): + for e in events: + if e.type_descriptor == "CAF Initial Submitted": + self._initial_submitted = e + else: + self._initial_submitted = None + if e.type_descriptor == "CAF Reviewed": + self._reviewed = e + else: + self._reviewed = None + if e.type_descriptor == "CAF Revisions Submitted": + self._revisions_submitted = e + else: + self._revisions_submitted = None + if e.type_descriptor == "CAF Validation Agreed": + self._validation_agreed = e + else: + self._validation_agreed = None + if e.type_descriptor == "Improvement Plan Submitted": + self._improvement_plan_submitted = e + else: + self._improvement_plan_submitted = None + if e.type_descriptor == "Improvement Plan Reviewed": + self._improvement_plan_reviewed = e + else: + self._improvement_plan_reviewed = None + if e.type_descriptor == "Improvement Plan Agreed": + self._improvement_plan_agreed = e + else: + self._improvement_plan_agreed = None + + @property + def initial_submitted(self): + return self._initial_submitted + + @property + def improvement_plan_agreed(self): + return self._improvement_plan_agreed + + +def test_swimlane_slots(): + class _TestEvent: + def __init__(self, type_descriptor): + self.type_descriptor = type_descriptor + + slots = CAFSwimlaneSlots( + [ + _TestEvent("CAF Initial Submitted"), + _TestEvent("CAF Reviewed"), + _TestEvent("CAF Revisions Submitted"), + _TestEvent("CAF Validation Agreed"), + _TestEvent("Improvement Plan Submitted"), + _TestEvent("Improvement Plan Reviewed"), + # _TestEvent("Improvement Plan Agreed") + ] + ) + assert slots.initial_submitted.type_descriptor == "CAF Initial Submitted" + assert slots.improvement_plan_agreed is None + + +def test_progress_chart_slots(caf, user): + accept = """ + + ORG NAME 1 + CAF Initial Submitted + CAF Reviewed + OES Revisions Submitted + Validation Agreed + Improvement Plan Submitted + Improvement Plan Review + + """ + caf_initial = CAFSingleDateEvent.objects.create( + type_descriptor=EventType.CAF_INITIAL_CAF_RECEIVED.name, + related_caf=caf, + date="2020-10-20", + user=user, + ) + output = Swimlane([caf_initial]) + assert output.tr == accept -- cgit v1.2.3