refactor(import): use runtime capability for url hint

This commit is contained in:
4gray committed 2026-05-22 12:30:22 +03:00
1 parent 9db5bd2b6a
commit e51dbd995e
2 files changed
+33 -1

No files matched your search

@@ -4,13 +4,21 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TranslateModule } from '@ngx-translate/core';
import { MockModule } from 'ng-mocks';
import { RuntimeCapabilitiesService } from '@iptvnator/services';
import { UrlUploadComponent } from './url-upload.component';
describe('UrlUploadComponent', () => {
let component: UrlUploadComponent;
let fixture: ComponentFixture<UrlUploadComponent>;
let runtime: {
isElectron: boolean;
};
beforeEach(waitForAsync(() => {
runtime = {
isElectron: true,
};
TestBed.configureTestingModule({
imports: [
UrlUploadComponent,
@@ -20,6 +28,12 @@ describe('UrlUploadComponent', () => {
TranslateModule.forRoot(),
NoopAnimationsModule,
],
providers: [
{
provide: RuntimeCapabilitiesService,
useValue: runtime,
},
],
}).compileComponents();
}));
@@ -33,6 +47,22 @@ describe('UrlUploadComponent', () => {
expect(component).toBeTruthy();
});
it('shows the CORS note only when Electron is unavailable', () => {
expect(
(fixture.nativeElement as HTMLElement).querySelector('.cors-note')
).toBeNull();
fixture.destroy();
runtime.isElectron = false;
fixture = TestBed.createComponent(UrlUploadComponent);
component = fixture.componentInstance;
fixture.detectChanges();
expect(
(fixture.nativeElement as HTMLElement).querySelector('.cors-note')
).not.toBeNull();
});
it('accepts an optional playlist name without affecting url validation', () => {
const testUrl = 'http://example.org/playlist.m3u';
@@ -9,6 +9,7 @@ import {
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { TranslatePipe } from '@ngx-translate/core';
import { RuntimeCapabilitiesService } from '@iptvnator/services';
@Component({
selector: 'app-url-upload',
@@ -22,12 +23,13 @@ import { TranslatePipe } from '@ngx-translate/core';
})
export class UrlUploadComponent implements OnInit {
private readonly fb = inject(FormBuilder);
private readonly runtime = inject(RuntimeCapabilitiesService);
form!: FormGroup<{
playlistName: FormControl<string>;
playlistUrl: FormControl<string>;
}>;
readonly isDesktop = !!window.electron;
readonly isDesktop = this.runtime.isElectron;
ngOnInit(): void {
const urlRegex = '(https?://.*?)';