fix: handle null context in MarkdownHtmlWidget and improve test stability with pumpAndSettle calls

This commit is contained in:
mso7nueh
2026-01-13 13:03:58 +03:00
parent 7b425e56f1
commit c786821275
9 changed files with 22 additions and 1 deletions

View File

@@ -41,7 +41,7 @@ class MarkdownHtmlWidget extends StatelessWidget {
extensionSet: md.ExtensionSet.gitHubFlavored,
);
final screenWidth = MediaQuery.of(context).size.width;
final screenWidth = MediaQuery.maybeOf(context)?.size.width ?? 400.0;
final defaultImageWidth = imageWidth ?? (screenWidth - 32);
final defaultTextColor = textColor ?? Colors.black87;
final defaultFontSize = fontSize ?? 16.0;

View File

@@ -29,6 +29,7 @@ void main() {
const MarketingBottomSheet(),
),
);
await tester.pumpAndSettle();
expect(find.byType(MarketingBottomSheet), findsOneWidget);
});
@@ -59,6 +60,7 @@ void main() {
),
);
await tester.pump();
await tester.tap(find.text('Show'));
await tester.pumpAndSettle();

View File

@@ -24,6 +24,7 @@ void main() {
testWidgets('returns SizedBox.shrink when option is null', (tester) async {
await tester.pumpWidget(createTestWidget(const OptionWidget(option: null, duration: 7)));
await tester.pumpAndSettle();
expect(find.byType(OptionWidget), findsOneWidget);
expect(find.byType(SizedBox), findsWidgets);
@@ -33,6 +34,7 @@ void main() {
const option = PacketOptions(items: ['Item 1', 'Item 2'], price: 1000.0, short: 'Short', description: 'Description', hasPersonalDiet: false);
await tester.pumpWidget(createTestWidget(const OptionWidget(option: option, duration: 7)));
await tester.pumpAndSettle();
expect(find.byType(OptionWidget), findsOneWidget);
expect(find.text('Short'), findsOneWidget);
@@ -43,6 +45,7 @@ void main() {
const option = PacketOptions(items: ['Item 1'], price: 1000.0, short: 'Short', description: 'Description', hasPersonalDiet: true);
await tester.pumpWidget(createTestWidget(const OptionWidget(option: option, duration: 7)));
await tester.pumpAndSettle();
expect(find.byType(OptionWidget), findsOneWidget);
});
@@ -51,6 +54,7 @@ void main() {
const option = PacketOptions(items: ['Item 1'], price: 1000.0, short: 'Short', description: 'Description', hasPersonalDiet: false);
await tester.pumpWidget(createTestWidget(const OptionWidget(option: option, duration: 7, disableDuration: true)));
await tester.pumpAndSettle();
expect(find.byType(OptionWidget), findsOneWidget);
});

View File

@@ -31,6 +31,7 @@ void main() {
),
);
await tester.pump();
await tester.tap(find.text('Show Error'));
await tester.pumpAndSettle();
@@ -68,6 +69,7 @@ void main() {
),
);
await tester.pump();
await tester.tap(find.text('Show Error'));
await tester.pumpAndSettle();
@@ -103,6 +105,7 @@ void main() {
),
);
await tester.pump();
await tester.tap(find.text('Show Error'));
await tester.pumpAndSettle();
@@ -134,6 +137,7 @@ void main() {
),
);
await tester.pump();
await tester.tap(find.text('Show Error'));
await tester.pumpAndSettle();

View File

@@ -34,6 +34,7 @@ void main() {
),
),
);
await tester.pumpAndSettle();
expect(find.byType(ChosenDietWidgetContent), findsOneWidget);
expect(find.text('Test Diet'), findsOneWidget);
@@ -50,6 +51,7 @@ void main() {
),
),
);
await tester.pumpAndSettle();
expect(find.byType(ChosenDietWidgetContent), findsOneWidget);
});
@@ -65,6 +67,7 @@ void main() {
),
),
);
await tester.pumpAndSettle();
expect(find.text('My Diet'), findsOneWidget);
});

View File

@@ -37,6 +37,7 @@ void main() {
planName: 'Test Plan',
planDuration: 14,
));
await tester.pumpAndSettle();
expect(find.byType(ChosenPlanWidgetContent), findsOneWidget);
expect(find.text('Test Plan'), findsOneWidget);
@@ -48,6 +49,7 @@ void main() {
planName: 'My Plan',
planDuration: 7,
));
await tester.pumpAndSettle();
expect(find.byType(ChosenPlanWidgetContent), findsOneWidget);
expect(find.textContaining('3'), findsOneWidget);
@@ -60,6 +62,7 @@ void main() {
planName: 'Long Plan',
planDuration: 30,
));
await tester.pumpAndSettle();
expect(find.byType(ChosenPlanWidgetContent), findsOneWidget);
expect(find.text('Long Plan'), findsOneWidget);

View File

@@ -78,6 +78,7 @@ void main() {
),
),
);
await tester.pumpAndSettle();
expect(find.byType(CommentsWidget), findsOneWidget);
});

View File

@@ -63,6 +63,7 @@ void main() {
// Act
await tester.pumpWidget(createTestWidget(const SizedBox(), mockCubit));
await tester.pump();
await tester.tap(find.text('Show Bottom Sheet'));
await tester.pumpAndSettle();
@@ -107,6 +108,7 @@ void main() {
// Act
await tester.pumpWidget(createTestWidgetError(const SizedBox(), mockCubit));
await tester.pump();
await tester.tap(find.text('Show Bottom Sheet'));
await tester.pumpAndSettle();

View File

@@ -54,6 +54,7 @@ void main() {
home: ChangePasswordScreen(settingsEntity: settingsEntity),
),
);
await tester.pumpAndSettle();
expect(find.byType(ChangePasswordScreen), findsOneWidget);
expect(find.text('Смена пароля'), findsOneWidget);
@@ -80,6 +81,7 @@ void main() {
home: ChangePasswordScreen(settingsEntity: settingsEntity),
),
);
await tester.pumpAndSettle();
expect(find.byType(AppBar), findsOneWidget);
expect(find.text('Смена пароля'), findsOneWidget);