Skip to content

Commit

Permalink
{utils}: [fix] initialization of current BeamLocation
Browse files Browse the repository at this point in the history
	- closes #532
  • Loading branch information
slovnicki committed Aug 14, 2022
1 parent 97cffe6 commit 60ef823
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ abstract class Utils {
);
if (!beamLocation.isCurrent) {
beamLocation.create(routeInformation);
} else {
beamLocation.update(null, routeInformation, null, false);
}
return beamLocation;
}
Expand Down
39 changes: 39 additions & 0 deletions package/test/beam_guard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -798,4 +798,43 @@ void main() {
},
);
});

testWidgets('Bug with lagging route check, issue #532', (tester) async {
var checkTriggered = false;
final delegate = BeamerDelegate(
locationBuilder: BeamerLocationBuilder(
beamLocations: [
SimpleBeamLocation(),
],
),
guards: [
BeamGuard(
pathPatterns: ['/route'],
check: (_, __) {
checkTriggered = true;
return false;
},
beamToNamed: (_, __) => '/',
),
],
);

await tester.pumpWidget(
MaterialApp.router(
routeInformationParser: BeamerParser(),
routerDelegate: delegate,
),
);

expect(delegate.configuration.location, '/');

delegate.beamToNamed('/route');
await tester.pumpAndSettle();
expect(checkTriggered, true);

checkTriggered = false;
delegate.beamToNamed('/route/deeper');
await tester.pumpAndSettle();
expect(checkTriggered, false);
});
}
31 changes: 31 additions & 0 deletions package/test/test_locations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,34 @@ class UpdateStateStubBeamLocation extends BeamLocation {
updateStateStub.call();
}
}

class SimpleBeamLocation extends BeamLocation<BeamState> {
@override
List<Pattern> get pathPatterns => [
'/',
'/route',
'/route/deeper',
];

@override
List<BeamPage> buildPages(
BuildContext context,
BeamState state,
) =>
[
BeamPage(
key: const ValueKey('/'),
child: Container(),
),
if (state.pathPatternSegments.contains('route'))
BeamPage(
key: const ValueKey('route'),
child: Container(),
),
if (state.pathPatternSegments.contains('deeper'))
BeamPage(
key: const ValueKey('deeper'),
child: Container(),
),
];
}

0 comments on commit 60ef823

Please sign in to comment.