diff --git a/libs/ui/epg/src/lib/epg-source-status/epg-source-status.component.spec.ts b/libs/ui/epg/src/lib/epg-source-status/epg-source-status.component.spec.ts new file mode 100644 index 000000000..552917aed --- /dev/null +++ b/libs/ui/epg/src/lib/epg-source-status/epg-source-status.component.spec.ts @@ -0,0 +1,82 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { signal } from '@angular/core'; +import { TranslateModule } from '@ngx-translate/core'; +import { EpgProgressService } from '@iptvnator/epg/data-access'; +import { RuntimeCapabilitiesService } from '@iptvnator/services'; +import { EpgSourceStatusComponent } from './epg-source-status.component'; + +describe('EpgSourceStatusComponent', () => { + let fixture: ComponentFixture; + let component: EpgSourceStatusComponent; + let runtimeCapabilities: { supportsEpg: boolean }; + const imports = signal([]); + const originalElectron = window.electron; + + beforeEach(async () => { + runtimeCapabilities = { supportsEpg: false }; + imports.set([]); + + await TestBed.configureTestingModule({ + imports: [EpgSourceStatusComponent, TranslateModule.forRoot()], + providers: [ + { + provide: EpgProgressService, + useValue: { imports }, + }, + { + provide: RuntimeCapabilitiesService, + useValue: runtimeCapabilities, + }, + ], + }).compileComponents(); + }); + + afterEach(() => { + window.electron = originalElectron; + fixture?.destroy(); + }); + + function createComponent(url = 'https://example.com/epg.xml'): void { + fixture = TestBed.createComponent(EpgSourceStatusComponent); + component = fixture.componentInstance; + fixture.componentRef.setInput('url', url); + } + + it('does not check source freshness when runtime EPG support is disabled', async () => { + const checkEpgFreshness = jest.fn().mockResolvedValue({ + freshUrls: ['https://example.com/epg.xml'], + staleUrls: [], + }); + window.electron = { + ...window.electron, + checkEpgFreshness, + } as unknown as typeof window.electron; + createComponent(); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(checkEpgFreshness).not.toHaveBeenCalled(); + expect(component.status()).toBe('unknown'); + }); + + it('loads source freshness when runtime EPG support is enabled', async () => { + const url = 'https://example.com/epg.xml'; + const checkEpgFreshness = jest.fn().mockResolvedValue({ + freshUrls: [url], + staleUrls: [], + }); + window.electron = { + ...window.electron, + checkEpgFreshness, + } as unknown as typeof window.electron; + runtimeCapabilities.supportsEpg = true; + createComponent(url); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(checkEpgFreshness).toHaveBeenCalledWith([url], 12); + expect(component.status()).toBe('fresh'); + }); +}); diff --git a/libs/ui/epg/src/lib/epg-source-status/epg-source-status.component.ts b/libs/ui/epg/src/lib/epg-source-status/epg-source-status.component.ts index 7356a5502..a33f019e6 100644 --- a/libs/ui/epg/src/lib/epg-source-status/epg-source-status.component.ts +++ b/libs/ui/epg/src/lib/epg-source-status/epg-source-status.component.ts @@ -12,6 +12,7 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { MatTooltipModule } from '@angular/material/tooltip'; import { TranslatePipe } from '@ngx-translate/core'; import { EpgProgressService } from '@iptvnator/epg/data-access'; +import { RuntimeCapabilitiesService } from '@iptvnator/services'; type BadgeStatus = | 'loading' @@ -37,6 +38,7 @@ export class EpgSourceStatusComponent implements OnInit { readonly url = input.required(); private readonly epgProgress = inject(EpgProgressService); + private readonly runtime = inject(RuntimeCapabilitiesService); private readonly freshnessLoaded = signal(false); private readonly isFresh = signal(false); @@ -78,7 +80,7 @@ export class EpgSourceStatusComponent implements OnInit { } async ngOnInit(): Promise { - if (!window.electron?.checkEpgFreshness) { + if (!this.runtime.supportsEpg || !window.electron?.checkEpgFreshness) { return; } const url = this.url();