3232from ultimate_notion .blocks import (
3333 TableOfContents as UnoTableOfContents ,
3434)
35+ from ultimate_notion .blocks import (
36+ ToggleItem as UnoToggleItem ,
37+ )
3538from ultimate_notion .core import NotionObject
3639from ultimate_notion .obj_api .core import GenericObject
3740from ultimate_notion .obj_api .enums import CodeLang , Color
@@ -62,12 +65,14 @@ def _assert_rst_converts_to_notion_objects(
6265 expected_objects : list [NotionObject [Any ]],
6366 make_app : Callable [..., SphinxTestApp ],
6467 tmp_path : Path ,
68+ extensions : tuple [str , ...] = ("sphinx_notion" ,),
6569) -> None :
6670 """
6771 The given rST content is converted to the given expected objects.
6872 """
6973 srcdir = tmp_path / "src"
7074 srcdir .mkdir ()
75+
7176 (srcdir / "conf.py" ).write_text (data = "" )
7277
7378 cleaned_content = textwrap .dedent (text = rst_content ).strip ()
@@ -77,7 +82,7 @@ def _assert_rst_converts_to_notion_objects(
7782 srcdir = srcdir ,
7883 builddir = tmp_path / "build" ,
7984 buildername = "notion" ,
80- confoverrides = {"extensions" : [ "sphinx_notion" ] },
85+ confoverrides = {"extensions" : list ( extensions ) },
8186 )
8287 app .build ()
8388
@@ -1007,3 +1012,51 @@ def test_nested_bullet_list_error_on_excessive_depth(
10071012 make_app = make_app ,
10081013 tmp_path = tmp_path ,
10091014 )
1015+
1016+
1017+ def test_collapse_block (
1018+ * ,
1019+ make_app : Callable [..., SphinxTestApp ],
1020+ tmp_path : Path ,
1021+ ) -> None :
1022+ """
1023+ Test that collapse directives convert to Notion ToggleItem blocks.
1024+ """
1025+ rst_content = """
1026+ Regular paragraph.
1027+
1028+ .. collapse:: Click to expand
1029+
1030+ This content is hidden by default.
1031+
1032+ It supports **formatting**.
1033+
1034+ Another paragraph.
1035+ """
1036+
1037+ toggle_block = UnoToggleItem (text = "Click to expand" )
1038+
1039+ nested_para1 = UnoParagraph (text = "This content is hidden by default." )
1040+ nested_para2 = UnoParagraph (text = "It supports formatting." )
1041+ nested_para2 .rich_text = (
1042+ text (text = "It supports " , bold = False )
1043+ + text (text = "formatting" , bold = True )
1044+ + text (text = "." , bold = False )
1045+ )
1046+
1047+ toggle_block .obj_ref .value .children .append (nested_para1 .obj_ref ) # pyright: ignore[reportUnknownMemberType]
1048+ toggle_block .obj_ref .value .children .append (nested_para2 .obj_ref ) # pyright: ignore[reportUnknownMemberType]
1049+
1050+ expected_objects : list [NotionObject [Any ]] = [
1051+ UnoParagraph (text = "Regular paragraph." ),
1052+ toggle_block ,
1053+ UnoParagraph (text = "Another paragraph." ),
1054+ ]
1055+
1056+ _assert_rst_converts_to_notion_objects (
1057+ rst_content = rst_content ,
1058+ expected_objects = expected_objects ,
1059+ make_app = make_app ,
1060+ tmp_path = tmp_path ,
1061+ extensions = ("sphinx_notion" , "sphinx_toolbox.collapse" ),
1062+ )
0 commit comments