0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Add tests for rendering breadcrumbs on workflows and tasks views

This commit is contained in:
Sage Abdullah 2023-09-13 14:00:32 +01:00
parent 5bc3fbf615
commit 8dc376ce26
No known key found for this signature in database
GPG Key ID: EB1A33CC51CC0217

View File

@ -40,6 +40,7 @@ from wagtail.test.testapp.models import (
SimpleTask,
)
from wagtail.test.utils import WagtailTestUtils
from wagtail.test.utils.template_tests import AdminTemplateTestUtils
from wagtail.users.models import UserProfile
@ -86,7 +87,7 @@ class TestWorkflowMenus(WagtailTestUtils, TestCase):
self.assertNotContains(response, '"url": "/admin/reports/workflow_tasks/"')
class TestWorkflowsIndexView(WagtailTestUtils, TestCase):
class TestWorkflowsIndexView(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
def setUp(self):
delete_existing_workflows()
self.login()
@ -115,6 +116,7 @@ class TestWorkflowsIndexView(WagtailTestUtils, TestCase):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailadmin/workflows/index.html")
self.assertBreadcrumbsItemsRendered([{"label": "Workflows"}], response.content)
# Initially there should be no workflows listed
self.assertContains(response, "There are no enabled workflows.")
@ -162,7 +164,7 @@ class TestWorkflowsIndexView(WagtailTestUtils, TestCase):
self.assertEqual(response.status_code, 200)
class TestWorkflowsCreateView(WagtailTestUtils, TestCase):
class TestWorkflowsCreateView(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
def setUp(self):
delete_existing_workflows()
self.login()
@ -202,6 +204,13 @@ class TestWorkflowsCreateView(WagtailTestUtils, TestCase):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailadmin/workflows/create.html")
self.assertBreadcrumbsItemsRendered(
[
{"label": "Workflows", "url": "/admin/workflows/list/"},
{"label": "New: Workflow"},
],
response.content,
)
def test_post(self):
response = self.post(
@ -372,7 +381,7 @@ class TestWorkflowsCreateView(WagtailTestUtils, TestCase):
self.assertEqual(link.workflow, workflow)
class TestWorkflowsEditView(WagtailTestUtils, TestCase):
class TestWorkflowsEditView(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
def setUp(self):
delete_existing_workflows()
self.login()
@ -425,6 +434,13 @@ class TestWorkflowsEditView(WagtailTestUtils, TestCase):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailadmin/workflows/edit.html")
self.assertBreadcrumbsItemsRendered(
[
{"url": "/admin/workflows/list/", "label": "Workflows"},
{"label": str(self.workflow)},
],
response.content,
)
# Check that the list of pages has the page to which this workflow is assigned
self.assertContains(response, self.page.title)
@ -708,7 +724,7 @@ class TestRemoveWorkflow(WagtailTestUtils, TestCase):
self.assertEqual(response.status_code, 302)
class TestTaskIndexView(WagtailTestUtils, TestCase):
class TestTaskIndexView(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
def setUp(self):
delete_existing_workflows()
self.login()
@ -737,6 +753,7 @@ class TestTaskIndexView(WagtailTestUtils, TestCase):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailadmin/workflows/task_index.html")
self.assertBreadcrumbsItemsRendered([{"label": "Tasks"}], response.content)
# Initially there should be no tasks listed
self.assertContains(response, "There are no enabled tasks")
@ -785,7 +802,7 @@ class TestTaskIndexView(WagtailTestUtils, TestCase):
self.assertEqual(response.status_code, 200)
class TestCreateTaskView(WagtailTestUtils, TestCase):
class TestCreateTaskView(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
def setUp(self):
delete_existing_workflows()
self.login()
@ -831,6 +848,13 @@ class TestCreateTaskView(WagtailTestUtils, TestCase):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailadmin/workflows/create_task.html")
self.assertBreadcrumbsItemsRendered(
[
{"label": "Tasks", "url": "/admin/workflows/tasks/index/"},
{"label": "New: Simple task"},
],
response.content,
)
def test_get_with_non_task_model(self):
response = self.get(
@ -911,7 +935,7 @@ class TestSelectTaskTypeView(WagtailTestUtils, TestCase):
)
class TestEditTaskView(WagtailTestUtils, TestCase):
class TestEditTaskView(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
def setUp(self):
delete_existing_workflows()
self.login()
@ -948,6 +972,13 @@ class TestEditTaskView(WagtailTestUtils, TestCase):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailadmin/workflows/edit_task.html")
self.assertBreadcrumbsItemsRendered(
[
{"url": "/admin/workflows/tasks/index/", "label": "Tasks"},
{"label": str(self.task)},
],
response.content,
)
def test_post(self):
self.assertEqual(self.task.groups.count(), 0)
@ -2803,7 +2834,7 @@ class TestSnippetNotificationPreferencesHTML(TestSnippetNotificationPreferences)
pass
class TestDisableViews(BasePageWorkflowTests):
class TestDisableViews(AdminTemplateTestUtils, BasePageWorkflowTests):
def test_disable_workflow(self):
"""Test that deactivating a workflow sets it to inactive and cancels in progress states"""
self.login(self.submitter)
@ -2851,6 +2882,7 @@ class TestDisableViews(BasePageWorkflowTests):
response,
"This workflow is in progress on 1 page/snippet. Disabling this workflow will cancel moderation on this page/snippet.",
)
self.assertBreadcrumbsNotRendered(response.content)
def test_get_disable_workflow_no_warning(self):
"""Test that deactivating a workflow does not show a warning if there are no in progress states"""
@ -2866,6 +2898,7 @@ class TestDisableViews(BasePageWorkflowTests):
response,
"Disabling this workflow will cancel moderation on this page/snippet.",
)
self.assertBreadcrumbsNotRendered(response.content)
def test_disable_task_view(self):
"""Test that a view is shown before disabling a task that shows a warning"""
@ -2888,6 +2921,7 @@ class TestDisableViews(BasePageWorkflowTests):
response,
"This task is in progress on 1 page/snippet. Disabling this task will cause it to be skipped in the moderation workflow and not be listed for selection when editing a workflow.",
)
self.assertBreadcrumbsNotRendered(response.content)
# create a new, unused, task and check there is no warning message
unused_task = GroupApprovalTask.objects.create(name="unused_task_3")
@ -2904,6 +2938,7 @@ class TestDisableViews(BasePageWorkflowTests):
"Disabling this task will cause it to be skipped in the moderation workflow "
"and not be listed for selection when editing a workflow.",
)
self.assertBreadcrumbsNotRendered(response.content)
unused_task.delete() # clean up