Skip to content

Commit

Permalink
add test cases for indent and outdent commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahad-patel committed Sep 30, 2024
1 parent ef475ef commit 591361e
Show file tree
Hide file tree
Showing 3 changed files with 661 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,151 @@ void main() async {
expect(nestedBlockAfter?.indentPadding.left, _padding);
expect(nestedBlockAfter?.indentPadding.right, 0);

await editor.dispose();
});
});
group('indentCommand (multi-line) - widget test multi-line indent padding',
() {
testWidgets("indent 2 LTR lines under LTR line", (tester) async {
final editor = await multiLineIndentTestHelper(
tester,
('Hello', blockComponentTextDirectionLTR),
('Will indent this', blockComponentTextDirectionLTR),
('Third Line', blockComponentTextDirectionLTR),
);

final node = editor.nodeAtPath([0])!;
final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, _padding);
expect(nestedBlock?.indentPadding.right, 0);

await editor.dispose();
});

testWidgets("indent two LTR lines under RTL line", (tester) async {
final editor = await multiLineIndentTestHelper(
tester,
('سلام', blockComponentTextDirectionRTL),
('Will indent this', blockComponentTextDirectionLTR),
('Third Line', blockComponentTextDirectionLTR),
);

final node = editor.nodeAtPath([0])!;
final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, _padding);
expect(nestedBlock?.indentPadding.right, 0);

await editor.dispose();
});

testWidgets("indent two RTL lines under RTL line", (tester) async {
final editor = await multiLineIndentTestHelper(
tester,
('سلام', blockComponentTextDirectionRTL),
('خط دوم', blockComponentTextDirectionRTL),
('خط سوم', blockComponentTextDirectionRTL),
);

await editor.pressKey(key: LogicalKeyboardKey.tab);
await tester.pumpAndSettle();

final node = editor.nodeAtPath([0])!;
final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, _padding);

await editor.dispose();
});

testWidgets("indent two RTL lines under LTR line", (tester) async {
final editor = await multiLineIndentTestHelper(
tester,
('Hello', blockComponentTextDirectionLTR),
('خط دوم', blockComponentTextDirectionRTL),
('خط سوم', blockComponentTextDirectionRTL),
);

await editor.pressKey(key: LogicalKeyboardKey.tab);
await tester.pumpAndSettle();

final node = editor.nodeAtPath([0])!;
final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, _padding);

await editor.dispose();
});

testWidgets("indent one RTL line and one LTR line under LTR line",
(tester) async {
final editor = await multiLineIndentTestHelper(
tester,
('Hello', blockComponentTextDirectionLTR),
('خط دوم', blockComponentTextDirectionRTL),
('Third Line', blockComponentTextDirectionLTR),
);

await editor.pressKey(key: LogicalKeyboardKey.tab);
await tester.pumpAndSettle();

final node = editor.nodeAtPath([0])!;
final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, _padding);

await editor.dispose();
});

testWidgets("indent one LTR line and one RTL lines under RTL line",
(tester) async {
final editor = await multiLineIndentTestHelper(
tester,
('سلام', blockComponentTextDirectionRTL),
('Will indent this', blockComponentTextDirectionLTR),
('خط سوم', blockComponentTextDirectionRTL),
);

await editor.pressKey(key: LogicalKeyboardKey.tab);
await tester.pumpAndSettle();

final node = editor.nodeAtPath([0])!;
final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, _padding);
expect(nestedBlock?.indentPadding.right, 0);

await editor.dispose();
});

testWidgets("indent AUTO line under AUTO line", (tester) async {
final editor = await multiLineIndentTestHelper(
tester,
('سلام', blockComponentTextDirectionAuto),
('خط دوم', blockComponentTextDirectionAuto),
('خط سوم', blockComponentTextDirectionAuto),
);

await editor.pressKey(key: LogicalKeyboardKey.tab);
await tester.pumpAndSettle();

final node = editor.nodeAtPath([0])!;
final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, _padding);

await editor.dispose();
});
});
Expand Down Expand Up @@ -170,3 +315,31 @@ Future<TestableEditor> indentTestHelper(

return editor;
}

Future<TestableEditor> multiLineIndentTestHelper(
WidgetTester tester,
TestLine firstLine,
TestLine secondLine,
TestLine thirdLine,
) async {
final editor = tester.editor
..addNode(paragraphNode(text: firstLine.$1, textDirection: firstLine.$2))
..addNode(paragraphNode(text: secondLine.$1, textDirection: secondLine.$2))
..addNode(paragraphNode(text: thirdLine.$1, textDirection: thirdLine.$2));
await editor.startTesting();

final selection = Selection(
start: Position(path: [1], offset: 1),
end: Position(path: [2], offset: 1),
);
await editor.updateSelection(selection);

await editor.pressKey(key: LogicalKeyboardKey.tab);
await tester.pumpAndSettle();

final node = editor.nodeAtPath([0])!;
expect(node.delta?.toPlainText(), firstLine.$1);
expect(node.children.every((element) => element.level == 2), true);

return editor;
}
Loading

0 comments on commit 591361e

Please sign in to comment.