mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
refactor(epg): gate source freshness by runtime capability
This commit is contained in:
1 parent
f974297634
commit
030c6ef89d
2 files changed
+85
-1
No files matched your search
@@ -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<EpgSourceStatusComponent>;
|
||||
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');
|
||||
});
|
||||
});
|
||||
@@ -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<string>();
|
||||
|
||||
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<void> {
|
||||
if (!window.electron?.checkEpgFreshness) {
|
||||
if (!this.runtime.supportsEpg || !window.electron?.checkEpgFreshness) {
|
||||
return;
|
||||
}
|
||||
const url = this.url();
|
||||
|
||||
Reference in new issue
Block a user