52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
"""Tests for the admin-UI hooks in dnscms/wagtail_hooks.py.
|
|
|
|
Both hooks run against Wagtail admin internals (the page action menu, editor
|
|
JS injection) — the surface most likely to churn silently across Wagtail
|
|
upgrades.
|
|
"""
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from dnscms.wagtail_hooks import editor_js, make_publish_default_action
|
|
|
|
|
|
@dataclass
|
|
class FakeMenuItem:
|
|
name: str
|
|
|
|
|
|
def _names(items):
|
|
return [item.name for item in items]
|
|
|
|
|
|
def test_make_publish_default_action_moves_publish_first():
|
|
menu_items = [
|
|
FakeMenuItem("action-save-draft"),
|
|
FakeMenuItem("action-submit"),
|
|
FakeMenuItem("action-publish"),
|
|
FakeMenuItem("action-unpublish"),
|
|
]
|
|
|
|
make_publish_default_action(menu_items, request=None, context={})
|
|
|
|
assert _names(menu_items) == [
|
|
"action-publish",
|
|
"action-save-draft",
|
|
"action-submit",
|
|
"action-unpublish",
|
|
]
|
|
|
|
|
|
def test_make_publish_default_action_without_publish_is_a_noop():
|
|
menu_items = [FakeMenuItem("action-save-draft"), FakeMenuItem("action-submit")]
|
|
|
|
make_publish_default_action(menu_items, request=None, context={})
|
|
|
|
assert _names(menu_items) == ["action-save-draft", "action-submit"]
|
|
|
|
|
|
def test_editor_js_returns_script_tag():
|
|
html = editor_js()
|
|
assert html.startswith("<script src=")
|
|
assert "js/page-editor.js" in html
|