second commit
This commit is contained in:
89
test/widget/primary_button_test.dart
Normal file
89
test/widget/primary_button_test.dart
Normal file
@@ -0,0 +1,89 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nearle_pos/core/widgets/primary_button.dart';
|
||||
import 'package:nearle_pos/core/widgets/status_pill.dart';
|
||||
import 'package:nearle_pos/domain/entities/customer.dart';
|
||||
|
||||
Widget _host(Widget child) => MaterialApp(
|
||||
home: Scaffold(body: Center(child: child)),
|
||||
);
|
||||
|
||||
void main() {
|
||||
group('PrimaryButton', () {
|
||||
testWidgets('renders its label', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(PrimaryButton(label: 'Charge', onPressed: () {})),
|
||||
);
|
||||
|
||||
expect(find.text('Charge'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('fires onPressed when tapped', (tester) async {
|
||||
var taps = 0;
|
||||
await tester.pumpWidget(
|
||||
_host(PrimaryButton(label: 'Charge', onPressed: () => taps++)),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Charge'));
|
||||
await tester.pump();
|
||||
|
||||
expect(taps, 1);
|
||||
});
|
||||
|
||||
testWidgets('does nothing when onPressed is null', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(const PrimaryButton(label: 'Charge')),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Charge'), warnIfMissed: false);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Charge'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('shows a spinner instead of the label while busy',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(PrimaryButton(label: 'Charge', busy: true, onPressed: () {})),
|
||||
);
|
||||
|
||||
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
||||
expect(find.text('Charge'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('renders a trailing total alongside the label',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(PrimaryButton(
|
||||
label: 'CHARGE',
|
||||
onPressed: () {},
|
||||
trailing: const Text('\u20B9384.00'),
|
||||
)),
|
||||
);
|
||||
|
||||
expect(find.text('CHARGE'), findsOneWidget);
|
||||
expect(find.text('\u20B9384.00'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
group('StatusPill', () {
|
||||
testWidgets('labels a membership tier', (tester) async {
|
||||
await tester.pumpWidget(_host(StatusPill.tier(MembershipTier.silver)));
|
||||
expect(find.text('SILVER'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('reports an out-of-stock product', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(StatusPill.stock(0, lowThreshold: 10)),
|
||||
);
|
||||
expect(find.text('Out of stock'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('warns when stock is low', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(StatusPill.stock(4, lowThreshold: 10)),
|
||||
);
|
||||
expect(find.text('4 left'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user