UNPKG

@skyux/router

Version:

This library was generated with [Nx](https://nx.dev).

143 lines (136 loc) 4.96 kB
import { SkyComponentHarness } from '@skyux/core/testing'; import * as i0 from '@angular/core'; import { InjectionToken, Inject, Injectable, NgModule } from '@angular/core'; import { SkyHrefModule, SkyHrefResolverService } from '@skyux/router'; /** * Allows interaction with a SkyHref directive during testing. */ class SkyHrefHarness extends SkyComponentHarness { /** * @internal */ static { this.hostSelector = '.sky-href'; } /** * Gets a `HarnessPredicate` that can be used to search for a * `SkyHrefHarness` that meets certain criteria. */ static with(filters) { return this.getDataSkyIdPredicate(filters); } /** * Gets the href attribute of the host element. */ async getHref() { return await (await this.host()).getAttribute('href'); } /** * Gets the visible text. */ async getText() { return await this.isVisible().then(async (visible) => { if (visible) { return await (await this.host()).text(); } return ''; }); } /** * Returns true if the text is visible. */ async isVisible() { return await (await this.host()) .matchesSelector('[hidden]') .then((hidden) => !hidden); } } const MockUserHasAccess = new InjectionToken('MockUserHasAccess'); /** * @internal */ class SkyHrefResolverMockService { constructor(userHasAccess) { this.userHasAccess = userHasAccess; } resolveHref(param) { return Promise.resolve({ url: param.url, userHasAccess: this.userHasAccess, }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: SkyHrefResolverMockService, deps: [{ token: MockUserHasAccess }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: SkyHrefResolverMockService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: SkyHrefResolverMockService, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: undefined, decorators: [{ type: Inject, args: [MockUserHasAccess] }] }] }); /** * Testing module for the `SkyHref` directive and route resolver. */ class SkyHrefTestingModule { static with(options) { return { ngModule: SkyHrefTestingModule, providers: [ { provide: MockUserHasAccess, useValue: options.userHasAccess, }, ], }; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: SkyHrefTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.15", ngImport: i0, type: SkyHrefTestingModule, exports: [SkyHrefModule] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: SkyHrefTestingModule, providers: [ SkyHrefResolverMockService, { provide: SkyHrefResolverService, useExisting: SkyHrefResolverMockService, }, { provide: MockUserHasAccess, useValue: true, }, ], imports: [SkyHrefModule] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: SkyHrefTestingModule, decorators: [{ type: NgModule, args: [{ exports: [SkyHrefModule], providers: [ SkyHrefResolverMockService, { provide: SkyHrefResolverService, useExisting: SkyHrefResolverMockService, }, { provide: MockUserHasAccess, useValue: true, }, ], }] }] }); /** * Provides testing services for the `SkyHref` directive and route resolver. * @param options Set whether the user has access to the route. */ function provideHrefTesting(options) { return [ SkyHrefResolverMockService, { provide: SkyHrefResolverService, useExisting: SkyHrefResolverMockService, }, { provide: MockUserHasAccess, useValue: !!options?.userHasAccess, }, ]; } /** * Generated bundle index. Do not edit. */ export { SkyHrefHarness, SkyHrefTestingModule, provideHrefTesting }; //# sourceMappingURL=skyux-router-testing.mjs.map