Skip to content

Commit

Permalink
test: PathChips tests (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexEbenrode authored Oct 17, 2023
1 parent 858189f commit 7723f8c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ app.*.map.json
/android/app/release

.env
test.sh
24 changes: 24 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions test/widgets/path_chips/cubit/path_chips_cubit_test.dart
Original file line number Diff line number Diff line change
@@ -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<PathChipsCubit, PathChipsState>(
'emits [PathChipsState] when setHover is added.',
build: () => PathChipsCubit(),
act: (cubit) => cubit.setHover(true),
expect: () => const <PathChipsState>[PathChipsState(isHovered: true)],
);
});
}
48 changes: 48 additions & 0 deletions test/widgets/path_chips/path_chips_test.dart
Original file line number Diff line number Diff line change
@@ -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);
});
}

0 comments on commit 7723f8c

Please sign in to comment.