From e2327675e1fe6d3573644fd1701a2dcdf17aca1d Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Tue, 8 Mar 2016 15:50:39 +0300 Subject: [PATCH] Adds tests for buttons hooks Tests folowing: * `register_page_listing_buttons` * `register_page_listing_more_buttons` * Custom hook produced by non-default `ButtonWithDropdownFromHook` instance organised indicator color state variables into main variables.scss file --- .../wagtailadmin/scss/_variables.scss | 9 ++ .../scss/components/_indicator.scss | 4 - .../wagtailadmin/tests/test_buttons_hooks.py | 83 +++++++++++++++++++ 3 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 wagtail/wagtailadmin/tests/test_buttons_hooks.py diff --git a/wagtail/wagtailadmin/static_src/wagtailadmin/scss/_variables.scss b/wagtail/wagtailadmin/static_src/wagtailadmin/scss/_variables.scss index 509956f09f..11b923a78b 100644 --- a/wagtail/wagtailadmin/static_src/wagtailadmin/scss/_variables.scss +++ b/wagtail/wagtailadmin/static_src/wagtailadmin/scss/_variables.scss @@ -65,6 +65,12 @@ $color-link-hover: $color-teal-dark; $color-text-base: $color-grey-2; $color-text-input: $color-grey-1; +// Color states +$color-state-live: #59b524; +$color-state-draft: #808080; +$color-state-absent: #ff8f11; +$color-state-live-draft: #43b1b0; + // Fonts $font-sans: Open Sans, Arial, sans-serif; $font-serif: Roboto Slab, Georgia, serif; @@ -72,3 +78,6 @@ $font-serif: Roboto Slab, Georgia, serif; // misc sizing $thumbnail-width: 130px; $menu-width: 180px; + + + diff --git a/wagtail/wagtailadmin/static_src/wagtailadmin/scss/components/_indicator.scss b/wagtail/wagtailadmin/static_src/wagtailadmin/scss/components/_indicator.scss index bb2af009a3..7a26a81161 100644 --- a/wagtail/wagtailadmin/static_src/wagtailadmin/scss/components/_indicator.scss +++ b/wagtail/wagtailadmin/static_src/wagtailadmin/scss/components/_indicator.scss @@ -24,10 +24,6 @@ $c-indicator-margin: .25rem; // States // ============================================================================= -$color-state-live: #59b524; -$color-state-draft: #808080; -$color-state-absent: #ff8f11; -$color-state-live-draft: #43b1b0; .is-absent .c-indicator { background: $color-state-absent; diff --git a/wagtail/wagtailadmin/tests/test_buttons_hooks.py b/wagtail/wagtailadmin/tests/test_buttons_hooks.py new file mode 100644 index 0000000000..ccb0175f6e --- /dev/null +++ b/wagtail/wagtailadmin/tests/test_buttons_hooks.py @@ -0,0 +1,83 @@ +from django.core.urlresolvers import reverse +from django.test import TestCase + +from wagtail.tests.utils import WagtailTestUtils +from wagtail.wagtailadmin import widgets as wagtailadmin_widgets +from wagtail.wagtailcore import hooks +from wagtail.wagtailcore.models import Page + + +class TestButtonsHooks(TestCase, WagtailTestUtils): + def setUp(self): + self.root_page = Page.objects.get(id=2) + self.login() + + def test_register_page_listing_buttons(self): + @hooks.register('register_page_listing_buttons') + def page_listing_buttons(page, page_perms, is_parent=False): + yield wagtailadmin_widgets.PageListingButton( + 'Another useless page listing button', + '/custom-url', + priority=10 + ) + + response = self.client.get( + reverse('wagtailadmin_explore', args=(self.root_page.id, )) + ) + + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailadmin/pages/listing/_button_with_dropdown.html') + self.assertTemplateUsed(response, 'wagtailadmin/pages/listing/_buttons.html') + + self.assertContains(response, 'Another useless page listing button') + + def test_register_page_listing_more_buttons(self): + @hooks.register('register_page_listing_more_buttons') + def page_listing_more_buttons(page, page_perms, is_parent=False): + yield wagtailadmin_widgets.Button( + 'Another useless button in default "More" dropdown', + '/custom-url', + priority=10 + ) + + response = self.client.get( + reverse('wagtailadmin_explore', args=(self.root_page.id, )) + ) + + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailadmin/pages/listing/_button_with_dropdown.html') + self.assertTemplateUsed(response, 'wagtailadmin/pages/listing/_buttons.html') + + self.assertContains(response, 'Another useless button in default "More" dropdown') + + def test_custom_button_with_dropdown(self): + @hooks.register('register_page_listing_buttons') + def page_custom_listing_buttons(page, page_perms, is_parent=False): + yield wagtailadmin_widgets.ButtonWithDropdownFromHook( + 'One more more button', + hook_name='register_page_listing_one_more_more_buttons', + page=page, + page_perms=page_perms, + is_parent=is_parent, + attrs={'target': '_blank'}, + priority=50 + ) + + @hooks.register('register_page_listing_one_more_more_buttons') + def page_custom_listing_more_buttons(page, page_perms, is_parent=False): + yield wagtailadmin_widgets.Button( + 'Another useless dropdown button in "One more more button" dropdown', + '/custom-url', + priority=10 + ) + + response = self.client.get( + reverse('wagtailadmin_explore', args=(self.root_page.id, )) + ) + + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailadmin/pages/listing/_button_with_dropdown.html') + self.assertTemplateUsed(response, 'wagtailadmin/pages/listing/_buttons.html') + + self.assertContains(response, 'One more more button') + self.assertContains(response, 'Another useless dropdown button in "One more more button" dropdown')