2022-10-05 23:46:34 -05:00
|
|
|
import 'dart:collection';
|
2022-10-04 22:39:55 -05:00
|
|
|
|
|
|
|
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
|
|
|
|
|
|
class MockNode extends Mock implements Node {}
|
|
|
|
|
|
|
|
|
|
void main() {
|
2023-03-09 14:38:54 +07:00
|
|
|
group('node_extension.dart', () {
|
2022-10-04 22:39:55 -05:00
|
|
|
final selection = Selection(
|
2022-10-05 23:46:34 -05:00
|
|
|
start: Position(path: [0]),
|
|
|
|
|
end: Position(path: [1]),
|
2022-10-04 22:39:55 -05:00
|
|
|
);
|
|
|
|
|
|
2022-10-05 23:46:34 -05:00
|
|
|
test('inSelection', () {
|
|
|
|
|
// I use an empty implementation instead of mock, because the mocked
|
|
|
|
|
// version throws error trying to access the path.
|
|
|
|
|
|
|
|
|
|
final subLinkedList = LinkedList<Node>()
|
|
|
|
|
..addAll([
|
|
|
|
|
Node(type: 'type', children: LinkedList(), attributes: {}),
|
|
|
|
|
Node(type: 'type', children: LinkedList(), attributes: {}),
|
|
|
|
|
Node(type: 'type', children: LinkedList(), attributes: {}),
|
|
|
|
|
Node(type: 'type', children: LinkedList(), attributes: {}),
|
|
|
|
|
Node(type: 'type', children: LinkedList(), attributes: {}),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
final linkedList = LinkedList<Node>()
|
|
|
|
|
..addAll([
|
|
|
|
|
Node(
|
|
|
|
|
type: 'type',
|
|
|
|
|
children: subLinkedList,
|
|
|
|
|
attributes: {},
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
final node = Node(
|
|
|
|
|
type: 'type',
|
|
|
|
|
children: linkedList,
|
|
|
|
|
attributes: {},
|
|
|
|
|
);
|
|
|
|
|
final result = node.inSelection(selection);
|
|
|
|
|
expect(result, false);
|
|
|
|
|
});
|
2023-03-09 14:38:54 +07:00
|
|
|
|
2023-03-24 13:59:03 +01:00
|
|
|
test('inSelection w/ Reverse selection', () {
|
|
|
|
|
final linkedList = LinkedList<Node>()
|
|
|
|
|
..addAll([
|
|
|
|
|
Node(
|
|
|
|
|
type: 'type',
|
|
|
|
|
attributes: {},
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
final node = Node(
|
|
|
|
|
type: 'type',
|
|
|
|
|
children: linkedList,
|
|
|
|
|
attributes: {},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final reverseSelection = Selection(
|
|
|
|
|
start: Position(path: [1]),
|
|
|
|
|
end: Position(path: [0]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final result = node.inSelection(reverseSelection);
|
|
|
|
|
expect(result, false);
|
|
|
|
|
});
|
2022-10-04 22:39:55 -05:00
|
|
|
});
|
|
|
|
|
}
|