diff --git a/.gitignore b/.gitignore index 72685a5..4b4c8b3 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,4 @@ app.*.map.json /android/app/release .env +test.sh diff --git a/pubspec.lock b/pubspec.lock index 9bc17b0..ed5b425 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -41,6 +41,14 @@ packages: url: "https://pub.dev" source: hosted version: "8.1.1" + bloc_test: + dependency: "direct main" + description: + name: bloc_test + sha256: af0de1a1e16a7536e95dcd7491e0a6d6078e11d2d691988e862280b74f5c7968 + url: "https://pub.dev" + source: hosted + version: "9.1.4" boolean_selector: dependency: transitive description: @@ -193,6 +201,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.1" + diff_match_patch: + dependency: transitive + description: + name: diff_match_patch + sha256: "2efc9e6e8f449d0abe15be240e2c2a3bcd977c8d126cfd70598aee60af35c0a4" + url: "https://pub.dev" + source: hosted + version: "0.4.1" easy_localization: dependency: "direct main" description: @@ -485,6 +501,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.5.0" + mocktail: + dependency: transitive + description: + name: mocktail + sha256: bac151b31e4ed78bd59ab89aa4c0928f297b1180186d5daf03734519e5f596c1 + url: "https://pub.dev" + source: hosted + version: "1.0.1" nested: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9fa0c92..4964142 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,6 +22,7 @@ dependencies: flutter: sdk: flutter easy_localization: ^3.0.2 + bloc_test: ^9.1.4 dependency_overrides: intl: 0.18.1 dev_dependencies: diff --git a/test/widgets/path_chips/cubit/path_chips_cubit_test.dart b/test/widgets/path_chips/cubit/path_chips_cubit_test.dart new file mode 100644 index 0000000..ca45c5e --- /dev/null +++ b/test/widgets/path_chips/cubit/path_chips_cubit_test.dart @@ -0,0 +1,22 @@ +import 'package:bloc_test/bloc_test.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pilot_s3/widgets/path_chips/cubit/path_chips_cubit.dart'; + +void main() { + group('PathChipsCubit', () { + late PathChipsCubit pathChipsCubit; + + setUp(() { + pathChipsCubit = PathChipsCubit(); + }); + test('isHovered in initial state is false', () { + expect(pathChipsCubit.state, const PathChipsState(isHovered: false)); + }); + blocTest( + 'emits [PathChipsState] when setHover is added.', + build: () => PathChipsCubit(), + act: (cubit) => cubit.setHover(true), + expect: () => const [PathChipsState(isHovered: true)], + ); + }); +} diff --git a/test/widgets/path_chips/path_chips_test.dart b/test/widgets/path_chips/path_chips_test.dart new file mode 100644 index 0000000..019a616 --- /dev/null +++ b/test/widgets/path_chips/path_chips_test.dart @@ -0,0 +1,48 @@ +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pilot_s3/widgets/path_chips/path_chips.dart'; + +void main() { + testWidgets('Renders passed text to chips', (tester) async { + const String testText = 'Chips label'; + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: PathChips( + label: testText, + onTap: () {}, + ), + ), + )); + + final labelFinder = find.text(testText); + expect(labelFinder, findsOneWidget); + }); + + testWidgets('Change chips color after hover', (tester) async { + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: PathChips( + onTap: () {}, + ), + ), + )); + expect( + find.byWidgetPredicate((Widget widget) => + widget is Container && widget.color == Colors.grey[150]), + findsOneWidget); + + final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); + await gesture.addPointer(location: Offset.zero); + addTearDown(gesture.removePointer); + await tester.pump(); + await gesture.moveTo(tester.getCenter(find.byType(PathChips))); + await tester.pumpAndSettle(); + + expect( + find.byWidgetPredicate((Widget widget) => + widget is Container && widget.color == Colors.grey[170]), + findsOneWidget); + }); +}