aboutsummaryrefslogtreecommitdiffstats
path: root/packages/flutter_calendar_carousel/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/flutter_calendar_carousel/test/src')
-rw-r--r--packages/flutter_calendar_carousel/test/src/header_test.dart104
-rw-r--r--packages/flutter_calendar_carousel/test/src/weekday_row_test.dart128
2 files changed, 232 insertions, 0 deletions
diff --git a/packages/flutter_calendar_carousel/test/src/header_test.dart b/packages/flutter_calendar_carousel/test/src/header_test.dart
new file mode 100644
index 0000000..2f9b603
--- /dev/null
+++ b/packages/flutter_calendar_carousel/test/src/header_test.dart
@@ -0,0 +1,104 @@
+import 'package:flutter_test/flutter_test.dart';
+import 'package:flutter_calendar_carousel/src/calendar_header.dart';
+
+import 'package:flutter/material.dart';
+
+void main() {
+ final title = "Test title";
+ final margin = const EdgeInsets.symmetric(vertical: 16.0);
+ final iconColor = Colors.blueAccent;
+
+ testWidgets('Verify Header Defaults', (WidgetTester tester) async {
+ var headerTapped = false;
+ var leftPressed = false;
+ var rightPressed = false;
+
+ await tester.pumpWidget(wrapped(CalendarHeader(
+ headerTitle: title,
+ headerMargin: margin,
+ showHeader: true,
+ showHeaderButtons: true,
+ headerIconColor: iconColor,
+ onHeaderTitlePressed: () => headerTapped = true,
+ onRightButtonPressed: () => rightPressed = true,
+ onLeftButtonPressed: () => leftPressed = true,
+ )));
+
+ expect(find.text(title), findsOneWidget);
+
+ await tester.tap(find.byType(TextButton));
+
+ await tester.pump();
+
+ expect(headerTapped, equals(true));
+
+ await tester.tap(find.widgetWithIcon(IconButton, Icons.chevron_right));
+
+ await tester.pump();
+
+ expect(rightPressed, equals(true));
+
+ await tester.tap(find.widgetWithIcon(IconButton, Icons.chevron_left));
+
+ await tester.pump();
+
+ expect(leftPressed, equals(true));
+ });
+
+ testWidgets('Verify No header Renders', (WidgetTester tester) async {
+ final noHeaderEmpty = CalendarHeader(
+ showHeader: false,
+ headerTitle: '',
+ onLeftButtonPressed: () {},
+ onHeaderTitlePressed: () {},
+ onRightButtonPressed: () {},
+ );
+
+ await tester.pumpWidget(Container(child: noHeaderEmpty));
+
+ expect(find.byWidget(noHeaderEmpty), findsOneWidget);
+ });
+
+ testWidgets('Verify Header Is Not Touchable', (WidgetTester tester) async {
+ await tester.pumpWidget(wrapped(CalendarHeader(
+ headerTitle: title,
+ headerMargin: margin,
+ showHeader: true,
+ showHeaderButtons: true,
+ headerIconColor: iconColor,
+ onHeaderTitlePressed: null,
+ onRightButtonPressed: () {},
+ onLeftButtonPressed: () {},
+ )));
+
+ // the header TextButton Should not render
+ final touchableHeader = find.byType(TextButton);
+
+ expect(touchableHeader, findsNothing);
+ });
+
+ testWidgets('Verify No Header Buttons', (WidgetTester tester) async {
+ await tester.pumpWidget(wrapped(CalendarHeader(
+ headerTitle: title,
+ headerMargin: margin,
+ showHeader: true,
+ showHeaderButtons: false,
+ headerIconColor: iconColor,
+ onHeaderTitlePressed: () {},
+ onRightButtonPressed: () {},
+ onLeftButtonPressed: () {},
+ )));
+
+ // the header IconButtons Should not render
+ final headerButton = find.byType(IconButton);
+
+ expect(headerButton, findsNothing);
+ });
+}
+
+// header uses Row which requires MaterialApp as an ancestor
+Widget wrapped(Widget widget) => MaterialApp(
+ home: Container(
+ child: Material(child: widget),
+ ),
+ );
diff --git a/packages/flutter_calendar_carousel/test/src/weekday_row_test.dart b/packages/flutter_calendar_carousel/test/src/weekday_row_test.dart
new file mode 100644
index 0000000..95090e4
--- /dev/null
+++ b/packages/flutter_calendar_carousel/test/src/weekday_row_test.dart
@@ -0,0 +1,128 @@
+import 'package:flutter_test/flutter_test.dart';
+import 'package:flutter_calendar_carousel/flutter_calendar_carousel.dart'
+ show WeekdayFormat;
+import 'package:intl/intl.dart' show DateFormat;
+
+import 'package:flutter_calendar_carousel/src/weekday_row.dart';
+import 'package:flutter/material.dart';
+
+void main() {
+ final locale = DateFormat.yMMM("en_US");
+ final margin = const EdgeInsets.only(bottom: 4.0);
+
+ testWidgets('test short weekday row', (WidgetTester tester) async {
+ await tester.pumpWidget(wrapped(
+ WeekdayRow(
+ 0,
+ null,
+ weekdayPadding: EdgeInsets.all(0),
+ weekdayBackgroundColor: Colors.transparent,
+ showWeekdays: true,
+ weekdayFormat: WeekdayFormat.short,
+ weekdayMargin: margin,
+ weekdayTextStyle: null,
+ localeDate: locale,
+ ),
+ ));
+
+ expect(find.text('Sun'), findsOneWidget);
+ expect(find.text('Mon'), findsOneWidget);
+ expect(find.text('Tue'), findsOneWidget);
+ expect(find.text('Wed'), findsOneWidget);
+ expect(find.text('Thu'), findsOneWidget);
+ expect(find.text('Fri'), findsOneWidget);
+ expect(find.text('Sat'), findsOneWidget);
+ });
+
+ testWidgets('test narrow weekday row', (WidgetTester tester) async {
+ await tester.pumpWidget(wrapped(WeekdayRow(
+ 0,
+ null,
+ weekdayPadding: EdgeInsets.all(0),
+ weekdayBackgroundColor: Colors.transparent,
+ showWeekdays: true,
+ weekdayFormat: WeekdayFormat.standaloneNarrow,
+ weekdayMargin: margin,
+ weekdayTextStyle: null,
+ localeDate: locale,
+ )));
+
+ // sat and sun
+ expect(find.text('S'), findsNWidgets(2));
+ // thurs and tues
+ expect(find.text('T'), findsNWidgets(2));
+
+ expect(find.text('M'), findsOneWidget);
+ expect(find.text('W'), findsOneWidget);
+ expect(find.text('F'), findsOneWidget);
+ });
+
+ testWidgets('test standalone weekday row', (WidgetTester tester) async {
+ await tester.pumpWidget(wrapped(WeekdayRow(
+ 0,
+ null,
+ weekdayPadding: EdgeInsets.all(0),
+ weekdayBackgroundColor: Colors.transparent,
+ showWeekdays: true,
+ weekdayFormat: WeekdayFormat.standalone,
+ weekdayMargin: margin,
+ weekdayTextStyle: null,
+ localeDate: locale,
+ )));
+
+ expect(find.text('Sunday'), findsOneWidget);
+ expect(find.text('Monday'), findsOneWidget);
+ expect(find.text('Tuesday'), findsOneWidget);
+ expect(find.text('Wednesday'), findsOneWidget);
+ expect(find.text('Thursday'), findsOneWidget);
+ expect(find.text('Friday'), findsOneWidget);
+ expect(find.text('Saturday'), findsOneWidget);
+ });
+
+ testWidgets('test standalone short weekday row', (WidgetTester tester) async {
+ await tester.pumpWidget(wrapped(WeekdayRow(
+ 0,
+ null,
+ weekdayPadding: EdgeInsets.all(0),
+ weekdayBackgroundColor: Colors.transparent,
+ showWeekdays: true,
+ weekdayFormat: WeekdayFormat.standaloneShort,
+ weekdayMargin: margin,
+ weekdayTextStyle: null,
+ localeDate: locale,
+ )));
+
+ expect(find.text('Sun'), findsOneWidget);
+ expect(find.text('Mon'), findsOneWidget);
+ expect(find.text('Tue'), findsOneWidget);
+ expect(find.text('Wed'), findsOneWidget);
+ expect(find.text('Thu'), findsOneWidget);
+ expect(find.text('Fri'), findsOneWidget);
+ expect(find.text('Sat'), findsOneWidget);
+ });
+
+ testWidgets('test row does not render', (WidgetTester tester) async {
+ final emptyContainer = WeekdayRow(
+ 0,
+ null,
+ weekdayPadding: EdgeInsets.all(0),
+ weekdayBackgroundColor: Colors.transparent,
+ showWeekdays: false,
+ weekdayFormat: WeekdayFormat.standaloneNarrow,
+ weekdayMargin: margin,
+ weekdayTextStyle: null,
+ localeDate: locale,
+ );
+
+ await tester.pumpWidget(emptyContainer);
+
+ expect(find.byType(Container), findsOneWidget);
+
+ expect(find.byType(Row), findsNothing);
+ });
+}
+
+Widget wrapped(Widget widget) => Directionality(
+ textDirection: TextDirection.ltr,
+ child: widget,
+ );