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:
@@ -1,6 +1,7 @@
|
||||
import {beforeEach, describe, expect, it, vi} from 'vitest';
|
||||
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 {LibraryService} from '../../book/service/library.service';
|
||||
import {ShelfService} from '../../book/service/shelf.service';
|
||||
@@ -365,27 +366,27 @@ describe('MagicShelfComponent (Part 3)', () => {
|
||||
|
||||
describe('buildRuleFromData edge cases', () => {
|
||||
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);
|
||||
expect(formGroup.get('valueStart')?.value).toBeInstanceOf(Date);
|
||||
expect(formGroup.get('valueEnd')?.value).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
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);
|
||||
expect(formGroup.get('valueStart')?.value).toBe(100);
|
||||
expect(formGroup.get('valueEnd')?.value).toBe(500);
|
||||
});
|
||||
|
||||
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);
|
||||
expect(formGroup.get('value')?.value).toEqual(['READ', 'READING']);
|
||||
});
|
||||
|
||||
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);
|
||||
expect(formGroup.get('value')?.value).toBeNull();
|
||||
});
|
||||
@@ -397,7 +398,7 @@ describe('MagicShelfComponent (Part 3)', () => {
|
||||
});
|
||||
|
||||
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);
|
||||
expect(formGroup.get('value')?.value).toBe('Harry Potter');
|
||||
});
|
||||
@@ -499,7 +500,7 @@ describe('MagicShelfComponent (Part 3)', () => {
|
||||
const group = component.createGroup();
|
||||
expect(group.get('type')?.value).toBe('group');
|
||||
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', () => {
|
||||
const config = component.numericFieldConfigMap.get('title' as any);
|
||||
const config = component.numericFieldConfigMap.get('title');
|
||||
expect(config).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -654,7 +655,7 @@ describe('MagicShelfComponent (Part 3)', () => {
|
||||
};
|
||||
const result = component.buildGroupFromData(groupData);
|
||||
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);
|
||||
const nestedGroup = rulesArray.at(1);
|
||||
expect(nestedGroup.get('rules')).toBeDefined();
|
||||
|
||||
@@ -175,7 +175,7 @@ describe('magic-shelf-utils', () => {
|
||||
|
||||
it('should return value as-is for undefined type', () => {
|
||||
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', () => {
|
||||
|
||||
@@ -3,9 +3,13 @@ import 'zone.js/testing';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';
|
||||
|
||||
declare global {
|
||||
var __ANGULAR_TESTBED_INITIALIZED__: boolean | undefined;
|
||||
}
|
||||
|
||||
// Only initialize if not already initialized
|
||||
if (!(globalThis as any).__ANGULAR_TESTBED_INITIALIZED__) {
|
||||
(globalThis as any).__ANGULAR_TESTBED_INITIALIZED__ = true;
|
||||
if (!globalThis.__ANGULAR_TESTBED_INITIALIZED__) {
|
||||
globalThis.__ANGULAR_TESTBED_INITIALIZED__ = true;
|
||||
TestBed.initTestEnvironment(
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting(),
|
||||
|
||||
Vendored
+7
-7
@@ -8,7 +8,7 @@ declare module 'epubjs' {
|
||||
|
||||
export interface Navigation {
|
||||
toc: TocItem[];
|
||||
get(target: string): any;
|
||||
get(target: string): TocItem | undefined;
|
||||
}
|
||||
|
||||
export interface Location {
|
||||
@@ -47,7 +47,7 @@ declare module 'epubjs' {
|
||||
}
|
||||
|
||||
export interface Themes {
|
||||
register(name: string, theme: any): void;
|
||||
register(name: string, theme: unknown): void;
|
||||
select(name: string): void;
|
||||
override(property: string, value: string): void;
|
||||
font(name: string): void;
|
||||
@@ -61,10 +61,10 @@ declare module 'epubjs' {
|
||||
next(): Promise<void>;
|
||||
currentLocation(): Location | null;
|
||||
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: string, callback: any): void;
|
||||
off(event: string, callback: any): void;
|
||||
on(event: string, callback: (...args: unknown[]) => void): void;
|
||||
off(event: string, callback: (...args: unknown[]) => void): void;
|
||||
destroy(): void;
|
||||
}
|
||||
|
||||
@@ -91,8 +91,8 @@ declare module 'epubjs' {
|
||||
|
||||
export class EpubCFI {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user