|
| 1 | +from unittest.mock import MagicMock |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | + |
| 6 | +@pytest.fixture |
| 7 | +def template(jinja_env): |
| 8 | + return jinja_env.get_template("components/start-appointment/template.jinja") |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture |
| 12 | +def presented_appointment(): |
| 13 | + mock = MagicMock() |
| 14 | + mock.pk = "abc-123" |
| 15 | + mock.participant.full_name = "Jane Smith" |
| 16 | + mock.can_be_checked_in = False |
| 17 | + return mock |
| 18 | + |
| 19 | + |
| 20 | +def render(template, user_has_perm, presented_appointment): |
| 21 | + user = MagicMock() |
| 22 | + user.has_perm.return_value = user_has_perm |
| 23 | + return template.render( |
| 24 | + { |
| 25 | + "user": user, |
| 26 | + "presented_appointment": presented_appointment, |
| 27 | + "start_appointment_url": "/mammograms/abc-123/start-appointment/", |
| 28 | + "csrf_input": "", |
| 29 | + } |
| 30 | + ) |
| 31 | + |
| 32 | + |
| 33 | +def test_renders_start_button_for_clinical_user(template, presented_appointment): |
| 34 | + html = render( |
| 35 | + template, user_has_perm=True, presented_appointment=presented_appointment |
| 36 | + ) |
| 37 | + assert 'data-module="app-start-appointment"' in html |
| 38 | + |
| 39 | + |
| 40 | +def test_does_not_render_start_button_for_admin_user(template, presented_appointment): |
| 41 | + html = render( |
| 42 | + template, user_has_perm=False, presented_appointment=presented_appointment |
| 43 | + ) |
| 44 | + assert 'data-module="app-start-appointment"' not in html |
| 45 | + |
| 46 | + |
| 47 | +def test_renders_button_hidden_before_checkin(template, presented_appointment): |
| 48 | + presented_appointment.can_be_checked_in = True |
| 49 | + html = render( |
| 50 | + template, user_has_perm=True, presented_appointment=presented_appointment |
| 51 | + ) |
| 52 | + assert 'data-module="app-start-appointment"' in html |
| 53 | + assert 'data-appointment-id="abc-123" hidden' in html |
| 54 | + |
| 55 | + |
| 56 | +def test_renders_button_visible_after_checkin(template, presented_appointment): |
| 57 | + presented_appointment.can_be_checked_in = False |
| 58 | + html = render( |
| 59 | + template, user_has_perm=True, presented_appointment=presented_appointment |
| 60 | + ) |
| 61 | + assert 'data-module="app-start-appointment"' in html |
| 62 | + assert 'data-appointment-id="abc-123" hidden' not in html |
0 commit comments