Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 69fa475

Browse filesBrowse files
committed
tests: add tests for custom serializer block + list bug
1 parent b79237f commit 69fa475
Copy full SHA for 69fa475

File tree

Expand file treeCollapse file tree

2 files changed

+35
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-0
lines changed
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"_key": "e5b6e416e6e9",
4+
"_type": "block",
5+
"children": [
6+
{ "_key": "3bbbff0f158b", "_type": "span", "marks": [], "text": "resers" }
7+
],
8+
"level": 1,
9+
"listItem": "bullet",
10+
"markDefs": [],
11+
"style": "normal"
12+
},
13+
{
14+
"_key": "73405dda68e0",
15+
"_type": "extraInfoBlock",
16+
"extraInfo": "This informations is not supported by Block",
17+
"markDefs": [],
18+
"style": "normal"
19+
}
20+
]

‎tests/test_rendering.py

Copy file name to clipboardExpand all lines: tests/test_rendering.py
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import html
22
import json
33
from pathlib import Path
4+
from typing import Optional
45

56
import pytest
67

78
from portabletext_html.renderer import MissingSerializerError, UnhandledNodeError, render
9+
from portabletext_html.types import Block
10+
11+
12+
def extraInfoSerializer(node: dict, context: Optional[Block], list_item: bool) -> str:
13+
extraInfo = node.get('extraInfo')
14+
15+
return f'<p>{extraInfo}</p>'
816

917

1018
def load_fixture(fixture_name) -> dict:
@@ -59,3 +67,10 @@ def test_invalid_node():
5967
fixture = load_fixture('invalid_node.json')
6068
with pytest.raises(UnhandledNodeError):
6169
render(fixture)
70+
71+
72+
def test_custom_serializer_node_after_list():
73+
fixture = load_fixture('custom_serializer_node_after_list.json')
74+
output = render(fixture, custom_serializers={'extraInfoBlock': extraInfoSerializer})
75+
76+
assert output == '<div><ul><li>resers</li></ul><p>This informations is not supported by Block</p></div>'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.