Skip to content

Commit

Permalink
Add more tests for CompositionAwareMixin (flutter#44717)
Browse files Browse the repository at this point in the history
Adds missing tests for `CompositionAwareMixin`. Check flutter#44139 (comment) and flutter#44139 (comment)

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
  • Loading branch information
Amir-P authored and gaaclarke committed Aug 30, 2023
1 parent 6b739bf commit 824bb0d
Showing 1 changed file with 80 additions and 9 deletions.
89 changes: 80 additions & 9 deletions lib/web_ui/test/engine/composition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,81 @@ Future<void> testMain() async {
});

group('determine composition state', () {
test('should return new composition state - compositing middle of text', () {
const int baseOffset = 100;
test('should return editing state if extentOffset is null', () {
final EditingState editingState = EditingState(text: 'Test');

final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin =
_MockWithCompositionAwareMixin();
mockWithCompositionAwareMixin.composingText = 'Test';

expect(
mockWithCompositionAwareMixin.determineCompositionState(editingState),
editingState,
);
});

test('should return editing state if composingText is null', () {
final EditingState editingState = EditingState(
text: 'Test',
baseOffset: 0,
extentOffset: 4,
);

final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin =
_MockWithCompositionAwareMixin();

expect(
mockWithCompositionAwareMixin.determineCompositionState(editingState),
editingState,
);
});

test('should return editing state if text is null', () {
final EditingState editingState = EditingState(
baseOffset: 0,
extentOffset: 0,
);

final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin =
_MockWithCompositionAwareMixin();
mockWithCompositionAwareMixin.composingText = 'Test';

expect(
mockWithCompositionAwareMixin.determineCompositionState(editingState),
editingState,
);
});

test(
'should return editing state if extentOffset is smaller than composingText length',
() {
const String composingText = 'composeMe';

final EditingState editingState = EditingState(
extentOffset: baseOffset,
text: 'testing',
text: 'Test',
baseOffset: 0,
extentOffset: 4,
);

final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin =
_MockWithCompositionAwareMixin();
mockWithCompositionAwareMixin.composingText = composingText;

expect(
mockWithCompositionAwareMixin.determineCompositionState(editingState),
editingState,
);
});

test('should return new composition state - compositing middle of text',
() {
const int baseOffset = 7;
const String composingText = 'Test';

final EditingState editingState = EditingState(
text: 'Testing',
baseOffset: baseOffset,
extentOffset: baseOffset,
);

final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin =
Expand All @@ -123,13 +190,17 @@ Future<void> testMain() async {
const int expectedComposingBase = baseOffset - composingText.length;

expect(
mockWithCompositionAwareMixin.determineCompositionState(editingState),
editingState.copyWith(
composingBaseOffset: expectedComposingBase,
composingExtentOffset: expectedComposingBase + composingText.length));
mockWithCompositionAwareMixin.determineCompositionState(editingState),
editingState.copyWith(
composingBaseOffset: expectedComposingBase,
composingExtentOffset: expectedComposingBase + composingText.length,
),
);
});

test('should return new composition state - compositing from beginning of text', () {
test(
'should return new composition state - compositing from beginning of text',
() {
const String composingText = '今日は';

final EditingState editingState = EditingState(
Expand Down

0 comments on commit 824bb0d

Please sign in to comment.