/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Component, Injectable, ViewChild } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { Router, RouterOutlet, ɵafterNextNavigation as afterNextNavigation } from '@angular/router';
import * as i0 from "@angular/core";
export class RootFixtureService {
createHarness() {
if (this.harness) {
throw new Error('Only one harness should be created per test.');
}
this.harness = new RouterTestingHarness(this.getRootFixture());
return this.harness;
}
getRootFixture() {
if (this.fixture !== undefined) {
return this.fixture;
}
this.fixture = TestBed.createComponent(RootCmp);
this.fixture.detectChanges();
return this.fixture;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RootFixtureService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RootFixtureService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RootFixtureService, decorators: [{
type: Injectable,
args: [{ providedIn: 'root' }]
}] });
export class RootCmp {
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RootCmp, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: RootCmp, isStandalone: true, selector: "ng-component", viewQueries: [{ propertyName: "outlet", first: true, predicate: RouterOutlet, descendants: true }], ngImport: i0, template: '', isInline: true, dependencies: [{ kind: "directive", type: RouterOutlet, selector: "router-outlet", inputs: ["name"], outputs: ["activate", "deactivate", "attach", "detach"], exportAs: ["outlet"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RootCmp, decorators: [{
type: Component,
args: [{
standalone: true,
template: '',
imports: [RouterOutlet],
}]
}], propDecorators: { outlet: [{
type: ViewChild,
args: [RouterOutlet]
}] } });
/**
* A testing harness for the `Router` to reduce the boilerplate needed to test routes and routed
* components.
*
* @publicApi
*/
export class RouterTestingHarness {
/**
* Creates a `RouterTestingHarness` instance.
*
* The `RouterTestingHarness` also creates its own root component with a `RouterOutlet` for the
* purposes of rendering route components.
*
* Throws an error if an instance has already been created.
* Use of this harness also requires `destroyAfterEach: true` in the `ModuleTeardownOptions`
*
* @param initialUrl The target of navigation to trigger before returning the harness.
*/
static async create(initialUrl) {
const harness = TestBed.inject(RootFixtureService).createHarness();
if (initialUrl !== undefined) {
await harness.navigateByUrl(initialUrl);
}
return harness;
}
/** @internal */
constructor(fixture) {
this.fixture = fixture;
}
/** Instructs the root fixture to run change detection. */
detectChanges() {
this.fixture.detectChanges();
}
/** The `DebugElement` of the `RouterOutlet` component. `null` if the outlet is not activated. */
get routeDebugElement() {
const outlet = this.fixture.componentInstance.outlet;
if (!outlet || !outlet.isActivated) {
return null;
}
return this.fixture.debugElement.query(v => v.componentInstance === outlet.component);
}
/** The native element of the `RouterOutlet` component. `null` if the outlet is not activated. */
get routeNativeElement() {
return this.routeDebugElement?.nativeElement ?? null;
}
async navigateByUrl(url, requiredRoutedComponentType) {
const router = TestBed.inject(Router);
let resolveFn;
const redirectTrackingPromise = new Promise(resolve => {
resolveFn = resolve;
});
afterNextNavigation(TestBed.inject(Router), resolveFn);
await router.navigateByUrl(url);
await redirectTrackingPromise;
this.fixture.detectChanges();
const outlet = this.fixture.componentInstance.outlet;
// The outlet might not be activated if the user is testing a navigation for a guard that
// rejects
if (outlet && outlet.isActivated && outlet.activatedRoute.component) {
const activatedComponent = outlet.component;
if (requiredRoutedComponentType !== undefined &&
!(activatedComponent instanceof requiredRoutedComponentType)) {
throw new Error(`Unexpected routed component type. Expected ${requiredRoutedComponentType.name} but got ${activatedComponent.constructor.name}`);
}
return activatedComponent;
}
else {
if (requiredRoutedComponentType !== undefined) {
throw new Error(`Unexpected routed component type. Expected ${requiredRoutedComponentType.name} but the navigation did not activate any component.`);
}
return null;
}
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyX3Rlc3RpbmdfaGFybmVzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3JvdXRlci90ZXN0aW5nL3NyYy9yb3V0ZXJfdGVzdGluZ19oYXJuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBQyxTQUFTLEVBQWdCLFVBQVUsRUFBUSxTQUFTLEVBQUMsTUFBTSxlQUFlLENBQUM7QUFDbkYsT0FBTyxFQUFtQixPQUFPLEVBQUMsTUFBTSx1QkFBdUIsQ0FBQztBQUNoRSxPQUFPLEVBQUMsTUFBTSxFQUFFLFlBQVksRUFBRSxvQkFBb0IsSUFBSSxtQkFBbUIsRUFBQyxNQUFNLGlCQUFpQixDQUFDOztBQUdsRyxNQUFNLE9BQU8sa0JBQWtCO0lBSTdCLGFBQWE7UUFDWCxJQUFJLElBQUksQ0FBQyxPQUFPLEVBQUU7WUFDaEIsTUFBTSxJQUFJLEtBQUssQ0FBQyw4Q0FBOEMsQ0FBQyxDQUFDO1NBQ2pFO1FBQ0QsSUFBSSxDQUFDLE9BQU8sR0FBRyxJQUFJLG9CQUFvQixDQUFDLElBQUksQ0FBQyxjQUFjLEVBQUUsQ0FBQyxDQUFDO1FBQy9ELE9BQU8sSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN0QixDQUFDO0lBRU8sY0FBYztRQUNwQixJQUFJLElBQUksQ0FBQyxPQUFPLEtBQUssU0FBUyxFQUFFO1lBQzlCLE9BQU8sSUFBSSxDQUFDLE9BQU8sQ0FBQztTQUNyQjtRQUNELElBQUksQ0FBQyxPQUFPLEdBQUcsT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