test: add delete node test

This commit is contained in:
Lucas.Xu 2022-07-11 21:14:32 +08:00
parent d2e62f882b
commit 9e4227d3d2
2 changed files with 13 additions and 3 deletions

View File

@ -14,6 +14,13 @@
"tag": "*"
},
"children": [
{
"type": "text",
"attributes": {
"text-type": "heading2",
"check": true
}
},
{
"type": "text",
"attributes": {

View File

@ -42,19 +42,22 @@ void main() {
final String response = await rootBundle.loadString('assets/document.json');
final data = Map<String, Object>.from(json.decode(response));
final stateTree = StateTree.fromJson(data);
final deletedNode = stateTree.delete([1, 0]);
final deletedNode = stateTree.delete([1, 1]);
expect(deletedNode != null, true);
expect(deletedNode!.attributes['text-type'], 'check-box');
final node = stateTree.nodeAtPath([1, 1]);
expect(node != null, true);
expect(node!.attributes['tag'], '**');
});
test('update node in state tree', () async {
final String response = await rootBundle.loadString('assets/document.json');
final data = Map<String, Object>.from(json.decode(response));
final stateTree = StateTree.fromJson(data);
final attributes = stateTree.update([1, 0], {'text-type': 'heading1'});
final attributes = stateTree.update([1, 1], {'text-type': 'heading1'});
expect(attributes != null, true);
expect(attributes!['text-type'], 'check-box');
final updatedNode = stateTree.nodeAtPath([1, 0]);
final updatedNode = stateTree.nodeAtPath([1, 1]);
expect(updatedNode != null, true);
expect(updatedNode!.attributes['text-type'], 'heading1');
});