Fixed download-count.pipe.spec.ts and a possible bug in addon.utils.ts

This commit is contained in:
Lynn
2020-11-22 20:46:08 +01:00
parent 6065537f6b
commit 652ed179eb
3 changed files with 45 additions and 16 deletions

View File

@@ -10,7 +10,7 @@ import { TranslateMessageFormatCompiler } from "ngx-translate-messageformat-comp
template: `<p>{{ number | downloadCount }}</p>`,
})
class TestDownloadCountComponent {
public number: number = 1;
public number: number = 0;
}
describe("DownloadCountPipe", () => {

View File

@@ -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: `<p>{{ version | interfaceFormat }}</p>`,
})
class TestInterfaceFormatComponent {
public version: string = "";
}
describe("InterfaceFormatPipe", () => {
let directive: InterfaceFormatPipe;
let fixture: ComponentFixture<InterfaceFormatPipe>;
let component: TestInterfaceFormatComponent;
let fixture: ComponentFixture<TestInterfaceFormatComponent>;
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");
});
});

View File

@@ -31,7 +31,7 @@ export function getGameVersion(gameVersion: string): string {
return gameVersion;
}
if (gameVersion.indexOf(".") !== -1) {
if (gameVersion.toString().indexOf(".") !== -1) {
return gameVersion;
}