@@ -86,7 +86,11 @@ def test_display_no_fields():
86
86
# insert_assert(d.model_dump(by_alias=True, exclude_none=True))
87
87
assert d .model_dump (by_alias = True , exclude_none = True ) == {
88
88
'data' : {'id' : 1 , 'name' : 'john' , 'representation' : '1: john' },
89
- 'fields' : [{'field' : 'id' }, {'title' : 'Name' , 'field' : 'name' }],
89
+ 'fields' : [
90
+ {'field' : 'id' },
91
+ {'title' : 'Name' , 'field' : 'name' },
92
+ {'title' : 'Representation' , 'field' : 'representation' },
93
+ ],
90
94
'type' : 'Details' ,
91
95
}
92
96
@@ -102,3 +106,41 @@ def test_display_fields():
102
106
'fields' : [{'title' : 'ID' , 'field' : 'id' }, {'title' : 'Name' , 'field' : 'name' }],
103
107
'type' : 'Details' ,
104
108
}
109
+
110
+
111
+ def test_table_respect_computed_field_title ():
112
+ class Foo (BaseModel ):
113
+ id : int
114
+
115
+ @computed_field (title = 'Foo Name' )
116
+ def name (self ) -> str :
117
+ return f'foo{ self .id } '
118
+
119
+ foos = [Foo (id = 1 )]
120
+ table = components .Table (data = foos )
121
+
122
+ # insert_assert(table.model_dump(by_alias=True, exclude_none=True))
123
+ assert table .model_dump (by_alias = True , exclude_none = True ) == {
124
+ 'data' : [{'id' : 1 , 'name' : 'foo1' }],
125
+ 'columns' : [{'field' : 'id' }, {'title' : 'Foo Name' , 'field' : 'name' }],
126
+ 'type' : 'Table' ,
127
+ }
128
+
129
+
130
+ def test_details_respect_computed_field_title ():
131
+ class Foo (BaseModel ):
132
+ id : int
133
+
134
+ @computed_field (title = 'Foo Name' )
135
+ def name (self ) -> str :
136
+ return f'foo{ self .id } '
137
+
138
+ foos = Foo (id = 1 )
139
+ details = components .Details (data = foos )
140
+
141
+ # insert_assert(table.model_dump(by_alias=True, exclude_none=True))
142
+ assert details .model_dump (by_alias = True , exclude_none = True ) == {
143
+ 'data' : {'id' : 1 , 'name' : 'foo1' },
144
+ 'fields' : [{'field' : 'id' }, {'title' : 'Foo Name' , 'field' : 'name' }],
145
+ 'type' : 'Details' ,
146
+ }
0 commit comments