Skip to content

Commit

Permalink
fix: prevent registered route from being overwritten
Browse files Browse the repository at this point in the history
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
  • Loading branch information
axel7083 committed Sep 13, 2024
1 parent e0d5526 commit 06611cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/main/src/plugin/navigation/navigation-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ describe('register route', () => {
expect(navigationManager.hasRoute(routeId)).toBeFalsy();
});

test('registering existing route should throw an error', async () => {
const routeId = 'dummy-route-id';
navigationManager.registerRoute({
routeId: routeId,
commandId: 'fake-command-id',
});

expect(() => {
return navigationManager.registerRoute({
routeId: routeId,
commandId: 'fake-command-id',
});
}).toThrowError('routeId dummy-route-id is already registered.');
});

test('calling navigateToRoute with invalid routeId should raise an error', async () => {
await expect(() => {
return navigationManager.navigateToRoute('invalidId');
Expand Down
3 changes: 3 additions & 0 deletions packages/main/src/plugin/navigation/navigation-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export class NavigationManager {
}

registerRoute(route: NavigationRoute): Disposable {
if (this.hasRoute(route.routeId)) {
throw new Error(`routeId ${route.routeId} is already registered.`);
}
this.#registry.set(route.routeId, route);

return Disposable.create(() => {
Expand Down

0 comments on commit 06611cb

Please sign in to comment.