fix: fix some tests

This commit is contained in:
2025-02-02 00:45:46 +08:00
parent 28da493462
commit 6a03a2bd62
93 changed files with 2671 additions and 1622 deletions

View File

@@ -1,23 +1,31 @@
import type { Provider } from 'injection-js';
import { JSDOM } from 'jsdom';
import { AbstractRouter, type Navigation, type UrlTree } from 'oidc-client-rx';
export class MockRouter extends AbstractRouter {
dom = new JSDOM('', {
url: 'http://localhost',
});
navigation: Navigation = {
id: 1,
extras: {},
initialUrl: new URL('https://localhost/'),
extractedUrl: new URL('https://localhost/'),
initialUrl: this.parseUrl(this.dom.window.location.href),
extractedUrl: this.parseUrl(this.dom.window.location.href),
trigger: 'imperative',
previousNavigation: null,
};
navigateByUrl(url: string): void {
const prevNavigation = this.navigation;
this.dom.reconfigure({
url: new URL(url, this.dom.window.location.href).href,
});
this.navigation = {
id: prevNavigation.id + 1,
extras: {},
initialUrl: prevNavigation.initialUrl,
extractedUrl: new URL(url),
extractedUrl: this.parseUrl(this.dom.window.location.href),
trigger: prevNavigation.trigger,
previousNavigation: prevNavigation,
};
@@ -26,7 +34,8 @@ export class MockRouter extends AbstractRouter {
return this.navigation;
}
parseUrl(url: string): UrlTree {
return new URL(url);
const u = new URL(url, this.dom.window.location.href);
return `${u.pathname}${u.search}${u.hash}`;
}
}