Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: unit tests
Vincent Chan8bd748d7cd61
diff --git a/frontend/app_flowy/packages/flowy_editor/lib/document/text_delta.dart b/frontend/app_flowy/packages/flowy_editor/lib/document/text_delta.dartindex 8d05099291..c53d243137 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/document/text_delta.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/document/text_delta.dart@@ -22,7 +22,8 @@ class TextOperation {}int _hashAttributes(Attributes attributes) {- return Object.hashAllUnordered(attributes.entries);+ return Object.hashAllUnordered(+ attributes.entries.map((e) => Object.hash(e.key, e.value)));}class TextInsert extends TextOperation {@@ -335,7 +336,7 @@ class Delta {if (otherOp is TextRetain && otherOp.length > 0) {TextOperation? newOp;if (thisOp is TextRetain) {- newOp = TextRetain(length: otherOp.length, attributes: attributes);+ newOp = TextRetain(length: length, attributes: attributes);} else if (thisOp is TextInsert) {newOp = TextInsert(thisOp.content, attributes);}@@ -363,7 +364,7 @@ class Delta {var ops = [...operations];if (other.operations.isNotEmpty) {ops.add(other.operations[0]);- ops = ops.sublist(1);+ ops.addAll(other.operations.sublist(1));}return Delta(ops);}@@ -399,15 +400,15 @@ Attributes? _composeMap(Attributes? a, Attributes? b) {final attributes = <String, Object>{};attributes.addAll(b);- if (attributes.isEmpty) {- return null;- }-for (final entry in a.entries) {if (!b.containsKey(entry.key)) {attributes[entry.key] = entry.value;}}+ if (attributes.isEmpty) {+ return null;+ }+return attributes;}diff --git a/frontend/app_flowy/packages/flowy_editor/test/delta_test.dart b/frontend/app_flowy/packages/flowy_editor/test/delta_test.dartindex 1123ad1bc0..f90d487b18 100644--- a/frontend/app_flowy/packages/flowy_editor/test/delta_test.dart+++ b/frontend/app_flowy/packages/flowy_editor/test/delta_test.dart@@ -73,16 +73,16 @@ void main() {final expected = Delta().delete(2);expect(a.compose(b), expected);});- // test('retain + insert', () {- // final a = Delta().retain(1, {- // 'color': 'blue'- // });- // final b = Delta().insert('B');- // final expected = Delta().insert('B').retain(1, {- // 'color': 'blue',- // });- // expect(a.compose(b), expected);- // });+ test('retain + insert', () {+ final a = Delta().retain(1, {+ 'color': 'blue'+ });+ final b = Delta().insert('B');+ final expected = Delta().insert('B').retain(1, {+ 'color': 'blue',+ });+ expect(a.compose(b), expected);+ });test('retain + retain', () {final a = Delta().retain(1, {'color': 'blue',@@ -105,12 +105,12 @@ void main() {final expected = Delta().delete(1);expect(a.compose(b), expected);});- // test('insert in middle of text', () {- // final a = Delta().insert('Hello');- // final b = Delta().retain(3).insert('X');- // final expected = Delta().insert('HElXlo');- // expect(a.compose(b), expected);- // });+ test('insert in middle of text', () {+ final a = Delta().insert('Hello');+ final b = Delta().retain(3).insert('X');+ final expected = Delta().insert('HelXlo');+ expect(a.compose(b), expected);+ });test('insert and delete ordering', () {final a = Delta().insert('Hello');final b = Delta().insert('Hello');@@ -147,29 +147,29 @@ void main() {.delete(1);expect(a.compose(b), expected);});- // test('retain end optimization', () {- // final a = Delta()- // .insert('A', {'bold': true})- // .insert('B')- // .insert('C', {'bold': true});- // final b = Delta().delete(1);- // final expected = Delta().insert('B').insert('C', {'bold': true});- // expect(a.compose(b), expected);- // });- // test('retain end optimization join', () {- // final a = Delta()- // .insert('A', {'bold': true})- // .insert('B')- // .insert('C', {'bold': true})- // .insert('D')- // .insert('E', {'bold': true})- // .insert('F');- // final b = Delta().retain(1).delete(1);- // final expected = Delta()- // .insert('AC', {'bold': true})- // .insert('D')- // .insert('E', {'bold': true})- // .insert('F');- // expect(a.compose(b), expected);- // });+ test('retain end optimization', () {+ final a = Delta()+ .insert('A', {'bold': true})+ .insert('B')+ .insert('C', {'bold': true});+ final b = Delta().delete(1);+ final expected = Delta().insert('B').insert('C', {'bold': true});+ expect(a.compose(b), expected);+ });+ test('retain end optimization join', () {+ final a = Delta()+ .insert('A', {'bold': true})+ .insert('B')+ .insert('C', {'bold': true})+ .insert('D')+ .insert('E', {'bold': true})+ .insert('F');+ final b = Delta().retain(1).delete(1);+ final expected = Delta()+ .insert('AC', {'bold': true})+ .insert('D')+ .insert('E', {'bold': true})+ .insert('F');+ expect(a.compose(b), expected);+ });}