Compare commits

..

3 commits

Author SHA1 Message Date
Vadim
069a07214c add not hit files to coverage percentage 2023-10-07 00:11:39 +02:00
Vadim
fce20c7154 fixed animated dialog picker tests 2023-10-07 00:11:21 +02:00
Vadim
e15d64b10f FilmPicker widget tests 2023-10-06 23:14:04 +02:00
6 changed files with 121 additions and 8 deletions

1
.gitignore vendored
View file

@ -60,4 +60,5 @@ ios/Runner/GoogleService-Info.plist
/lib/firebase_options.dart
coverage/
test/coverage_helper_test.dart
screenshots/

View file

@ -118,11 +118,7 @@ class _DialogPickerState<T> extends State<DialogPicker<T>> {
),
const SizedBox(width: Dimens.grid16),
TextButton(
onPressed: () {
if (widget.initialValue != _selectedValue) {
widget.onSelect(_selectedValue);
}
},
onPressed: () => widget.onSelect(_selectedValue),
child: Text(S.of(context).select),
),
],

View file

@ -0,0 +1,109 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/film_picker/widget_picker_film.dart';
import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/reading_value_container/widget_container_reading_value.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
import '../../../../../application_mock.dart';
void main() {
group('Film push/pull label', () {
testWidgets(
'Film.other()',
(tester) async {
await tester.pumpApplication(_films[0]);
_expectReadingValueContainerText(S.current.film);
_expectReadingValueContainerText(S.current.none);
},
);
testWidgets(
'Film with the same ISO',
(tester) async {
await tester.pumpApplication(_films[2]);
_expectReadingValueContainerText(S.current.film);
_expectReadingValueContainerText(_films[2].name);
},
);
testWidgets(
'Film with greater ISO',
(tester) async {
await tester.pumpApplication(_films[3]);
_expectReadingValueContainerText(S.current.filmPull);
_expectReadingValueContainerText(_films[3].name);
},
);
testWidgets(
'Film with lower ISO',
(tester) async {
await tester.pumpApplication(_films[1]);
_expectReadingValueContainerText(S.current.filmPush);
_expectReadingValueContainerText(_films[1].name);
},
);
});
testWidgets(
'Film picker shows only films in use',
(tester) async {
await tester.pumpApplication(_films[1]);
await tester.tap(find.byType(FilmPicker));
await tester.pumpAndSettle(Dimens.durationL);
_expectRadioListTile(S.current.none);
_expectRadioListTile(_films[1].name);
_expectRadioListTile(_films[2].name);
_expectRadioListTile(_films[3].name);
},
);
}
extension WidgetTesterActions on WidgetTester {
Future<void> pumpApplication(Film selectedFilm) async {
await pumpWidget(
FilmsProvider(
child: Films(
values: _films,
filmsInUse: _films.sublist(0, _films.length - 1),
selected: selectedFilm,
child: const WidgetTestApplicationMock(
child: Row(
children: [
Expanded(
child: FilmPicker(selectedIso: IsoValue(400, StopType.full)),
),
],
),
),
),
),
);
await pumpAndSettle();
}
}
const _films = [
Film.other(),
Film('ISO 100 Film', 100),
Film('ISO 400 Film', 400),
Film('ISO 800 Film', 800),
Film('ISO 1600 Film', 1600),
];
void _expectReadingValueContainerText(String text) {
expect(
find.descendant(of: find.byType(ReadingValueContainer), matching: find.text(text)),
findsOneWidget,
);
}
void _expectRadioListTile(String filmName) {
expect(
find.descendant(of: find.byType(RadioListTile<Film>), matching: find.text(filmName)),
findsOneWidget,
);
}

View file

@ -101,7 +101,7 @@ extension WidgetTesterActions on WidgetTester {
);
expect(cancelButton, findsOneWidget);
await tap(cancelButton);
await pumpAndSettle();
await pumpAndSettle(Dimens.durationML);
}
Future<void> tapCancelButton() async {
@ -110,6 +110,6 @@ extension WidgetTesterActions on WidgetTester {
);
expect(cancelButton, findsOneWidget);
await tap(cancelButton);
await pumpAndSettle();
await pumpAndSettle(Dimens.durationML);
}
}

View file

@ -41,7 +41,7 @@ void main() {
expect(find.byType(DialogPicker<IsoValue>), findsOneWidget);
await tester.tapListTile(400);
await tester.tapSelectButton();
verifyNever(() => functions.onChanged(const IsoValue(400, StopType.full)));
verify(() => functions.onChanged(const IsoValue(400, StopType.full))).called(1);
},
);
},

View file

@ -1,4 +1,11 @@
flutter test --coverage
file=test/coverage_helper_test.dart
echo "// Helper file to make coverage work for all dart files\n" > $file
echo "// ignore_for_file: unused_import, directives_ordering" >> $file
find lib '!' -path '*generated*/*' '!' -name '*.g.dart' '!' -name '*.part.dart' -name '*.dart' | cut -c4- | awk -v package=$1 '{printf "import '\''package:lightmeter%s%s'\'';\n", package, $1}' >> $file
echo "void main() {}" >> $file
lcov --remove coverage/lcov.info 'lib/generated/*' 'lib/l10n/*' -o coverage/new_lcov.info
genhtml coverage/new_lcov.info -o coverage/html
open coverage/html/index.html