From 4fa9f95058259a43f7ed1d3ca7977c8f02eaac69 Mon Sep 17 00:00:00 2001 From: Lynn Date: Sun, 22 Nov 2020 15:20:06 +0100 Subject: [PATCH] (Hopefully) Fixed addon-detail.component.spec.ts --- .../addon-detail.component.spec.ts | 58 +++++++++++++++++-- .../options-debug-section.component.spec.ts | 2 +- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/wowup-electron/src/app/components/addon-detail/addon-detail.component.spec.ts b/wowup-electron/src/app/components/addon-detail/addon-detail.component.spec.ts index 68ad2ab1..3c210f87 100644 --- a/wowup-electron/src/app/components/addon-detail/addon-detail.component.spec.ts +++ b/wowup-electron/src/app/components/addon-detail/addon-detail.component.spec.ts @@ -1,23 +1,73 @@ import { ComponentFixture, TestBed } from "@angular/core/testing"; -import { AddonDetailComponent } from "./addon-detail.component"; +import {AddonDetailComponent, AddonDetailModel} from "./addon-detail.component"; +import { CUSTOM_ELEMENTS_SCHEMA } from "@angular/core"; +import { MAT_DIALOG_DATA } from "@angular/material/dialog"; +import { AddonService } from "../../services/addons/addon.service"; +import { + TranslateCompiler, + TranslateLoader, + TranslateModule, + TranslateService, TranslateStore +} from "@ngx-translate/core"; +import { Subject} from "rxjs"; +import { AddonUpdateEvent } from "../../models/wowup/addon-update-event"; +import { HttpClient, HttpClientModule } from "@angular/common/http"; +import {httpLoaderFactory} from "../../app.module"; +import {TranslateMessageFormatCompiler} from "ngx-translate-messageformat-compiler"; +import {AddonViewModel} from "../../business-objects/my-addon-list-item"; +import {Addon} from "../../entities/addon"; describe("AddonDetailComponent", () => { let component: AddonDetailComponent; let fixture: ComponentFixture; + let addonService: AddonService; + let dialogModel: AddonDetailModel; + let addonServiceSpy: any; beforeEach(async () => { + addonServiceSpy = jasmine.createSpyObj("AddonService", ["logDebugData"], { + addonInstalled$ : new Subject().asObservable(), + }); + + const viewModel = new AddonViewModel({ + installedVersion: "1.0.0", + externalId: '52001', + } as Addon); + + dialogModel = {listItem: viewModel} as AddonDetailModel; + await TestBed.configureTestingModule({ declarations: [AddonDetailComponent], + imports: [HttpClientModule, TranslateModule.forRoot({ + loader: { + provide: TranslateLoader, + useFactory: httpLoaderFactory, + deps: [HttpClient], + }, + compiler: { + provide: TranslateCompiler, + useClass: TranslateMessageFormatCompiler, + }, + })], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + providers: [ + { provide: MAT_DIALOG_DATA, useValue: dialogModel }, + ] + }).overrideComponent(AddonDetailComponent, { + set: { + providers: [ + { provide: AddonService, useValue: addonServiceSpy }, + ]}, }).compileComponents(); - }); - beforeEach(() => { fixture = TestBed.createComponent(AddonDetailComponent); component = fixture.componentInstance; + addonService = fixture.debugElement.injector.get(AddonService); + fixture.detectChanges(); }); - it("should create", () => { + it("should create a", () => { expect(component).toBeTruthy(); }); }); diff --git a/wowup-electron/src/app/components/options-debug-section/options-debug-section.component.spec.ts b/wowup-electron/src/app/components/options-debug-section/options-debug-section.component.spec.ts index ab922896..55e54278 100644 --- a/wowup-electron/src/app/components/options-debug-section/options-debug-section.component.spec.ts +++ b/wowup-electron/src/app/components/options-debug-section/options-debug-section.component.spec.ts @@ -9,11 +9,11 @@ import { httpLoaderFactory } from "../../app.module"; describe("OptionsDebugSectionComponent", () => { let component: OptionsDebugSectionComponent; + let fixture: ComponentFixture; let addonService: AddonService; let wowUpService: WowUpService; let addonServiceSpy: any; let wowUpServiceSpy: any; - let fixture: ComponentFixture; beforeEach(async () => { addonServiceSpy = jasmine.createSpyObj(AddonService, ["logDebugData"]);