Skip to content

Commit

Permalink
staging semi-working version
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-newey committed Nov 6, 2024
1 parent 4ef1022 commit f89408c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { generateAudioRecording } from "@test/fakes/AudioRecording";
import { ShallowSitesService } from "@baw-api/site/sites.service";
import { patchSharedArrayBuffer } from "src/patches/tests/testPatches";
import { testAsset } from "@test/helpers/karma";
import { assertPageInfo } from "@test/helpers/pageRoute";
import { AnnotationSearchParameters } from "../annotationSearchParameters";
import { AnnotationSearchComponent } from "./search.component";

Expand Down Expand Up @@ -149,6 +150,8 @@ describe("AnnotationSearchComponent", () => {
setup();
}));

assertPageInfo(AnnotationSearchComponent, "Search Annotations");

it("should create", () => {
expect(spectator.component).toBeInstanceOf(AnnotationSearchComponent);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createServiceFactory, SpectatorService } from "@ngneat/spectator";
import { Injector } from "@angular/core";
import { BAW_SERVICE_OPTIONS } from "@baw-api/api-common";
import { ACCOUNT } from "@baw-api/ServiceTokens";
import { MockBawApiModule } from "@baw-api/baw-apiMock.module";
import { ToastrService } from "ngx-toastr";
import { GlobalsService } from "@services/globals/globals.service";
import { Injector } from "@angular/core";
import { AssociationInjectorService } from "./association-injector.service";

describe("AssociationInjectorService", () => {
Expand All @@ -16,32 +16,33 @@ describe("AssociationInjectorService", () => {
mocks: [ToastrService],
});

async function associationInjector(): Promise<Injector> {
return await spectator.service.createInstance();
function associationInjector(): Injector {
return spectator.service.instance;
}

beforeEach(() => {
beforeEach(async () => {
spectator = createService();
spectator.service.instance = await spectator.service.createInstance();
});

it("should create", () => {
expect(spectator.service).toBeInstanceOf(AssociationInjectorService);
});

it("should have the service options injected with the correct options", async () => {
const injector = await associationInjector();
it("should have the service options injected with the correct options", () => {
const injector = associationInjector();
const bawServiceOptions = injector.get(BAW_SERVICE_OPTIONS);
expect(bawServiceOptions).toEqual({ disableNotification: true });
});

it("should provide baw-api services through the association injector", async () => {
const injector = await associationInjector();
it("should provide baw-api services through the association injector", () => {
const injector = associationInjector();
const service = injector.get(ACCOUNT.token);
expect(service).toBeProvidedBy(injector);
});

it("should use the root injector for services that don't contact the baw-api", async () => {
const injector = await associationInjector();
it("should use the root injector for services that don't contact the baw-api", () => {
const injector = associationInjector();
const service = injector.get(GlobalsService);
expect(service).not.toBeProvidedBy(injector);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ export class AssociationInjectorService {
public constructor(private injector: Injector) {
// TODO: fix this potential race condition
this.createInstance().then((instance) => {
this._instance = instance;
this.instance = instance;
});
}

public _instance?: Injector;

public get instance(): Injector {
return this._instance;
}
public instance?: Injector;

public async createInstance(): Promise<Injector> {
const imported = await import("../baw-api/ServiceProviders");
Expand Down

0 comments on commit f89408c

Please sign in to comment.