Add tests for custom columns on snippets listing view

pull/9259/head
Sage Abdullah 2022-09-11 16:43:31 +01:00 zatwierdzone przez Matt Westcott
rodzic 0a0bd30fad
commit c90dfc6fef
3 zmienionych plików z 44 dodań i 0 usunięć

Wyświetl plik

@ -598,6 +598,42 @@ class TestSnippetListViewWithFilterSet(TestCase, WagtailTestUtils):
)
class TestListViewWithCustomColumns(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
@classmethod
def setUpTestData(cls):
FilterableSnippet.objects.create(text="From Indonesia", country_code="ID")
FilterableSnippet.objects.create(text="From the UK", country_code="UK")
def get(self, params={}):
return self.client.get(
reverse("wagtailsnippets_snippetstests_filterablesnippet:list"),
params,
)
def test_custom_columns(self):
response = self.get()
self.assertContains(response, "Text")
self.assertContains(response, "Country Code")
self.assertContains(response, "Custom Foo Column")
self.assertContains(response, "Updated")
self.assertContains(response, "Foo UK")
list_url = reverse("wagtailsnippets_snippetstests_filterablesnippet:list")
sort_country_code_url = list_url + "?ordering=country_code"
# One from the country code column, another from the custom foo column
self.assertContains(response, sort_country_code_url, count=2)
html = response.content.decode()
# The bulk actions column plus 4 columns defined in FilterableSnippetViewSet
self.assertTagInHTML("<th>", html, count=5, allow_extra_attrs=True)
class TestSnippetCreateView(TestCase, WagtailTestUtils):
def setUp(self):
self.user = self.login()

Wyświetl plik

@ -80,6 +80,12 @@ class FilterableSnippet(index.Indexed, models.Model):
def __str__(self):
return self.text
def get_foo_country_code(self):
return f"Foo {self.country_code}"
get_foo_country_code.admin_order_field = "country_code"
get_foo_country_code.short_description = "Custom foo column"
class FilterableSnippetFilterSet(WagtailFilterSet):
class Meta:

Wyświetl plik

@ -1,6 +1,8 @@
from wagtail.admin.ui.tables import UpdatedAtColumn
from wagtail.snippets.views.snippets import SnippetViewSet
from wagtail.test.snippets.models import FilterableSnippetFilterSet
class FilterableSnippetViewSet(SnippetViewSet):
filterset_class = FilterableSnippetFilterSet
list_display = ["text", "country_code", "get_foo_country_code", UpdatedAtColumn()]