mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-16 22:26:16 -08:00
Takes Angular Material off the renderer's startup path: renderer.initialBytes 1,596,201 -> 1,344,067 bytes (-252,134, 15.8%) at the branch point; merged with master, where #1928 lands the form-field defaults per component, the branch measures 1,345,807 (-188,797, 12.3% against master's baseline). The bundler keeps each module in one chunk, so one eager import of any export carries the module's whole code; each item removes the last eager importer of one Material module. - EPG progress and update panels: eager host + `@defer (when visible)` view with an `@error` notice; the startup spinner is static markup copied from mat-spinner. - LazyMatDialog: the confirm dialog service, player service, parental lock prompt and shell actions resolve MatDialog on first use. - The theme emits tokens for the 21 imported components only, through a `$material-components` list and meta.apply; tools/nx/check-material-theme-scope.mjs (CI) keeps it in step with the imports in both directions. - No provideAnimations(): Material 22 animates with CSS and reads prefers-reduced-motion itself; apps/electron-backend-e2e/src/material-motion.e2e.ts proves dialogs, selects, menus, snack-bars and tooltips animate in and out and stop under reduced motion. Its renderer had deferred every DOM removal to the end of the tick, so the catalog list now tracks the grid offset from scroll events and the player settings panel decides "focus was inside" in a microtask, both with specs that detach the view first. - The snack-bar stays, and with it button, the icon-button chunk and the CDK overlay (about 190 KB): root services inject it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
110 lines
3.6 KiB
TypeScript
110 lines
3.6 KiB
TypeScript
import { signal } from '@angular/core';
|
|
import {
|
|
ComponentFixture,
|
|
DeferBlockBehavior,
|
|
DeferBlockState,
|
|
TestBed,
|
|
} from '@angular/core/testing';
|
|
import { TranslateModule } from '@ngx-translate/core';
|
|
import {
|
|
EpgImportProgress,
|
|
EpgProgressService,
|
|
} from '@iptvnator/epg/data-access';
|
|
import { EpgProgressPanelComponent } from './epg-progress-panel.component';
|
|
|
|
describe('EpgProgressPanelComponent', () => {
|
|
const imports = signal<EpgImportProgress[]>([]);
|
|
const isVisible = signal(false);
|
|
const activeCount = signal(0);
|
|
const queuedCount = signal(0);
|
|
let fixture: ComponentFixture<EpgProgressPanelComponent>;
|
|
|
|
function setImports(items: EpgImportProgress[]): void {
|
|
imports.set(items);
|
|
isVisible.set(items.length > 0);
|
|
activeCount.set(items.filter((i) => i.status !== 'queued').length);
|
|
queuedCount.set(items.filter((i) => i.status === 'queued').length);
|
|
}
|
|
|
|
/** Lets the deferred view's chunk resolve, then renders it. */
|
|
async function settle(): Promise<void> {
|
|
fixture.detectChanges();
|
|
await fixture.whenStable();
|
|
await new Promise((resolve) => setTimeout(resolve));
|
|
fixture.detectChanges();
|
|
}
|
|
|
|
async function configure(
|
|
deferBlockBehavior = DeferBlockBehavior.Playthrough
|
|
): Promise<void> {
|
|
await TestBed.configureTestingModule({
|
|
imports: [EpgProgressPanelComponent, TranslateModule.forRoot()],
|
|
providers: [
|
|
{
|
|
provide: EpgProgressService,
|
|
useValue: {
|
|
imports,
|
|
isVisible,
|
|
activeCount,
|
|
queuedCount,
|
|
dismiss: jest.fn(),
|
|
dismissAll: jest.fn(),
|
|
retry: jest.fn(),
|
|
},
|
|
},
|
|
],
|
|
deferBlockBehavior,
|
|
}).compileComponents();
|
|
fixture = TestBed.createComponent(EpgProgressPanelComponent);
|
|
await settle();
|
|
}
|
|
|
|
beforeEach(async () => {
|
|
setImports([]);
|
|
await configure();
|
|
});
|
|
|
|
afterEach(() => fixture.destroy());
|
|
|
|
it('renders no view while no import is running', () => {
|
|
expect(
|
|
fixture.nativeElement.querySelector('app-epg-progress-panel-view')
|
|
).toBeNull();
|
|
});
|
|
|
|
it('shows the panel with the first import and hides it again when the list empties', async () => {
|
|
setImports([{ url: 'https://example.com/epg.xml', status: 'loading' }]);
|
|
await settle();
|
|
|
|
expect(
|
|
fixture.nativeElement.querySelector(
|
|
'.epg-progress-panel .import-item.status-loading'
|
|
)
|
|
).not.toBeNull();
|
|
|
|
setImports([]);
|
|
await settle();
|
|
|
|
expect(
|
|
fixture.nativeElement.querySelector('.epg-progress-panel')
|
|
).toBeNull();
|
|
});
|
|
|
|
it('tells the user when the view chunk cannot be loaded during an import', async () => {
|
|
fixture.destroy();
|
|
TestBed.resetTestingModule();
|
|
await configure(DeferBlockBehavior.Manual);
|
|
setImports([{ url: 'https://example.com/epg.xml', status: 'loading' }]);
|
|
fixture.detectChanges();
|
|
|
|
const [block] = await fixture.getDeferBlocks();
|
|
await block.render(DeferBlockState.Error);
|
|
|
|
const notice = fixture.nativeElement.querySelector('[role="alert"]');
|
|
expect(notice?.textContent).toContain('EPG.IMPORT_PANEL_UNAVAILABLE');
|
|
expect(
|
|
fixture.nativeElement.querySelector('app-epg-progress-panel-view')
|
|
).toBeNull();
|
|
});
|
|
});
|