From 48b05fb8d54a7938195399575f8eae0495565583 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Tue, 19 Jun 2018 16:16:53 +0100 Subject: [PATCH] Add tests for the applicant dashboard --- .../dashboard/applicant_dashboard.html | 8 +++- opentech/apply/dashboard/tests/test_views.py | 38 +++++++++++++++++++ .../apply/funds/tests/factories/models.py | 4 ++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 opentech/apply/dashboard/tests/test_views.py diff --git a/opentech/apply/dashboard/templates/dashboard/applicant_dashboard.html b/opentech/apply/dashboard/templates/dashboard/applicant_dashboard.html index a9795e015..ee3d6ebc8 100644 --- a/opentech/apply/dashboard/templates/dashboard/applicant_dashboard.html +++ b/opentech/apply/dashboard/templates/dashboard/applicant_dashboard.html @@ -28,7 +28,13 @@ </div> {% include "funds/includes/status_bar.html" with phases=submission.workflow current_phase=submission.phase class="status-bar--small" %} {% if request.user|has_edit_perm:submission %} - <a class="button button--primary" href="{% url 'funds:submissions:edit' submission.id %}">Start your {{ submission.stage }} application</a> + <a class="button button--primary" href="{% url 'funds:submissions:edit' submission.id %}"> + {% if submission.status == 'draft_proposal' %} + Start your {{ submission.stage }} application + {% else %} + Edit + {% endif %} + </a> {% endif %} </div> {% empty %} diff --git a/opentech/apply/dashboard/tests/test_views.py b/opentech/apply/dashboard/tests/test_views.py new file mode 100644 index 000000000..a6d3514a2 --- /dev/null +++ b/opentech/apply/dashboard/tests/test_views.py @@ -0,0 +1,38 @@ +from opentech.apply.funds.tests.factories import ApplicationSubmissionFactory +from opentech.apply.users.tests.factories import UserFactory +from opentech.apply.utils.tests import BaseViewTestCase + + +class TestApplicantDashboard(BaseViewTestCase): + user_factory = UserFactory + url_name = 'dashboard:{}' + base_view_name = 'dashboard' + + def test_can_access_dashboard_with_active(self): + application = ApplicationSubmissionFactory(user=self.user, form_data__title='Improve the internet') + response = self.get_page() + self.assertContains(response, application.title) + self.assertNotContains(response, 'Submission history') + + def test_can_not_access_other_users_active(self): + application = ApplicationSubmissionFactory(form_data__title='Ruin the internet') + response = self.get_page() + self.assertNotContains(response, application.title) + self.assertNotContains(response, 'Submission history') + + def test_gets_invite_if_invited_to_proposal(self): + ApplicationSubmissionFactory(user=self.user, draft_proposal=True) + response = self.get_page() + self.assertContains(response, 'Start your ') + + def test_no_invite_if_can_edit(self): + ApplicationSubmissionFactory(user=self.user, status='concept_more_info', workflow_stages=2) + response = self.get_page() + self.assertNotContains(response, 'Start your ') + self.assertContains(response, 'Edit', 1) + + def test_no_edit_if_in_review(self): + ApplicationSubmissionFactory(user=self.user, status='internal_review') + response = self.get_page() + self.assertNotContains(response, 'Edit') + self.assertNotContains(response, 'Submission history') diff --git a/opentech/apply/funds/tests/factories/models.py b/opentech/apply/funds/tests/factories/models.py index abef318fc..dd93ca97e 100644 --- a/opentech/apply/funds/tests/factories/models.py +++ b/opentech/apply/funds/tests/factories/models.py @@ -186,6 +186,10 @@ class ApplicationSubmissionFactory(factory.DjangoModelFactory): class Params: workflow_stages = 1 + draft_proposal = factory.Trait( + status='draft_proposal', + workflow_name='double', + ) form_fields = blocks.CustomFormFieldsFactory form_data = factory.SubFactory(FormDataFactory, form_fields=factory.SelfAttribute('..form_fields')) -- GitLab