Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martijn00 committed Aug 20, 2024
1 parent 221dce5 commit ea3234a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/flutter_adaptive_scaffold/lib/src/breakpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ class Breakpoint {
final bool isHeightActive = isDesktop ||
orientation == Orientation.portrait ||
(orientation == Orientation.landscape && andUp
? height >= lowerBoundHeight
? isWidthActive && height <= lowerBoundHeight ||
height >= lowerBoundHeight
: height >= lowerBoundHeight && height < upperBoundHeight);

return isWidthActive && isHeightActive && isRightPlatform;
Expand Down
51 changes: 49 additions & 2 deletions packages/flutter_adaptive_scaffold/test/breakpoint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ void main() {
await tester.pumpWidget(
SimulatedLayout.smallLandscapeMediumPortrait.slot(tester));
await tester.pumpAndSettle();
expect(find.byKey(const Key('Breakpoints.smallMobile')), findsOneWidget);
expect(find.byKey(const Key('Breakpoints.smallMobile')), findsNothing);
expect(find.byKey(const Key('Breakpoints.mediumMobile')), findsNothing);
});

Expand All @@ -545,7 +545,7 @@ void main() {
await tester.pumpWidget(
SimulatedLayout.smallLandscapeMediumLargePortrait.slot(tester));
await tester.pumpAndSettle();
expect(find.byKey(const Key('Breakpoints.smallMobile')), findsOneWidget);
expect(find.byKey(const Key('Breakpoints.smallMobile')), findsNothing);
expect(find.byKey(const Key('Breakpoints.largeMobile')), findsNothing);
});
});
Expand Down Expand Up @@ -627,6 +627,53 @@ void main() {
expect(find.byKey(const Key('Breakpoints.small')), findsNothing);
});
});

group('Slot And Up Layout Tests with Portrait and Landscape Mixed Layout',
() {
testWidgets(
'slotAndUp shows correct slot for smallPortraitMediumLandscape layout',
(WidgetTester tester) async {
// smallPortraitMediumLandscape layout should only show the small slot.
await tester.pumpWidget(
SimulatedLayout.smallPortraitMediumLandscape.slotAndUp(tester));
await tester.pumpAndSettle();
expect(find.byKey(const Key('Breakpoints.small')), findsOneWidget);
expect(find.byKey(const Key('Breakpoints.mediumAndUp')), findsNothing);
});

testWidgets(
'slotAndUp shows correct slot for smallLandscapeMediumPortrait layout',
(WidgetTester tester) async {
// smallLandscapeMediumPortrait layout should show the small slot.
await tester.pumpWidget(
SimulatedLayout.smallLandscapeMediumPortrait.slotAndUp(tester));
await tester.pumpAndSettle();
expect(find.byKey(const Key('Breakpoints.small')), findsNothing);
expect(find.byKey(const Key('Breakpoints.mediumAndUp')), findsOneWidget);
});

testWidgets(
'slotAndUp shows correct slot for smallPortraitMediumLargeLandscape layout',
(WidgetTester tester) async {
// smallPortraitMediumLargeLandscape layout should show the small slot.
await tester.pumpWidget(
SimulatedLayout.smallPortraitMediumLargeLandscape.slotAndUp(tester));
await tester.pumpAndSettle();
expect(find.byKey(const Key('Breakpoints.small')), findsOneWidget);
expect(find.byKey(const Key('Breakpoints.mediumAndUp')), findsNothing);
});

testWidgets(
'slotAndUp shows correct slot for smallLandscapeMediumLargePortrait layout',
(WidgetTester tester) async {
// smallLandscapeMediumLargePortrait layout should show the small slot.
await tester.pumpWidget(
SimulatedLayout.smallLandscapeMediumLargePortrait.slotAndUp(tester));
await tester.pumpAndSettle();
expect(find.byKey(const Key('Breakpoints.small')), findsNothing);
expect(find.byKey(const Key('Breakpoints.mediumAndUp')), findsOneWidget);
});
});
}

class DummyWidget extends StatelessWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ enum SimulatedLayout {
smallPortraitMediumLargeLandscape(
width: 360, height: 900, navSlotKey: 'bottomNavigation'),
smallLandscapeMediumLargePortrait(
width: 900, height: 360, navSlotKey: 'bottomNavigation');
width: 900, height: 360, navSlotKey: 'primaryNavigation');

const SimulatedLayout({
required double width,
Expand Down

0 comments on commit ea3234a

Please sign in to comment.