-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into SWAP-4501-save-table-settings-in-user-exte…
…rnal-settings
- Loading branch information
Showing
8 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { TestBed } from "@angular/core/testing"; | ||
|
||
import { RouteTrackerService } from "./route-tracker.service"; | ||
import { provideRouter, Router } from "@angular/router"; | ||
import { Component } from "@angular/core"; | ||
|
||
@Component({}) | ||
class DummyComponent {} | ||
|
||
describe("RouteTrackerService", () => { | ||
let service: RouteTrackerService; | ||
let router: Router; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
provideRouter([ | ||
{ path: "datasets/:pid", component: DummyComponent }, | ||
{ path: "login", component: DummyComponent }, | ||
]), | ||
], | ||
}); | ||
service = TestBed.inject(RouteTrackerService); | ||
router = TestBed.inject(Router); | ||
}); | ||
|
||
it("should be created", () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it("should save the last route navigated from", async () => { | ||
expect(router).toBeTruthy(); | ||
await router.navigateByUrl("/datasets/123"); | ||
await router.navigateByUrl("/login"); | ||
const previousRoute = service.getPreviousRoute(); | ||
expect(previousRoute).toBe("/datasets/123"); | ||
}); | ||
|
||
it("should preserve query parameters in the previous route", async () => { | ||
expect(router).toBeTruthy(); | ||
await router.navigateByUrl("/datasets/123?query=value"); | ||
await router.navigateByUrl("/login"); | ||
const previousRoute = service.getPreviousRoute(); | ||
expect(previousRoute).toBe("/datasets/123?query=value"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { Router, NavigationStart } from "@angular/router"; | ||
import { filter } from "rxjs"; | ||
|
||
@Injectable({ | ||
providedIn: "root", | ||
}) | ||
export class RouteTrackerService { | ||
private currentRoute: string | null = null; | ||
private previousRoute: string | null = null; | ||
|
||
constructor(private router: Router) { | ||
this.router.events | ||
.pipe(filter((event) => event instanceof NavigationStart)) | ||
.subscribe((event) => { | ||
this.previousRoute = this.currentRoute; | ||
this.currentRoute = (event as NavigationStart).url; | ||
}); | ||
} | ||
|
||
getPreviousRoute(): string | null { | ||
return this.previousRoute; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters