fix(tests): fix all 39 failing specs and re-enable pre-commit hook

- Fix circular dependency in guildwar-attack/defence: import FortificationCardContentComponent directly instead of via @components/shared barrel
- Add index === -1 guard in guildwar-attack, guildwar-defence, guildwar-teams _setChampionsByPower to avoid crash when members input is empty
- Fix MembersStatisticsComponent to guard against undefined member in ngOnInit
- Fix JumpComponent: initialize jump with sautants/author defaults to avoid template crash
- Add provideRouter([]), provideHttpClient(), provideAnimations(), provideNativeDateAdapter() to 26 spec files missing them
- Register Chart.js scales in chart component specs
- Rewrite FrenchPaginator spec to instantiate service directly
- Fix AppComponent spec assertions to match actual component
- Re-enable npm test in .husky/pre-commit
This commit is contained in:
2026-04-26 05:28:58 +02:00
parent 8cdd03b28b
commit b645f28daf
40 changed files with 358 additions and 74 deletions
@@ -1,5 +1,10 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { Chart, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement } from 'chart.js';
Chart.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement);
import { MenuItems } from '@components/shared';
import { AeronefsBarComponent } from './aeronefs-bar.component';
describe('AeronefsBarComponent', () => {
@@ -7,9 +12,14 @@ describe('AeronefsBarComponent', () => {
let fixture: ComponentFixture<AeronefsBarComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [AeronefsBarComponent]
})
TestBed.configureTestingModule({
imports: [AeronefsBarComponent],
providers: [
provideHttpClient(),
provideAnimations(),
MenuItems,
],
})
.compileComponents();
}));
@@ -1,5 +1,10 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { Chart, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement, DoughnutController, PieController } from 'chart.js';
Chart.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement, DoughnutController, PieController);
import { MenuItems } from '@components/shared';
import { AeronefsPieComponent } from './aeronefs-pie.component';
describe('AeronefsPieComponent', () => {
@@ -8,8 +13,13 @@ describe('AeronefsPieComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [AeronefsPieComponent]
})
imports: [AeronefsPieComponent],
providers: [
provideHttpClient(),
provideAnimations(),
MenuItems,
],
})
.compileComponents();
}));
@@ -1,5 +1,10 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { Chart, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement, DoughnutController, PieController } from 'chart.js';
Chart.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement, DoughnutController, PieController);
import { MenuItems } from '@components/shared';
import { CanopiesModelsComponent } from './canopies-models.component';
describe('CanopiesModelsComponent', () => {
@@ -8,8 +13,13 @@ describe('CanopiesModelsComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [CanopiesModelsComponent]
})
imports: [CanopiesModelsComponent],
providers: [
provideHttpClient(),
provideAnimations(),
MenuItems,
],
})
.compileComponents();
}));
@@ -1,5 +1,10 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { Chart, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement, DoughnutController, PieController } from 'chart.js';
Chart.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement, DoughnutController, PieController);
import { MenuItems } from '@components/shared';
import { CanopiesSizesComponent } from './canopies-sizes.component';
describe('CanopiesSizesComponent', () => {
@@ -8,8 +13,13 @@ describe('CanopiesSizesComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [CanopiesSizesComponent]
})
imports: [CanopiesSizesComponent],
providers: [
provideHttpClient(),
provideAnimations(),
MenuItems,
],
})
.compileComponents();
}));
@@ -1,5 +1,10 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { Chart, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement } from 'chart.js';
Chart.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement);
import { MenuItems } from '@components/shared';
import { DropzonesBarComponent } from './dropzones-bar.component';
describe('DropzonesBarComponent', () => {
@@ -8,8 +13,13 @@ describe('DropzonesBarComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [DropzonesBarComponent]
})
imports: [DropzonesBarComponent],
providers: [
provideHttpClient(),
provideAnimations(),
MenuItems,
],
})
.compileComponents();
}));
@@ -1,5 +1,10 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { Chart, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement, DoughnutController, PieController } from 'chart.js';
Chart.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement, LineElement, PointElement, DoughnutController, PieController);
import { MenuItems } from '@components/shared';
import { DropzonesPieComponent } from './dropzones-pie.component';
describe('DropzonesPieComponent', () => {
@@ -8,8 +13,13 @@ describe('DropzonesPieComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [DropzonesPieComponent]
})
imports: [DropzonesPieComponent],
providers: [
provideHttpClient(),
provideAnimations(),
MenuItems,
],
})
.compileComponents();
}));
@@ -1,5 +1,8 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { MenuItems } from '@components/shared';
import { JumpsByMonthComponent } from './jumps-by-month.component';
describe('JumpsByMonthComponent', () => {
@@ -7,9 +10,14 @@ describe('JumpsByMonthComponent', () => {
let fixture: ComponentFixture<JumpsByMonthComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [JumpsByMonthComponent]
})
TestBed.configureTestingModule({
imports: [JumpsByMonthComponent],
providers: [
provideHttpClient(),
provideAnimations(),
MenuItems,
],
})
.compileComponents();
}));
@@ -1,24 +1,14 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FrenchPaginator } from './french-paginator.component';
describe('FrenchPaginator', () => {
let component: FrenchPaginator;
let fixture: ComponentFixture<FrenchPaginator>;
let paginator: FrenchPaginator;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FrenchPaginator]
})
.compileComponents();
fixture = TestBed.createComponent(FrenchPaginator);
component = fixture.componentInstance;
fixture.detectChanges();
beforeEach(() => {
paginator = new FrenchPaginator();
});
it('should create', () => {
expect(component).toBeTruthy();
expect(paginator).toBeTruthy();
});
});
@@ -1,4 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideAnimations } from '@angular/platform-browser/animations';
import { provideNativeDateAdapter } from '@angular/material/core';
import { GuildraidsLogComponent } from './guildraids-log.component';
@@ -8,7 +10,11 @@ describe('GuildraidsLogComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [GuildraidsLogComponent]
imports: [GuildraidsLogComponent],
providers: [
provideAnimations(),
provideNativeDateAdapter(),
],
})
.compileComponents();
@@ -4,7 +4,7 @@ import { MatCardModule } from '@angular/material/card';
import { MatDividerModule } from '@angular/material/divider';
import { MatIconModule } from '@angular/material/icon';
import { FortificationCardContentComponent } from '@components/shared';
import { FortificationCardContentComponent } from '../fortification-card-content/fortification-card-content.component';
import {
HWGuildWarEnemySlot, HWGuildWarEnemyTeam, HWGuildWarFortification,
HWGuildWarHeroTeam, HWGuildWarTitanTeam, HWGuildWarSlots, HWMember
@@ -194,6 +194,7 @@ export class GuildwarAttackComponent implements OnInit {
private _setChampionsByPower(): void {
for (const [teamId, teamValues] of Object.entries(guildWarData.teams)) {
const index = this.guildMembers.findIndex(member => member.id === teamId);
if (index === -1) continue;
let totalHeroPower = 0;
let totalTitanPower = 0;
const heroes: HWGuildWarHeroTeam[] = [];
@@ -4,7 +4,7 @@ import { MatCardModule } from '@angular/material/card';
import { MatDividerModule } from '@angular/material/divider';
import { MatIconModule } from '@angular/material/icon';
import { FortificationCardContentComponent } from '@components/shared';
import { FortificationCardContentComponent } from '../fortification-card-content/fortification-card-content.component';
//import { HWMember } from '@models';
import { HWGuildWarFortification, HWGuildWarHeroTeam, HWGuildWarSlots, HWGuildWarTitanTeam, HWMember } from '@models';
@@ -41,6 +41,7 @@ export class GuildwarDefenceComponent implements OnInit {
ngOnInit() {
for (const [teamId, teamValues] of Object.entries(guildWarData.teams)) {
const index = this.guildMembers.findIndex(member => member.id === teamId);
if (index === -1) continue;
let totalHeroPower = 0;
let totalTitanPower = 0;
const heroes: HWGuildWarHeroTeam[] = [];
@@ -82,15 +83,16 @@ export class GuildwarDefenceComponent implements OnInit {
const slots: HWGuildWarSlots = guildWarSlots.slots;
let count = 0;
indexes.forEach((data) => {
const member = this._championsByPower[data];
if (!member) return;
switch (type) {
case 'heroes':
//console.log(name, data, this._championsByPower[data]);
teams.push(this._championsByPower[data]);
count += this._championsByPower[data].heroes.power;
teams.push(member);
count += member.heroes.power;
break;
case 'titans':
teams.push(this._championsByPower[data]);
count += this._championsByPower[data].titans.power;
teams.push(member);
count += member.titans.power;
break;
default:
break;
@@ -48,6 +48,7 @@ export class GuildwarTeamsComponent implements OnInit {
for (const [teamId, teamValues] of Object.entries(guildWarData.teams)) {
const index = this._championsByPower.findIndex(member => member.id === teamId);
if (index === -1) continue;
let totalHeroPower = 0;
let totalTitanPower = 0;
const heroes: HWGuildWarHeroTeam[] = [];
@@ -94,6 +94,8 @@ export class MembersStatisticsComponent implements OnInit {
const index = this._membersByName.findIndex(member => member.id === data[1].userId);
if (index !== -1) {
this._membersByName[index].stat = stat;
} else {
continue;
}
this._membersByName[index].score = (this._membersByName[index].stat.dungeonActivitySum + this._membersByName[index].stat.activitySum + this._membersByName[index].stat.prestigeSum);
this._membersByName[index].warGifts = (((guildData.clan.giftsCount / 2) * ((this._membersByName[index].clanWarSum * 10) / 100)) / 20);
@@ -1,4 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideRouter } from '@angular/router';
import { provideHttpClient } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { FullComponent } from './full.component';
@@ -8,7 +11,12 @@ describe('FullComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FullComponent]
imports: [FullComponent],
providers: [
provideRouter([]),
provideHttpClient(),
provideAnimations(),
],
})
.compileComponents();
@@ -1,4 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideRouter } from '@angular/router';
import { provideHttpClient } from '@angular/common/http';
import { HeaderComponent } from './header.component';
@@ -8,7 +10,11 @@ describe('HeaderComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HeaderComponent]
imports: [HeaderComponent],
providers: [
provideRouter([]),
provideHttpClient(),
],
})
.compileComponents();