From 652ed179eb0157a46f4709256a4fcbbcd90ddc18 Mon Sep 17 00:00:00 2001 From: Lynn Date: Sun, 22 Nov 2020 20:46:08 +0100 Subject: [PATCH] Fixed download-count.pipe.spec.ts and a possible bug in addon.utils.ts --- .../src/app/pipes/download-count.pipe.spec.ts | 2 +- .../app/pipes/interface-format.pipe.spec.ts | 57 ++++++++++++++----- wowup-electron/src/app/utils/addon.utils.ts | 2 +- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/wowup-electron/src/app/pipes/download-count.pipe.spec.ts b/wowup-electron/src/app/pipes/download-count.pipe.spec.ts index eb6f8499..52de0ca5 100644 --- a/wowup-electron/src/app/pipes/download-count.pipe.spec.ts +++ b/wowup-electron/src/app/pipes/download-count.pipe.spec.ts @@ -10,7 +10,7 @@ import { TranslateMessageFormatCompiler } from "ngx-translate-messageformat-comp template: `

{{ number | downloadCount }}

`, }) class TestDownloadCountComponent { - public number: number = 1; + public number: number = 0; } describe("DownloadCountPipe", () => { diff --git a/wowup-electron/src/app/pipes/interface-format.pipe.spec.ts b/wowup-electron/src/app/pipes/interface-format.pipe.spec.ts index 354c0050..271176ad 100644 --- a/wowup-electron/src/app/pipes/interface-format.pipe.spec.ts +++ b/wowup-electron/src/app/pipes/interface-format.pipe.spec.ts @@ -1,21 +1,50 @@ -import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing"; +import { ComponentFixture, TestBed } from "@angular/core/testing"; import { InterfaceFormatPipe } from "./interface-format.pipe"; +import { Component } from "@angular/core"; + +@Component({ + template: `

{{ version | interfaceFormat }}

`, +}) +class TestInterfaceFormatComponent { + public version: string = ""; +} describe("InterfaceFormatPipe", () => { - let directive: InterfaceFormatPipe; - let fixture: ComponentFixture; + let component: TestInterfaceFormatComponent; + let fixture: ComponentFixture; - beforeEach( - waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [InterfaceFormatPipe], - }).compileComponents(); - }) - ); + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [TestInterfaceFormatComponent, InterfaceFormatPipe], + }).compileComponents(); - it("should create an instance", () => { - fixture = TestBed.createComponent(InterfaceFormatPipe); - directive = fixture.componentInstance; - expect(directive).toBeTruthy(); + fixture = TestBed.createComponent(TestInterfaceFormatComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it("should create", () => { + expect(component).toBeTruthy(); + }); + + it("should transform .toc format to semver", () => { + component.version = "90002"; + fixture.detectChanges(); + let p = fixture.debugElement.nativeElement.querySelector("p"); + expect(p.innerHTML).toBe("9.0.2"); + }); + + it("should leave any dot version alone", () => { + let p: HTMLElement; + + component.version = "0.1"; + fixture.detectChanges(); + p = fixture.debugElement.nativeElement.querySelector("p"); + expect(p.innerHTML).toBe("0.1"); + + component.version = "8.3.1"; + fixture.detectChanges(); + p = fixture.debugElement.nativeElement.querySelector("p"); + expect(p.innerHTML).toBe("8.3.1"); }); }); diff --git a/wowup-electron/src/app/utils/addon.utils.ts b/wowup-electron/src/app/utils/addon.utils.ts index c5f12f1a..4eddcf67 100644 --- a/wowup-electron/src/app/utils/addon.utils.ts +++ b/wowup-electron/src/app/utils/addon.utils.ts @@ -31,7 +31,7 @@ export function getGameVersion(gameVersion: string): string { return gameVersion; } - if (gameVersion.indexOf(".") !== -1) { + if (gameVersion.toString().indexOf(".") !== -1) { return gameVersion; }