merge upstream

This commit is contained in:
2026-11-24 11:06:39 +00:00
6 changed files with 427 additions and 131 deletions

View File

@@ -8,6 +8,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:table_calendar/table_calendar.dart';
class FakeDiaryCubit extends Cubit<DiaryState> implements DiaryCubit {
@@ -28,15 +29,20 @@ void main() {
theme: ThemeHelper().themeData(),
builder: (context, appChild) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(textScale)),
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: appChild!,
);
},
localizationsDelegates: const [S.delegate, ...GlobalMaterialLocalizations.delegates],
localizationsDelegates: const [
S.delegate,
...GlobalMaterialLocalizations.delegates,
],
supportedLocales: const [Locale('ru')],
home: BlocProvider<DiaryCubit>.value(
value: cubit,
child: Scaffold(body: child),
child: Scaffold(body: SingleChildScrollView(child: child)),
),
);
}
@@ -52,19 +58,124 @@ void main() {
testWidgets('scales weekday row when system font is large', (tester) async {
const textScale = 2.0;
final cubit = FakeDiaryCubit(const DiaryState.loading());
await tester.pumpWidget(wrap(const CalendarWidget(), cubit, textScale: textScale));
await tester.pumpWidget(
wrap(const CalendarWidget(), cubit, textScale: textScale),
);
await tester.pump();
final calendar = tester.widget<TableCalendar<dynamic>>(find.byType(TableCalendar<dynamic>));
expect(calendar.daysOfWeekHeight, greaterThan(16 * textScale * 0.9));
final calendar = tester.widget<TableCalendar<dynamic>>(
find.byType(TableCalendar<dynamic>),
);
expect(calendar.rowHeight, 52 * textScale);
expect(find.text('пн'), findsWidgets);
final weekday = tester.renderObject<RenderParagraph>(find.text('пн').first);
expect(weekday.size.height, lessThanOrEqualTo(calendar.daysOfWeekHeight + 0.5));
final weekday = tester.renderObject<RenderParagraph>(
find.text('пн').first,
);
expect(weekday.size.height, greaterThan(16 * textScale * 0.9));
expect(
tester.getBottomLeft(find.text('пн')).dy,
lessThanOrEqualTo(
tester.getTopLeft(find.byType(TableCalendar<dynamic>)).dy,
),
);
expect(tester.takeException(), isNull);
await cubit.close();
});
testWidgets(
'header chevron switches directly between the focused week and month',
(tester) async {
final cubit = FakeDiaryCubit(const DiaryState.loading());
addTearDown(cubit.close);
final widget = find.byType(CalendarWidget);
final date = DateTime(2026, 11, 23);
await tester.pumpWidget(wrap(CalendarWidget(date: date), cubit));
await tester.pumpAndSettle();
final header = find.text(DateFormat.yMMMM('ru_RU').format(date));
final weekHeight = tester.getSize(widget).height;
expect(find.text('23').hitTestable(), findsOneWidget);
expect(find.text('9').hitTestable(), findsNothing);
await tester.tap(find.byIcon(Icons.keyboard_arrow_down_rounded));
await tester.pump();
expect(header, findsOneWidget);
expect(tester.getSize(widget).height, weekHeight + 5 * 52);
expect(find.text('9').hitTestable(), findsOneWidget);
expect(find.text('23').hitTestable(), findsOneWidget);
await tester.tap(find.byIcon(Icons.keyboard_arrow_up_rounded));
await tester.pump();
expect(tester.getSize(widget).height, weekHeight);
expect(find.text('23').hitTestable(), findsOneWidget);
},
);
testWidgets('horizontal swipes still page by week and by month', (
tester,
) async {
final cubit = FakeDiaryCubit(const DiaryState.loading());
addTearDown(cubit.close);
await tester.pumpWidget(
wrap(CalendarWidget(date: DateTime(2026, 11, 23)), cubit),
);
await tester.pumpAndSettle();
final days = find.byType(TableCalendar<dynamic>);
await tester.fling(days, const Offset(-450, 0), 1000);
await tester.pumpAndSettle();
expect(find.text('30').hitTestable(), findsOneWidget);
expect(find.text('23').hitTestable(), findsNothing);
await tester.tap(find.byIcon(Icons.keyboard_arrow_down_rounded));
await tester.pump();
await tester.fling(days, const Offset(-450, 0), 1000);
await tester.pumpAndSettle();
expect(
find.text(DateFormat.yMMMM('ru_RU').format(DateTime(2026, 12))),
findsOneWidget,
);
});
testWidgets(
'dragging the bottom handle resizes the calendar before release',
(tester) async {
final cubit = FakeDiaryCubit(const DiaryState.loading());
addTearDown(cubit.close);
final widget = find.byType(CalendarWidget);
await tester.pumpWidget(
wrap(CalendarWidget(date: DateTime(2026, 11, 23)), cubit),
);
await tester.pumpAndSettle();
final weekBottom = tester.getBottomLeft(widget).dy;
final centerX = tester.getCenter(widget).dx;
final drag = await tester.startGesture(
Offset(centerX, weekBottom - 12),
);
await drag.moveBy(const Offset(0, 64));
await tester.pump();
expect(tester.getBottomLeft(widget).dy, closeTo(weekBottom + 64, 1));
expect(find.text('23').hitTestable(), findsOneWidget);
await drag.moveBy(const Offset(0, 100));
await drag.up();
await tester.pumpAndSettle();
final monthBottom = weekBottom + 5 * 52;
expect(tester.getBottomLeft(widget).dy, closeTo(monthBottom, 1));
final reverse = await tester.startGesture(
Offset(centerX, monthBottom - 12),
);
await reverse.moveBy(const Offset(0, -160));
await tester.pump();
expect(tester.getBottomLeft(widget).dy, closeTo(monthBottom - 160, 1));
await reverse.up();
await tester.pumpAndSettle();
expect(tester.getBottomLeft(widget).dy, closeTo(weekBottom, 1));
},
);
});
}