kopia lustrzana https://github.com/wagtail/wagtail
add basic tableblock full page test
rodzic
68ccec22d9
commit
05beebf51f
|
@ -1,10 +1,13 @@
|
|||
import json
|
||||
|
||||
from django.test import SimpleTestCase, TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import translation
|
||||
from django.utils.html import escape
|
||||
|
||||
from wagtail.contrib.table_block.blocks import DEFAULT_TABLE_OPTIONS, TableBlock
|
||||
from wagtail.core.models import Page
|
||||
from wagtail.tests.testapp.models import TableBlockStreamPage
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
|
||||
|
||||
|
@ -311,3 +314,49 @@ class TestTableBlockForm(WagtailTestUtils, SimpleTestCase):
|
|||
self.assertIn('<div class="field char_field widget-table_input">', html)
|
||||
# check that options render in the init function
|
||||
self.assertIn(json.dumps(block.table_options), html)
|
||||
|
||||
def test_searchable_content(self):
|
||||
"""
|
||||
Test searchable content is created correctly.
|
||||
"""
|
||||
block = TableBlock()
|
||||
search_content = block.get_searchable_content(value=self.value)
|
||||
self.assertIn('Galactica', search_content)
|
||||
self.assertIn('Brenik', search_content)
|
||||
|
||||
|
||||
class TestTableBlockPageEdit(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
self.value = {
|
||||
'first_row_is_table_header': True,
|
||||
'first_col_is_header': True,
|
||||
'data': [
|
||||
['Ship', 'Type', 'Status'],
|
||||
['Galactica', 'Battlestar', 'Active'],
|
||||
['Valkyrie', 'Battlestar', 'Destroyed'],
|
||||
['Cylon Basestar', 'Basestar', 'Active'],
|
||||
['Brenik', 'Small Military Vessel', 'Destroyed'],
|
||||
]
|
||||
}
|
||||
self.root_page = Page.objects.get(id=2)
|
||||
table_block_page_instance = TableBlockStreamPage(
|
||||
title='Ships',
|
||||
table=json.dumps([{'type': 'table', 'value': self.value}])
|
||||
)
|
||||
self.table_block_page = self.root_page.add_child(instance=table_block_page_instance)
|
||||
self.user = self.login()
|
||||
|
||||
def test_page_edit_page_view(self):
|
||||
"""
|
||||
Test that edit page loads with saved table data and correct init function.
|
||||
"""
|
||||
response = self.client.get(reverse('wagtailadmin_pages:edit', args=(self.table_block_page.id,)))
|
||||
# check page + field renders
|
||||
self.assertContains(response, '<div class="field char_field widget-table_input fieldname-table">')
|
||||
# check data
|
||||
self.assertContains(response, 'Battlestar')
|
||||
self.assertContains(response, 'Galactica')
|
||||
# check init
|
||||
self.assertContains(response, 'initTable("table-0-value"')
|
||||
self.assertContains(response, 'minSpareRows')
|
||||
self.assertContains(response, 'startRows')
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.6 on 2017-12-03 08:19
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import wagtail.contrib.table_block.blocks
|
||||
import wagtail.core.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0040_page_draft_title'),
|
||||
('tests', '0023_formpagewithredirect_redirectformfield'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='TableBlockStreamPage',
|
||||
fields=[
|
||||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
|
||||
('table', wagtail.core.fields.StreamField((('table', wagtail.contrib.table_block.blocks.TableBlock()),))),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
bases=('wagtailcore.page',),
|
||||
),
|
||||
]
|
|
@ -16,18 +16,19 @@ from modelcluster.models import ClusterableModel
|
|||
from taggit.managers import TaggableManager
|
||||
from taggit.models import TaggedItemBase
|
||||
|
||||
from wagtail.contrib.settings.models import BaseSetting, register_setting
|
||||
from wagtail.admin.edit_handlers import (
|
||||
FieldPanel, InlinePanel, MultiFieldPanel, ObjectList, PageChooserPanel, StreamFieldPanel,
|
||||
TabbedInterface)
|
||||
FieldPanel, InlinePanel, MultiFieldPanel, ObjectList, PageChooserPanel,
|
||||
StreamFieldPanel, TabbedInterface)
|
||||
from wagtail.admin.forms import WagtailAdminPageForm
|
||||
from wagtail.admin.utils import send_mail
|
||||
from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField, AbstractFormSubmission
|
||||
from wagtail.contrib.settings.models import BaseSetting, register_setting
|
||||
from wagtail.contrib.table_block.blocks import TableBlock
|
||||
from wagtail.core.blocks import CharBlock, RichTextBlock
|
||||
from wagtail.core.fields import RichTextField, StreamField
|
||||
from wagtail.core.models import Orderable, Page, PageManager, PageQuerySet
|
||||
from wagtail.documents.edit_handlers import DocumentChooserPanel
|
||||
from wagtail.documents.models import AbstractDocument, Document
|
||||
from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField, AbstractFormSubmission
|
||||
from wagtail.images.blocks import ImageChooserBlock
|
||||
from wagtail.images.edit_handlers import ImageChooserPanel
|
||||
from wagtail.images.models import AbstractImage, AbstractRendition, Image
|
||||
|
@ -1025,6 +1026,12 @@ class InlineStreamPage(Page):
|
|||
]
|
||||
|
||||
|
||||
class TableBlockStreamPage(Page):
|
||||
table = StreamField([('table', TableBlock())])
|
||||
|
||||
content_panels = [StreamFieldPanel('table')]
|
||||
|
||||
|
||||
class UserProfile(models.Model):
|
||||
# Wagtail's schema must be able to coexist alongside a custom UserProfile model
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
|
|
Ładowanie…
Reference in New Issue