diff --git a/components/ui/context_menu.py b/components/ui/context_menu.py index 51444d64..b38f8dda 100644 --- a/components/ui/context_menu.py +++ b/components/ui/context_menu.py @@ -344,7 +344,7 @@ class ContextMenuShortcut(Span, CoreComponent): @classmethod def create(cls, *children, **props) -> Span: props["data-slot"] = "context-menu-shortcut" - props["class_name"] = ClassNames.SHORTCUT + cls.set_class_name(ClassNames.SHORTCUT, props) return super().create(*children, **props) diff --git a/tests/test_context_menu.py b/tests/test_context_menu.py new file mode 100644 index 00000000..f41d9ba9 --- /dev/null +++ b/tests/test_context_menu.py @@ -0,0 +1,34 @@ +import sys +from pathlib import Path + +ROOT_DIR = Path(__file__).parent.parent +sys.path.insert(0, str(ROOT_DIR)) + +from components.ui.context_menu import ClassNames, ContextMenuShortcut # noqa: E402 + + +def test_context_menu_shortcut_uses_default_classes() -> None: + shortcut = ContextMenuShortcut.create("Ctrl+C") + + assert ClassNames.SHORTCUT in str(shortcut.class_name) + + +def test_context_menu_shortcut_merges_custom_class_name() -> None: + shortcut = ContextMenuShortcut.create("Ctrl+C", class_name="custom-shortcut") + + assert ClassNames.SHORTCUT in str(shortcut.class_name) + assert "custom-shortcut" in str(shortcut.class_name) + + +def test_context_menu_shortcut_unstyled_omits_default_classes() -> None: + shortcut = ContextMenuShortcut.create("Ctrl+C", unstyled=True) + + assert str(shortcut.class_name) == "" + + +def test_context_menu_shortcut_unstyled_keeps_custom_class_name() -> None: + shortcut = ContextMenuShortcut.create( + "Ctrl+C", class_name="custom-shortcut", unstyled=True + ) + + assert str(shortcut.class_name) == "custom-shortcut"