Skip to content

Commit

Permalink
fix: Fixing tests. #275
Browse files Browse the repository at this point in the history
  • Loading branch information
LuchoTurtle committed Oct 2, 2023
1 parent ba0ddcb commit 4ac50c1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 70 deletions.
1 change: 0 additions & 1 deletion lib/presentation/views/new_todo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:responsive_framework/responsive_framework.dart';
import '../../blocs/blocs.dart';
import '../../models/models.dart';

const textfieldOnNewPageKey = Key('textfieldOnNewPageKey');
const saveButtonKey = Key('saveButtonKey');

/// Transition handler that navigates the route to the `NewTodo` item page.
Expand Down
9 changes: 1 addition & 8 deletions lib/presentation/widgets/editor/todo_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class DeltaTodoEditorState extends State<DeltaTodoEditor> {
Widget build(BuildContext context) {
// Default editor (for mobile devices)
Widget quillEditor = QuillEditor(
key: quillEditorKey,
controller: widget.editorController,
scrollController: ScrollController(),
scrollable: true,
Expand Down Expand Up @@ -272,7 +273,6 @@ class DeltaTodoEditorState extends State<DeltaTodoEditor> {
Expanded(
flex: 15,
child: Container(
key: quillEditorKey,
color: Colors.white,
padding: const EdgeInsets.only(left: 16, right: 16),
child: quillEditor,
Expand Down Expand Up @@ -359,10 +359,3 @@ class DeltaTodoEditorState extends State<DeltaTodoEditor> {
}
}
}

// coverage:ignore-start
/// Image file picker wrapper class
class ImageFilePicker {
Future<FilePickerResult?> pickImage() => FilePicker.platform.pickFiles(type: FileType.image);
}
// coverage:ignore-end
97 changes: 36 additions & 61 deletions test/widget/widget_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import 'package:dwyl_app/presentation/views/views.dart';
import 'package:dwyl_app/presentation/widgets/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart' hide Text;
import 'package:flutter_quill/flutter_quill_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:dwyl_app/main.dart';

void main() {

setUpAll(() {
TestWidgetsFlutterBinding.ensureInitialized();
});

testWidgets('Build correctly setup and is loaded', (WidgetTester tester) async {
await tester.pumpWidget(const MainApp());
await tester.pump();
Expand All @@ -25,29 +32,17 @@ void main() {
await tester.tap(find.byKey(textfieldKey));
await tester.pumpAndSettle(const Duration(seconds: 2));

// Type text into todo input
await tester.enterText(find.byKey(textfieldOnNewPageKey), 'new todo');
expect(
find.descendant(
of: find.byKey(textfieldOnNewPageKey),
matching: find.text('new todo'),
),
findsOneWidget,
);
final editor = find.byType(QuillEditor);

// Type text into todo editor
await tester.tap(editor);
await tester.quillEnterText(editor, 'new todo\n');
await tester.pumpAndSettle();

// Tap "Save" button to add new todo item
await tester.tap(find.byKey(saveButtonKey));
await tester.pumpAndSettle(const Duration(seconds: 2));

// Input is cleared
expect(
find.descendant(
of: find.byKey(textfieldOnNewPageKey),
matching: find.text('new todo'),
),
findsNothing,
);

// Pump the widget so it renders the new item
await tester.pumpAndSettle(const Duration(seconds: 2));

Expand All @@ -72,29 +67,17 @@ void main() {
await tester.tap(find.byKey(textfieldKey));
await tester.pumpAndSettle(const Duration(seconds: 2));

final editor = find.byType(QuillEditor);

// Type text into todo input
await tester.enterText(find.byKey(textfieldOnNewPageKey), 'new todo');
expect(
find.descendant(
of: find.byKey(textfieldOnNewPageKey),
matching: find.text('new todo'),
),
findsOneWidget,
);
await tester.tap(editor);
await tester.quillEnterText(editor, 'new todo\n');
await tester.pumpAndSettle();

// Tap "Save" button to add new todo item
await tester.tap(find.byKey(saveButtonKey));
await tester.pumpAndSettle(const Duration(seconds: 2));

// Input is cleared
expect(
find.descendant(
of: find.byKey(textfieldOnNewPageKey),
matching: find.text('new todo'),
),
findsNothing,
);

// Pump the widget so it renders the new item
await tester.pumpAndSettle(const Duration(seconds: 2));

Expand All @@ -108,7 +91,7 @@ void main() {
testWidgets('Adding a new todo item shows a card (on tablet screen)', (WidgetTester tester) async {
// Ensure binding is initialized to setup camera size
TestWidgetsFlutterBinding.ensureInitialized();
tester.view.physicalSize = const Size(400, 600);
tester.view.physicalSize = const Size(400, 900);
tester.view.devicePixelRatio = 1.0;

await tester.pumpWidget(const MainApp());
Expand All @@ -122,29 +105,17 @@ void main() {
await tester.tap(find.byKey(textfieldKey));
await tester.pumpAndSettle(const Duration(seconds: 2));

final editor = find.byType(QuillEditor);

// Type text into todo input
await tester.enterText(find.byKey(textfieldOnNewPageKey), 'new todo');
expect(
find.descendant(
of: find.byKey(textfieldOnNewPageKey),
matching: find.text('new todo'),
),
findsOneWidget,
);
await tester.tap(editor);
await tester.quillEnterText(editor, 'new todo\n');
await tester.pumpAndSettle();

// Tap "Save" button to add new todo item
await tester.tap(find.byKey(saveButtonKey));
await tester.pumpAndSettle(const Duration(seconds: 2));

// Input is cleared
expect(
find.descendant(
of: find.byKey(textfieldOnNewPageKey),
matching: find.text('new todo'),
),
findsNothing,
);

// Pump the widget so it renders the new item
await tester.pumpAndSettle(const Duration(seconds: 2));

Expand All @@ -168,11 +139,13 @@ void main() {
await tester.pumpAndSettle(const Duration(seconds: 2));

// Type text into todo input and tap "Save" button to add new todo item
await tester.enterText(find.byKey(textfieldOnNewPageKey), 'new todo');
await tester.tap(find.byKey(saveButtonKey));
await tester.pumpAndSettle(const Duration(seconds: 2));
final editor = find.byType(QuillEditor);

// Pump the widget so it renders the new item
await tester.tap(editor);
await tester.quillEnterText(editor, 'new todo\n');
await tester.pumpAndSettle();

await tester.tap(find.byKey(saveButtonKey));
await tester.pumpAndSettle(const Duration(seconds: 2));

// Expect to find at least one widget, pertaining to the one that was added
Expand Down Expand Up @@ -209,11 +182,13 @@ void main() {
await tester.pumpAndSettle(const Duration(seconds: 2));

// Type text into todo input and tap "Save" button to add new todo item
await tester.enterText(find.byKey(textfieldOnNewPageKey), 'new todo');
await tester.tap(find.byKey(saveButtonKey));
await tester.pumpAndSettle(const Duration(seconds: 2));
final editor = find.byType(QuillEditor);

// Pump the widget so it renders the new item
await tester.tap(editor);
await tester.quillEnterText(editor, 'new todo\n');
await tester.pumpAndSettle();

await tester.tap(find.byKey(saveButtonKey));
await tester.pumpAndSettle(const Duration(seconds: 2));

// Expect to find at least one widget, pertaining to the one that was added
Expand Down

0 comments on commit 4ac50c1

Please sign in to comment.