diff --git a/wagtail/wagtailadmin/tests/test_blocks.py b/wagtail/wagtailadmin/tests/test_blocks.py index 2de2aeb5d..759c47dc6 100644 --- a/wagtail/wagtailadmin/tests/test_blocks.py +++ b/wagtail/wagtailadmin/tests/test_blocks.py @@ -201,6 +201,20 @@ class TestStructBlock(unittest.TestCase): self.assertIn('
', html) self.assertIn('', html) + def test_render_form_uses_default_value(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField(), default="Torchbox") + link = blocks.FieldBlock(forms.URLField(), default="http://www.torchbox.com") + + block = LinkBlock() + html = block.render_form({}, prefix='mylink') + + self.assertIn('
', html) + self.assertIn('
', html) + self.assertIn('', html) + self.assertIn('
', html) + self.assertIn('', html) + class TestListBlock(unittest.TestCase): def test_initialise_with_class(self): @@ -261,7 +275,7 @@ class TestListBlock(unittest.TestCase): html = self.render_form() self.assertIn('', html) - self.assertIn('', html) + self.assertIn('', html) def test_render_form_values(self): html = self.render_form() @@ -271,6 +285,28 @@ class TestListBlock(unittest.TestCase): self.assertIn('', html) self.assertIn('', html) + def test_html_declarations(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField()) + link = blocks.FieldBlock(forms.URLField()) + + block = blocks.ListBlock(LinkBlock) + html = block.html_declarations() + + self.assertIn('', html) + self.assertIn('', html) + + def test_html_declarations_uses_default(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField(), default="Github") + link = blocks.FieldBlock(forms.URLField(), default="http://www.github.com") + + block = blocks.ListBlock(LinkBlock) + html = block.html_declarations() + + self.assertIn('', html) + self.assertIn('', html) + class TestStreamBlock(unittest.TestCase): def test_initialisation(self): @@ -426,3 +462,54 @@ class TestStreamBlock(unittest.TestCase): self.assertIn('', html) self.assertIn('', html) self.assertIn('', html) + + def test_render_form_uses_default_value(self): + class ArticleBlock(blocks.StreamBlock): + heading = blocks.FieldBlock(forms.CharField(), ) + paragraph = blocks.FieldBlock(forms.CharField()) + + default = [ + { + 'type': 'heading', + 'value': "My title", + } + ] + + block = ArticleBlock() + value = block.to_python([ + { + 'type': 'heading', + 'value': "My title", + }, + { + 'type': 'paragraph', + 'value': 'My first paragraph', + }, + { + 'type': 'paragraph', + 'value': 'My second paragraph', + }, + ]) + return block.render_form(value, prefix='myarticle') + + def test_html_declarations(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField()) + link = blocks.FieldBlock(forms.URLField()) + + block = blocks.ListBlock(LinkBlock) + html = block.html_declarations() + + self.assertIn('', html) + self.assertIn('', html) + + def test_html_declarations_uses_default(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField(), default="Github") + link = blocks.FieldBlock(forms.URLField(), default="http://www.github.com") + + block = blocks.ListBlock(LinkBlock) + html = block.html_declarations() + + self.assertIn('', html) + self.assertIn('', html)