chore(ui): clear test and declaration any bucket

Replace low-risk any usages in test harnesses, specs, and epubjs type declarations with concrete unions, unknown, or Angular form types so the no-explicit-any backlog starts shrinking without changing runtime behavior.

Validation: just ui lint
This commit is contained in:
James Cox
2026-04-22 17:26:50 -04:00
committed by Zach Yale
parent 878cfa09c8
commit 2e66fd30b6
4 changed files with 24 additions and 19 deletions
@@ -1,6 +1,7 @@
import {beforeEach, describe, expect, it, vi} from 'vitest'; import {beforeEach, describe, expect, it, vi} from 'vitest';
import {TestBed} from '@angular/core/testing'; import {TestBed} from '@angular/core/testing';
import {MagicShelfComponent, Rule} from './magic-shelf-component'; import {FormArray} from '@angular/forms';
import {MagicShelfComponent, Rule, RuleOperator} from './magic-shelf-component';
import {TranslocoService} from '@jsverse/transloco'; import {TranslocoService} from '@jsverse/transloco';
import {LibraryService} from '../../book/service/library.service'; import {LibraryService} from '../../book/service/library.service';
import {ShelfService} from '../../book/service/shelf.service'; import {ShelfService} from '../../book/service/shelf.service';
@@ -365,27 +366,27 @@ describe('MagicShelfComponent (Part 3)', () => {
describe('buildRuleFromData edge cases', () => { describe('buildRuleFromData edge cases', () => {
it('should handle in_between for date fields', () => { it('should handle in_between for date fields', () => {
const rule: Rule = {field: 'publishedDate', operator: 'in_between' as any, value: null, valueStart: '2024-01-01', valueEnd: '2024-12-31'}; const rule: Rule = {field: 'publishedDate', operator: 'in_between' as RuleOperator, value: null, valueStart: '2024-01-01', valueEnd: '2024-12-31'};
const formGroup = component.buildRuleFromData(rule); const formGroup = component.buildRuleFromData(rule);
expect(formGroup.get('valueStart')?.value).toBeInstanceOf(Date); expect(formGroup.get('valueStart')?.value).toBeInstanceOf(Date);
expect(formGroup.get('valueEnd')?.value).toBeInstanceOf(Date); expect(formGroup.get('valueEnd')?.value).toBeInstanceOf(Date);
}); });
it('should handle in_between for number fields', () => { it('should handle in_between for number fields', () => {
const rule: Rule = {field: 'pageCount', operator: 'in_between' as any, value: null, valueStart: 100, valueEnd: 500}; const rule: Rule = {field: 'pageCount', operator: 'in_between' as RuleOperator, value: null, valueStart: 100, valueEnd: 500};
const formGroup = component.buildRuleFromData(rule); const formGroup = component.buildRuleFromData(rule);
expect(formGroup.get('valueStart')?.value).toBe(100); expect(formGroup.get('valueStart')?.value).toBe(100);
expect(formGroup.get('valueEnd')?.value).toBe(500); expect(formGroup.get('valueEnd')?.value).toBe(500);
}); });
it('should preserve array values for includes_any', () => { it('should preserve array values for includes_any', () => {
const rule: Rule = {field: 'readStatus', operator: 'includes_any' as any, value: ['READ', 'READING']}; const rule: Rule = {field: 'readStatus', operator: 'includes_any' as RuleOperator, value: ['READ', 'READING']};
const formGroup = component.buildRuleFromData(rule); const formGroup = component.buildRuleFromData(rule);
expect(formGroup.get('value')?.value).toEqual(['READ', 'READING']); expect(formGroup.get('value')?.value).toEqual(['READ', 'READING']);
}); });
it('should handle is_empty operator with no value', () => { it('should handle is_empty operator with no value', () => {
const rule: Rule = {field: 'title', operator: 'is_empty' as any, value: null}; const rule: Rule = {field: 'title', operator: 'is_empty' as RuleOperator, value: null};
const formGroup = component.buildRuleFromData(rule); const formGroup = component.buildRuleFromData(rule);
expect(formGroup.get('value')?.value).toBeNull(); expect(formGroup.get('value')?.value).toBeNull();
}); });
@@ -397,7 +398,7 @@ describe('MagicShelfComponent (Part 3)', () => {
}); });
it('should handle string values for text fields', () => { it('should handle string values for text fields', () => {
const rule: Rule = {field: 'title', operator: 'contains' as any, value: 'Harry Potter'}; const rule: Rule = {field: 'title', operator: 'contains' as RuleOperator, value: 'Harry Potter'};
const formGroup = component.buildRuleFromData(rule); const formGroup = component.buildRuleFromData(rule);
expect(formGroup.get('value')?.value).toBe('Harry Potter'); expect(formGroup.get('value')?.value).toBe('Harry Potter');
}); });
@@ -499,7 +500,7 @@ describe('MagicShelfComponent (Part 3)', () => {
const group = component.createGroup(); const group = component.createGroup();
expect(group.get('type')?.value).toBe('group'); expect(group.get('type')?.value).toBe('group');
expect(group.get('join')?.value).toBe('and'); expect(group.get('join')?.value).toBe('and');
expect((group.get('rules') as any).length).toBe(0); expect((group.get('rules') as FormArray).length).toBe(0);
}); });
}); });
@@ -623,7 +624,7 @@ describe('MagicShelfComponent (Part 3)', () => {
}); });
it('should not contain title', () => { it('should not contain title', () => {
const config = component.numericFieldConfigMap.get('title' as any); const config = component.numericFieldConfigMap.get('title');
expect(config).toBeUndefined(); expect(config).toBeUndefined();
}); });
@@ -654,7 +655,7 @@ describe('MagicShelfComponent (Part 3)', () => {
}; };
const result = component.buildGroupFromData(groupData); const result = component.buildGroupFromData(groupData);
expect(result.get('join')?.value).toBe('or'); expect(result.get('join')?.value).toBe('or');
const rulesArray = result.get('rules') as any; const rulesArray = result.get('rules') as FormArray;
expect(rulesArray.length).toBe(2); expect(rulesArray.length).toBe(2);
const nestedGroup = rulesArray.at(1); const nestedGroup = rulesArray.at(1);
expect(nestedGroup.get('rules')).toBeDefined(); expect(nestedGroup.get('rules')).toBeDefined();
@@ -175,7 +175,7 @@ describe('magic-shelf-utils', () => {
it('should return value as-is for undefined type', () => { it('should return value as-is for undefined type', () => {
expect(parseValue('hello', undefined)).toBe('hello'); expect(parseValue('hello', undefined)).toBe('hello');
expect(parseValue('true', 'boolean' as any)).toBe('true'); expect(parseValue('true', 'boolean')).toBe('true');
}); });
it('should return arrays as-is for undefined type', () => { it('should return arrays as-is for undefined type', () => {
+6 -2
View File
@@ -3,9 +3,13 @@ import 'zone.js/testing';
import {TestBed} from '@angular/core/testing'; import {TestBed} from '@angular/core/testing';
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing'; import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';
declare global {
var __ANGULAR_TESTBED_INITIALIZED__: boolean | undefined;
}
// Only initialize if not already initialized // Only initialize if not already initialized
if (!(globalThis as any).__ANGULAR_TESTBED_INITIALIZED__) { if (!globalThis.__ANGULAR_TESTBED_INITIALIZED__) {
(globalThis as any).__ANGULAR_TESTBED_INITIALIZED__ = true; globalThis.__ANGULAR_TESTBED_INITIALIZED__ = true;
TestBed.initTestEnvironment( TestBed.initTestEnvironment(
BrowserDynamicTestingModule, BrowserDynamicTestingModule,
platformBrowserDynamicTesting(), platformBrowserDynamicTesting(),
+6 -6
View File
@@ -8,7 +8,7 @@ declare module 'epubjs' {
export interface Navigation { export interface Navigation {
toc: TocItem[]; toc: TocItem[];
get(target: string): any; get(target: string): TocItem | undefined;
} }
export interface Location { export interface Location {
@@ -47,7 +47,7 @@ declare module 'epubjs' {
} }
export interface Themes { export interface Themes {
register(name: string, theme: any): void; register(name: string, theme: unknown): void;
select(name: string): void; select(name: string): void;
override(property: string, value: string): void; override(property: string, value: string): void;
font(name: string): void; font(name: string): void;
@@ -61,10 +61,10 @@ declare module 'epubjs' {
next(): Promise<void>; next(): Promise<void>;
currentLocation(): Location | null; currentLocation(): Location | null;
on(event: 'relocated', callback: (location: Location) => void): void; on(event: 'relocated', callback: (location: Location) => void): void;
on(event: 'rendered', callback: (section: any) => void): void; on(event: 'rendered', callback: (section: unknown) => void): void;
on(event: 'keyup', callback: (event: KeyboardEvent) => void): void; on(event: 'keyup', callback: (event: KeyboardEvent) => void): void;
on(event: string, callback: any): void; on(event: string, callback: (...args: unknown[]) => void): void;
off(event: string, callback: any): void; off(event: string, callback: (...args: unknown[]) => void): void;
destroy(): void; destroy(): void;
} }
@@ -91,7 +91,7 @@ declare module 'epubjs' {
export class EpubCFI { export class EpubCFI {
compare(cfi1: string, cfi2: string): number; compare(cfi1: string, cfi2: string): number;
prototype: any; // Allow prototype access if needed prototype: unknown; // Allow prototype access if needed
} }
export default function ePub(input: string | ArrayBuffer): Book; export default function ePub(input: string | ArrayBuffer): Book;