diff --git a/wagtail/admin/rich_text/__init__.py b/wagtail/admin/rich_text/__init__.py index 09ecc2c77..fb0603f5a 100644 --- a/wagtail/admin/rich_text/__init__.py +++ b/wagtail/admin/rich_text/__init__.py @@ -1,14 +1,15 @@ from django.conf import settings from django.utils.module_loading import import_string -from wagtail.admin.rich_text.editors.hallo import ( +from wagtail.admin.rich_text.editors.hallo import ( # NOQA HalloFormatPlugin, HalloHeadingPlugin, HalloListPlugin, HalloPlugin, HalloRichTextArea -) # NOQA +) +from wagtail.admin.rich_text.editors.draftail import DraftailRichTextArea # NOQA DEFAULT_RICH_TEXT_EDITORS = { 'default': { - 'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea' + 'WIDGET': 'wagtail.admin.rich_text.DraftailRichTextArea' } } diff --git a/wagtail/admin/tests/test_edit_handlers.py b/wagtail/admin/tests/test_edit_handlers.py index 1bcafb1a3..487d1e75c 100644 --- a/wagtail/admin/tests/test_edit_handlers.py +++ b/wagtail/admin/tests/test_edit_handlers.py @@ -14,7 +14,7 @@ from wagtail.admin.edit_handlers import ( FieldPanel, FieldRowPanel, InlinePanel, ObjectList, PageChooserPanel, RichTextFieldPanel, TabbedInterface, extract_panel_definitions_from_model_class, get_form_for_model) from wagtail.admin.forms import WagtailAdminModelForm, WagtailAdminPageForm -from wagtail.admin.rich_text import HalloRichTextArea +from wagtail.admin.rich_text import DraftailRichTextArea from wagtail.admin.widgets import AdminAutoHeightTextInput, AdminDateInput, AdminPageChooser from wagtail.core.models import Page, Site from wagtail.images.edit_handlers import ImageChooserPanel @@ -62,7 +62,7 @@ class TestGetFormForModel(TestCase): # RichTextField - they should retain their default widgets EventPageForm = get_form_for_model(EventPage, form_class=WagtailAdminPageForm) event_form = EventPageForm() - self.assertEqual(type(event_form.fields['body'].widget), HalloRichTextArea) + self.assertEqual(type(event_form.fields['body'].widget), DraftailRichTextArea) def test_get_form_for_model_with_specific_fields(self): EventPageForm = get_form_for_model( diff --git a/wagtail/admin/tests/test_pages_views.py b/wagtail/admin/tests/test_pages_views.py index 793f0261f..96f5dfc72 100644 --- a/wagtail/admin/tests/test_pages_views.py +++ b/wagtail/admin/tests/test_pages_views.py @@ -4231,15 +4231,15 @@ class TestInlinePanelMedia(TestCase, WagtailTestUtils): homepage = Page.objects.get(id=2) self.login() - # simplepage does not need hallo... + # simplepage does not need draftail... response = self.client.get(reverse('wagtailadmin_pages:add', args=('tests', 'simplepage', homepage.id))) self.assertEqual(response.status_code, 200) - self.assertNotContains(response, 'wagtailadmin/js/hallo-bootstrap.js') + self.assertNotContains(response, 'wagtailadmin/js/draftail.js') # but sectionedrichtextpage does response = self.client.get(reverse('wagtailadmin_pages:add', args=('tests', 'sectionedrichtextpage', homepage.id))) self.assertEqual(response.status_code, 200) - self.assertContains(response, 'wagtailadmin/js/hallo-bootstrap.js') + self.assertContains(response, 'wagtailadmin/js/draftail.js') class TestInlineStreamField(TestCase, WagtailTestUtils): @@ -4737,7 +4737,9 @@ class TestPreview(TestCase, WagtailTestUtils): self.post_data = { 'title': "Beach party", 'slug': 'beach-party', - 'body': "party on wayne", + 'body': '''{"entityMap": {},"blocks": [ + {"inlineStyleRanges": [], "text": "party on wayne", "depth": 0, "type": "unstyled", "key": "00000", "entityRanges": []} + ]}''', 'date_from': '2017-08-01', 'audience': 'public', 'location': 'the beach', diff --git a/wagtail/admin/tests/test_rich_text.py b/wagtail/admin/tests/test_rich_text.py index 2e838aff2..1169ea36e 100644 --- a/wagtail/admin/tests/test_rich_text.py +++ b/wagtail/admin/tests/test_rich_text.py @@ -8,7 +8,7 @@ from django.urls import reverse from wagtail.tests.testapp.models import SingleEventPage from wagtail.tests.testapp.rich_text import CustomRichTextArea from wagtail.tests.utils import WagtailTestUtils -from wagtail.admin.rich_text import HalloRichTextArea, get_rich_text_editor_widget +from wagtail.admin.rich_text import DraftailRichTextArea, HalloRichTextArea, get_rich_text_editor_widget from wagtail.core.blocks import RichTextBlock from wagtail.core.models import Page, get_page_models from wagtail.core.rich_text import RichText @@ -48,7 +48,7 @@ class TestGetRichTextEditorWidget(TestCase): if hasattr(settings, 'WAGTAILADMIN_RICH_TEXT_EDITORS'): del settings.WAGTAILADMIN_RICH_TEXT_EDITORS - self.assertIsInstance(get_rich_text_editor_widget(), HalloRichTextArea) + self.assertIsInstance(get_rich_text_editor_widget(), DraftailRichTextArea) @override_settings(WAGTAILADMIN_RICH_TEXT_EDITORS={ 'default': { @@ -79,7 +79,6 @@ class TestGetRichTextEditorWidget(TestCase): self.assertIsInstance(get_rich_text_editor_widget('custom'), CustomRichTextArea) -@override_settings() class TestDefaultRichText(BaseRichTextEditHandlerTestCase, WagtailTestUtils): def setUp(self): @@ -89,10 +88,59 @@ class TestDefaultRichText(BaseRichTextEditHandlerTestCase, WagtailTestUtils): self.login() + @override_settings() + def test_default_editor_in_rich_text_field(self): # Simulate the absence of a setting if hasattr(settings, 'WAGTAILADMIN_RICH_TEXT_EDITORS'): del settings.WAGTAILADMIN_RICH_TEXT_EDITORS + response = self.client.get(reverse( + 'wagtailadmin_pages:add', args=('tests', 'defaultrichtextfieldpage', self.root_page.id) + )) + + # Check status code + self.assertEqual(response.status_code, 200) + + # Check that draftail (default editor) initialisation is applied + self.assertContains(response, "window.draftail.initEditor('body',") + + # check that media for draftail is being imported + self.assertContains(response, 'wagtailadmin/js/draftail.js') + + @override_settings() + def test_default_editor_in_rich_text_block(self): + # Simulate the absence of a setting + if hasattr(settings, 'WAGTAILADMIN_RICH_TEXT_EDITORS'): + del settings.WAGTAILADMIN_RICH_TEXT_EDITORS + + response = self.client.get(reverse( + 'wagtailadmin_pages:add', args=('tests', 'defaultrichblockfieldpage', self.root_page.id) + )) + + # Check status code + self.assertEqual(response.status_code, 200) + + # Check that draftail (default editor) initialisation is applied + self.assertContains(response, "window.draftail.initEditor('__PREFIX__-value',") + + # check that media for draftail is being imported + self.assertContains(response, 'wagtailadmin/js/draftail.js') + + +@override_settings(WAGTAILADMIN_RICH_TEXT_EDITORS={ + 'default': { + 'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea' + }, +}) +class TestHalloRichText(BaseRichTextEditHandlerTestCase, WagtailTestUtils): + + def setUp(self): + super().setUp() + # Find root page + self.root_page = Page.objects.get(id=2) + + self.login() + def test_default_editor_in_rich_text_field(self): response = self.client.get(reverse( 'wagtailadmin_pages:add', args=('tests', 'defaultrichtextfieldpage', self.root_page.id) @@ -101,7 +149,7 @@ class TestDefaultRichText(BaseRichTextEditHandlerTestCase, WagtailTestUtils): # Check status code self.assertEqual(response.status_code, 200) - # Check that hallo (default editor by now) + # Check that hallo (default editor now) initialisation is applied self.assertContains(response, 'makeHalloRichTextEditable("id_body",') # check that media for the default hallo features (but not others) is being imported @@ -116,7 +164,7 @@ class TestDefaultRichText(BaseRichTextEditHandlerTestCase, WagtailTestUtils): # Check status code self.assertEqual(response.status_code, 200) - # Check that hallo (default editor by now) + # Check that hallo (default editor now) initialisation is applied self.assertContains(response, 'makeHalloRichTextEditable("__PREFIX__-value",') # check that media for the default hallo features (but not others) is being imported @@ -219,7 +267,6 @@ class TestRichTextValue(TestCase): ) self.root_page.add_child(instance=self.single_event_page) - def test_render(self): text = '
To the moon!
'.format( self.single_event_page.id @@ -275,6 +322,11 @@ class TestHalloJsWithCustomPluginOptions(BaseRichTextEditHandlerTestCase, Wagtai self.assertIn('makeHalloRichTextEditable("body", {"halloheadings": {"formatBlocks": ["p", "h2"]}});', form_html) +@override_settings(WAGTAILADMIN_RICH_TEXT_EDITORS={ + 'default': { + 'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea' + }, +}) class TestHalloJsWithFeaturesKwarg(BaseRichTextEditHandlerTestCase, WagtailTestUtils): def setUp(self): diff --git a/wagtail/core/tests/test_blocks.py b/wagtail/core/tests/test_blocks.py index 3f1721e32..4f40266cd 100644 --- a/wagtail/core/tests/test_blocks.py +++ b/wagtail/core/tests/test_blocks.py @@ -446,7 +446,7 @@ class TestRichTextBlock(TestCase): render_form should produce the editor-specific rendition of the rich text value (which includes e.g. 'data-linktype' attributes on elements) """ - block = blocks.RichTextBlock() + block = blocks.RichTextBlock(editor='hallo') value = RichText('Merry Christmas!
') result = block.render_form(value, prefix='richtext') self.assertIn( diff --git a/wagtail/core/tests/test_tests.py b/wagtail/core/tests/test_tests.py index f6086b23d..b4082b623 100644 --- a/wagtail/core/tests/test_tests.py +++ b/wagtail/core/tests/test_tests.py @@ -79,11 +79,13 @@ class TestWagtailPageTests(WagtailPageTests): self.assertCanNotCreateAt(EventIndex, EventPage) def test_assert_can_create(self): - self.assertFalse(EventIndex.objects.exists()) self.assertCanCreate(self.root, EventIndex, { 'title': 'Event Index', - 'intro': 'Event intro
'}) + 'intro': '''{"entityMap": {},"blocks": [ + {"inlineStyleRanges": [], "text": "Event intro", "depth": 0, "type": "unstyled", "key": "00000", "entityRanges": []} + ]}''' + }) self.assertTrue(EventIndex.objects.exists()) self.assertCanCreate(self.root, StreamPage, { @@ -93,7 +95,9 @@ class TestWagtailPageTests(WagtailPageTests): 'body-0-order': '0', 'body-0-deleted': '', 'body-1-type': 'rich_text', - 'body-1-value': 'Dit is onze mooie text in een ferrari
', + 'body-1-value': '''{"entityMap": {},"blocks": [ + {"inlineStyleRanges": [], "text": "Dit is onze mooie text in een ferrari", "depth": 0, "type": "unstyled", "key": "00000", "entityRanges": []} + ]}''', 'body-1-order': '1', 'body-1-deleted': '', 'body-count': '2' diff --git a/wagtail/snippets/tests.py b/wagtail/snippets/tests.py index 4b9e8d9c8..f53d6cd25 100644 --- a/wagtail/snippets/tests.py +++ b/wagtail/snippets/tests.py @@ -716,7 +716,7 @@ class TestInlinePanelMedia(TestCase, WagtailTestUtils): response = self.client.get(reverse('wagtailsnippets:add', args=('snippetstests', 'multisectionrichtextsnippet'))) self.assertEqual(response.status_code, 200) - self.assertContains(response, 'wagtailadmin/js/hallo-bootstrap.js') + self.assertContains(response, 'wagtailadmin/js/draftail.js') class TestSnippetChooserBlock(TestCase): diff --git a/wagtail/tests/settings.py b/wagtail/tests/settings.py index b2850b919..c3d79f1f0 100644 --- a/wagtail/tests/settings.py +++ b/wagtail/tests/settings.py @@ -203,6 +203,9 @@ WAGTAIL_USER_CUSTOM_FIELDS = ['country', 'attachment'] WAGTAILADMIN_RICH_TEXT_EDITORS = { 'default': { + 'WIDGET': 'wagtail.admin.rich_text.DraftailRichTextArea' + }, + 'hallo': { 'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea' }, 'custom': {