11
11
current_hook ,
12
12
strictly_equal ,
13
13
)
14
- from idom .core .layout import Layout
15
- from idom .core .serve import render_json_patch
14
+ from idom .core .layout import Layout , LayoutUpdate
16
15
from idom .testing import DisplayFixture , HookCatcher , assert_idom_did_log , poll
17
16
from idom .testing .logs import assert_idom_did_not_log
18
17
from idom .utils import Ref
19
- from tests .tooling .asserts import assert_same_items
20
18
21
19
22
20
async def test_must_be_rendering_in_layout_to_use_hooks ():
@@ -42,31 +40,35 @@ def SimpleStatefulComponent():
42
40
sse = SimpleStatefulComponent ()
43
41
44
42
async with idom .Layout (sse ) as layout :
45
- patch_1 = await render_json_patch (layout )
46
- assert patch_1 .path == ""
47
- assert_same_items (
48
- patch_1 .changes ,
49
- [
50
- {"op" : "add" , "path" : "/tagName" , "value" : "" },
51
- {
52
- "op" : "add" ,
53
- "path" : "/children" ,
54
- "value" : [{"children" : ["0" ], "tagName" : "div" }],
55
- },
56
- ],
43
+ update_1 = await layout .render ()
44
+ assert update_1 == LayoutUpdate (
45
+ path = "" ,
46
+ old = None ,
47
+ new = {
48
+ "tagName" : "" ,
49
+ "children" : [{"tagName" : "div" , "children" : ["0" ]}],
50
+ },
57
51
)
58
52
59
- patch_2 = await render_json_patch (layout )
60
- assert patch_2 .path == ""
61
- assert patch_2 .changes == [
62
- {"op" : "replace" , "path" : "/children/0/children/0" , "value" : "1" }
63
- ]
64
-
65
- patch_3 = await render_json_patch (layout )
66
- assert patch_3 .path == ""
67
- assert patch_3 .changes == [
68
- {"op" : "replace" , "path" : "/children/0/children/0" , "value" : "2" }
69
- ]
53
+ update_2 = await layout .render ()
54
+ assert update_2 == LayoutUpdate (
55
+ path = "" ,
56
+ old = update_1 .new ,
57
+ new = {
58
+ "tagName" : "" ,
59
+ "children" : [{"tagName" : "div" , "children" : ["1" ]}],
60
+ },
61
+ )
62
+
63
+ update_3 = await layout .render ()
64
+ assert update_3 == LayoutUpdate (
65
+ path = "" ,
66
+ old = update_2 .new ,
67
+ new = {
68
+ "tagName" : "" ,
69
+ "children" : [{"tagName" : "div" , "children" : ["2" ]}],
70
+ },
71
+ )
70
72
71
73
72
74
async def test_set_state_callback_identity_is_preserved ():
0 commit comments