Skip to content

Commit

Permalink
ShiftStartsTimePopup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Syutkin committed Jan 4, 2025
1 parent 81e3620 commit 22d100b
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/src/common/widget/cancel_ok_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ List<Widget> cancelOkButtons({
}) {
return <Widget>[
TextButton(
key: const Key('cancelButton'),
onPressed: onCancelPressed?.call,
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
),
TextButton(
key: const Key('okButton'),
onPressed: onOkPressed?.call,
child: Text(MaterialLocalizations.of(context).okButtonLabel),
),
Expand Down
16 changes: 8 additions & 8 deletions lib/src/constants/pubspec.yaml.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ sealed class Pubspec {
static const PubspecVersion version = (
/// Non-canonical string representation of the version as provided
/// in the pubspec.yaml file.
representation: r'0.5.0-beta.3+417',
representation: r'0.5.0-beta.3+418',

/// Returns a 'canonicalized' representation
/// of the application version.
/// This represents the version string in accordance with
/// Semantic Versioning (SemVer) standards.
canonical: r'0.5.0-beta.3+417',
canonical: r'0.5.0-beta.3+418',

/// MAJOR version when you make incompatible API changes.
/// The major version number: 1 in "1.2.3".
Expand All @@ -119,19 +119,19 @@ sealed class Pubspec {
preRelease: <String>[r'beta', r'3'],

/// The build identifier: "foo" in "1.2.3+foo".
build: <String>[r'417'],
build: <String>[r'418'],
);

/// Build date and time (UTC)
static final DateTime timestamp = DateTime.utc(
2025,
1,
4,
8,
39,
44,
583,
861,
10,
50,
40,
884,
90,
);

/// Name
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repository: https://github.com/Syutkin/entime-mobile
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.5.0-beta.3+417
version: 0.5.0-beta.3+418

environment:
sdk: ^3.7.0-209.1.beta
Expand Down
204 changes: 204 additions & 0 deletions test/src/feature/database/widget/popup/shift_starts_time_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:drift/drift.dart';
import 'package:entime/src/common/localization/localization.dart';
import 'package:entime/src/feature/database/database.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:patrol_finders/patrol_finders.dart';

class MockQueryRow extends Mock implements QueryRow {}

class MockDatabaseBloc extends MockBloc<DatabaseEvent, DatabaseState>
implements DatabaseBloc {}

void main() {
late DatabaseBloc databaseBloc;
late ParticipantAtStart item;
late int number;
late String startTime;

Widget testWidget(ParticipantAtStart item) {
return MaterialApp(
localizationsDelegates: const [Localization.delegate],
supportedLocales: Localization.supportedLocales,
home: Material(
child: Builder(
builder:
(context) => TextButton(
onPressed: () => shiftStartsTime(context: context, item: item),
child: const Text('TextButton'),
),
),
),
);
}

Widget testShiftStartsTimePopup(ParticipantAtStart item) {
return MaterialApp(
localizationsDelegates: const [Localization.delegate],
supportedLocales: Localization.supportedLocales,
home: BlocProvider.value(
value: databaseBloc,
child: Material(child: ShiftStartsTimePopup(item: item)),
),
);
}

setUp(() {
databaseBloc = MockDatabaseBloc();
number = 1234;
startTime = '12:13:14';

item = ParticipantAtStart(
row: MockQueryRow(),
riderId: 1,
raceId: 1,
number: number,
participantStatusId: 1,
name: 'name',
startId: 1,
stageId: 1,
participantId: 1,
startTime: startTime,
statusId: 1,
);
});

group('ShiftStartsTimePopup tests', () {
patrolWidgetTest('Pump widget', (PatrolTester $) async {
await $.pumpWidgetAndSettle(testWidget(item));

expect($(Localization.current.I18nCore_warning), findsNothing);
expect(
$(
Localization.current.I18nStart_shiftStartsTimeFromNumber(
number,
startTime,
),
),
findsNothing,
);
expect($(Localization.current.I18nStart_shiftMinutes), findsNothing);

await $(TextButton).tap();
await $.pumpAndSettle();

expect($(Localization.current.I18nCore_warning), findsOneWidget);
expect(
$(
Localization.current.I18nStart_shiftStartsTimeFromNumber(
number,
startTime,
),
),
findsOneWidget,
);
expect($(Localization.current.I18nStart_shiftMinutes), findsOneWidget);
});

patrolWidgetTest('Do not call bloc event, when shist is empty', (
PatrolTester $,
) async {
await $.pumpWidgetAndSettle(testWidget(item));
await $(TextButton).tap();
await $.pumpAndSettle();

await $(TextFormField).enterText('');
await $(#okButton).tap();
await $.pumpAndSettle();

expect($(Localization.current.I18nCore_warning), findsNothing);
expect(
$(
Localization.current.I18nStart_shiftStartsTimeFromNumber(
number,
startTime,
),
),
findsNothing,
);
expect($(Localization.current.I18nStart_shiftMinutes), findsNothing);
});

patrolWidgetTest('Do not call bloc event, when shift is empty', (
PatrolTester $,
) async {
await $.pumpWidgetAndSettle(testWidget(item));
await $(TextButton).tap();
await $.pumpAndSettle();

expect($(Localization.current.I18nCore_warning), findsOneWidget);
expect(
$(
Localization.current.I18nStart_shiftStartsTimeFromNumber(
number,
startTime,
),
),
findsOneWidget,
);
expect($(Localization.current.I18nStart_shiftMinutes), findsOneWidget);

await $(#cancelButton).tap();
await $.pumpAndSettle();

expect($(Localization.current.I18nCore_warning), findsNothing);
expect(
$(
Localization.current.I18nStart_shiftStartsTimeFromNumber(
number,
startTime,
),
),
findsNothing,
);
expect($(Localization.current.I18nStart_shiftMinutes), findsNothing);
});

patrolWidgetTest('Call bloc event on correct shift', (
PatrolTester $,
) async {
await $.pumpWidgetAndSettle(testShiftStartsTimePopup(item));

expect($(Localization.current.I18nCore_warning), findsOneWidget);
expect(
$(
Localization.current.I18nStart_shiftStartsTimeFromNumber(
number,
startTime,
),
),
findsOneWidget,
);
expect($(Localization.current.I18nStart_shiftMinutes), findsOneWidget);

await $(TextFormField).enterText('100');
await $(#okButton).tap();
await $.pumpAndSettle();

expect($(Localization.current.I18nCore_warning), findsNothing);
expect(
$(
Localization.current.I18nStart_shiftStartsTimeFromNumber(
number,
startTime,
),
),
findsNothing,
);

expect($(Localization.current.I18nStart_shiftMinutes), findsNothing);
verify(
() => databaseBloc.add(
DatabaseEvent.shiftStartsTime(
stageId: 1,
minutes: 100,
fromTime: startTime,
),
),
).called(1);
});
});
}

0 comments on commit 22d100b

Please sign in to comment.