Skip to content

Commit

Permalink
fix: added lines were not covered by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-jiao committed Sep 15, 2023
1 parent 4c4848a commit bcd0999
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'dart:convert';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../../new/util/util.dart';
import '../../../test_helper.dart';

void main() {
group('InsertImage', () {
Expand All @@ -19,4 +23,49 @@ void main() {
expect(editorState.document.root.children.length, 2);
});
});

group('ImageWidget', () {
testWidgets('invalidURL', (tester) async {
await tester.buildAndPump(
UploadImageMenu(
onSubmitted: (String text) {},
onUpload: (String text) {},
),
);

final urlButtonFinder = find.widgetWithText(Tab, 'URL Image');
expect(urlButtonFinder, findsOneWidget);
await tester.tap(urlButtonFinder);
await tester.pumpAndSettle();
final urlFieldFinder = find.widgetWithText(TextField, 'URL');
expect(urlFieldFinder, findsOneWidget);
await tester.enterText(urlFieldFinder, 'Hello World!');
final uploadButtonFinder = find.text('Upload');
expect(uploadButtonFinder, findsOneWidget);
await tester.tap(uploadButtonFinder);
await tester.pumpAndSettle();
final incorrectLinkFinder = find.text('Incorrect Link');
expect(incorrectLinkFinder, findsOneWidget);
});

testWidgets('imageLoadError', (tester) async {
await AppFlowyEditorLocalizations.load(
const Locale.fromSubtags(languageCode: 'en'),
);

await tester.buildAndPump(
AppFlowyEditor(
editorState: EditorState(
document: Document.fromJson(
json.decode(
'{"document":{"type":"page","children":[{"type":"heading","data":{"level":2,"delta":[]}},{"type":"image","data":{"url":"https://127.0.0.1/image/not/exist.jpg","align":"center"}}]}}',
),
),
),
),
);
final couldNotLoadFinder = find.text('Could not load the image');
expect(couldNotLoadFinder, findsOneWidget);
});
});
}

0 comments on commit bcd0999

Please sign in to comment.