diff --git a/krill/reports/test_sidebar.py b/krill/reports/test_sidebar.py new file mode 100644 index 0000000..5f87902 --- /dev/null +++ b/krill/reports/test_sidebar.py @@ -0,0 +1,56 @@ +import re + +from django.contrib.auth import get_user_model +from django.test import TestCase +from django.urls import reverse + +User = get_user_model() + +REPORT_PAGES = { + 'Overview': 'reports:reports_dashboard', + 'Storage Audits': 'reports:audit_list', + 'Alerts': 'reports:alert_list', + 'Checked Out, No Owner': 'reports:checked_out_no_owner', +} + + +class ReportsSidebarSectionTest(TestCase): + def setUp(self): + self.user = User.objects.create_user(username='member', password='x') + self.client.force_login(self.user) + + def _item_classes(self, html, url): + match = re.search(r'{label}', section) + + def test_section_is_collapsed_away_from_reports_and_open_inside_it(self): + away = self.client.get(reverse('home')).content.decode() + self.assertIn('id="reports-section" class="sidebar-submenu "', away) + inside = self.client.get(reverse('reports:alert_list')).content.decode() + self.assertIn('id="reports-section" class="sidebar-submenu show"', inside) + + def test_the_current_page_is_the_active_item(self): + for label, name in REPORT_PAGES.items(): + with self.subTest(label=label): + html = self.client.get(reverse(name)).content.decode() + for other_label, other_name in REPORT_PAGES.items(): + classes = self._item_classes(html, reverse(other_name)) + if other_name == name: + self.assertIn('active', classes.split(), f'{other_label} should be active on {label}') + else: + self.assertNotIn('active', classes.split(), f'{other_label} should not be active on {label}') + + def test_audit_detail_pages_keep_storage_audits_active(self): + url = reverse('reports:generate_audit_report') + html = self.client.get(url).content.decode() + self.assertIn('active', self._item_classes(html, reverse('reports:audit_list')).split()) diff --git a/krill/sample/tests/test_dashboard_sections.py b/krill/sample/tests/test_dashboard_sections.py new file mode 100644 index 0000000..de4ae0e --- /dev/null +++ b/krill/sample/tests/test_dashboard_sections.py @@ -0,0 +1,93 @@ +from django.contrib.auth import get_user_model +from django.urls import reverse +from django.utils import timezone + +from person.models import SiteConfiguration +from ..models.aliquot import Aliquot, AliquotDisposition +from .test_views import SampleViewTest + +User = get_user_model() + + +class DashboardSectionsTest(SampleViewTest): + """The dashboard groups its tiles under Samples, Storage and Consumables, like the sidebar.""" + + def setUp(self): + super().setUp() + self.client.force_login(self.user) + self.in_use = AliquotDisposition.objects.get_or_create( + name='In Use', defaults={'disposition_type': 'in_use'})[0] + + def _html(self): + return self.client.get(reverse('home')).content.decode() + + def _consumables(self, enabled): + config = SiteConfiguration.load() + config.consumables_enabled = enabled + config.save() + + def _owned(self): + return Aliquot.objects.create( + sample=self.sample, disposition=self.in_use, + checked_out_by=self.user, checked_out_at=timezone.now()) + + def test_groups_appear_in_order_with_recent_activity_last(self): + self._consumables(True) + html = self._html() + positions = [html.index(f'class="dashboard-group-label">{name}<') for name in ('Samples', 'Storage', 'Consumables')] + self.assertEqual(positions, sorted(positions)) + self.assertGreater(html.index('

Recent Activity

'), positions[-1]) + + def test_sample_tiles_and_checked_out_card_sit_in_the_samples_group(self): + self._owned() + html = self._html() + start, end = html.index('>Samples<'), html.index('class="dashboard-group-label">Storage<') + group = html[start:end] + for expected in ('

Samples

', '

Aliquots

', 'Checked out by you (1)'): + self.assertIn(expected, group) + for elsewhere in ('

Storage Used

', '

Audits

', '

Freezers

'): + self.assertNotIn(elsewhere, group) + + def test_storage_tiles_and_freezers_sit_in_the_storage_group(self): + self._consumables(True) + html = self._html() + start = html.index('class="dashboard-group-label">Storage<') + end = html.index('class="dashboard-group-label">Consumables<') + group = html[start:end] + for expected in ('

Storage Used

', '

Audits

', '

Freezers

'): + self.assertIn(expected, group) + + def test_alerts_tile_is_kept_and_sits_after_audits_in_the_storage_group(self): + self._consumables(True) + html = self._html() + group = html[html.index('class="dashboard-group-label">Storage<'):html.index('class="dashboard-group-label">Consumables<')] + self.assertRegex(group, r'
\s*

Alerts

') + self.assertLess(group.index('

Audits

'), group.index('

Alerts

')) + self.assertIn(reverse('reports:alert_list'), group) + + def test_consumable_tiles_sit_in_the_consumables_group_when_enabled(self): + self._consumables(True) + html = self._html() + group = html[html.index('class="dashboard-group-label">Consumables<'):html.index('

Recent Activity

')] + self.assertIn('

Low Stock

', group) + self.assertIn('

Expiring Soon

', group) + + def test_no_consumables_group_when_the_feature_is_off(self): + self._consumables(False) + html = self._html() + self.assertNotIn('Consumables<', html.replace('class="dashboard-group-label">Samples<', '')) + self.assertNotIn('

Low Stock

', html) + self.assertNotIn('

Expiring Soon

', html) + + def test_quick_actions_come_before_the_groups(self): + html = self._html() + self.assertLess(html.index('class="quick-actions"'), html.index('class="dashboard-group-label">Samples<')) + + def test_manager_tile_is_in_the_samples_group(self): + manager = User.objects.create_user(username='mgr', password='x') + manager.role.role = 'lab_manager' + manager.role.save() + self.client.force_login(manager) + html = self._html() + group = html[html.index('>Samples<'):html.index('class="dashboard-group-label">Storage<')] + self.assertIn('

Lab Checkouts

', group) diff --git a/krill/templates/base/left_sidebar.html b/krill/templates/base/left_sidebar.html index c5bc067..7732a0a 100644 --- a/krill/templates/base/left_sidebar.html +++ b/krill/templates/base/left_sidebar.html @@ -107,12 +107,34 @@

Reorder List

{% endif %} -
- - description - -

Reports

-
+ + settings diff --git a/krill/templates/krill/home.html b/krill/templates/krill/home.html index 748052f..91042fc 100644 --- a/krill/templates/krill/home.html +++ b/krill/templates/krill/home.html @@ -7,7 +7,26 @@

Dashboard

- + +
+
+ + add_circle + New Aliquot + + + search + Find Aliquot + + + fact_check + Start Audit + +
+
+ + +

Samples

science @@ -23,43 +42,6 @@

Aliquots

{{ stats.aliquots|default:"0" }}

- - inventory_2 -
-

Storage Used

-

{{ stats.storage_usage|default:"0" }}%

-
-
- - fact_check -
-

Audits

-

{% if audits_in_progress %}{{ audits_in_progress|length }} in progress{% else %}None in progress{% endif %}

-
-
- - warning -
-

Alerts

-

{% if stats.alerts %}{{ stats.alerts }} active{% else %}All clear{% endif %}

-
-
- {% if site_config.consumables_enabled %} - - production_quantity_limits -
-

Low Stock

-

{% if stats.low_stock_count %}{{ stats.low_stock_count }} item{{ stats.low_stock_count|pluralize }}{% else %}All stocked{% endif %}

-
-
- - event_busy -
-

Expiring Soon

-

{% if stats.expiring_soon_count %}{{ stats.expiring_soon_count }} item{{ stats.expiring_soon_count|pluralize }}{% else %}None in 30 days{% endif %}

-
-
- {% endif %} {% if lab_checkouts is not None %} groups @@ -70,25 +52,6 @@

Lab Checkouts

{% endif %} - - -
-
- - add_circle - New Aliquot - - - search - Find Aliquot - - - fact_check - Start Audit - -
-
- {% url 'home' as home_url %} {% if checked_out.total %} @@ -127,6 +90,31 @@

Checked out by you ({{ checked_out.total }})

Nothing checked out. Find an aliquot to check one out.

{% endif %} + +

Storage

+
+ + inventory_2 +
+

Storage Used

+

{{ stats.storage_usage|default:"0" }}%

+
+
+ + fact_check +
+

Audits

+

{% if audits_in_progress %}{{ audits_in_progress|length }} in progress{% else %}None in progress{% endif %}

+
+
+ + warning +
+

Alerts

+

{% if stats.alerts %}{{ stats.alerts }} active{% else %}All clear{% endif %}

+
+
+
@@ -180,6 +168,27 @@

In progress

{% endif %} + + {% if site_config.consumables_enabled %} +

Consumables

+
+ + production_quantity_limits +
+

Low Stock

+

{% if stats.low_stock_count %}{{ stats.low_stock_count }} item{{ stats.low_stock_count|pluralize }}{% else %}All stocked{% endif %}

+
+
+ + event_busy +
+

Expiring Soon

+

{% if stats.expiring_soon_count %}{{ stats.expiring_soon_count }} item{{ stats.expiring_soon_count|pluralize }}{% else %}None in 30 days{% endif %}

+
+
+
+ {% endif %} +
@@ -218,6 +227,8 @@

Recent Activity

.checked-out-card { margin-top: 16px; } .checked-out-empty { margin: 8px 0 16px; color: var(--color-dark-variant); } .dashboard-header { margin-bottom: 20px; } + .dashboard-group-label { margin: 24px 0 10px; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; + text-transform: uppercase; color: var(--color-dark-variant); } .freezer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; } .freezer-card { display: flex; flex-direction: column; gap: 10px; padding: 16px; text-decoration: none; background: var(--color-white); color: var(--color-dark); border: 1px solid var(--color-light);