87 lines
2.8 KiB
TypeScript
87 lines
2.8 KiB
TypeScript
import {EditierenComponent} from './editieren.component';
|
|
import {ActivatedRoute, convertToParamMap} from '@angular/router';
|
|
import {FormBuilder} from '@angular/forms';
|
|
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
|
import {of} from 'rxjs';
|
|
import {HttpClient} from '@angular/common/http';
|
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
|
import {NGXLogger} from 'ngx-logger';
|
|
import {MatDialog} from '@angular/material/dialog';
|
|
import {HttpClientTestingModule} from '@angular/common/http/testing';
|
|
|
|
class MockSnackBar {}
|
|
class MockMatDialog {}
|
|
class MockNGXLogger {}
|
|
|
|
export class MockActivatedRoute {
|
|
public paramMap = of(convertToParamMap({
|
|
id: null,
|
|
}));
|
|
}
|
|
|
|
|
|
describe('Component: Editieren', () => {
|
|
let fixture: ComponentFixture<EditierenComponent>;
|
|
let component: EditierenComponent;
|
|
|
|
beforeEach(async(() => {
|
|
TestBed.configureTestingModule({
|
|
imports: [],
|
|
providers: [
|
|
{provide: ActivatedRoute, useClass: MockActivatedRoute},
|
|
FormBuilder,
|
|
{provide: HttpClient, useClass: HttpClientTestingModule},
|
|
{provide: MatSnackBar, useClass: MockSnackBar},
|
|
{provide: MatDialog, useClass: MockMatDialog},
|
|
{provide: NGXLogger, useClass: MockNGXLogger}
|
|
]
|
|
}).compileComponents();
|
|
fixture = TestBed.createComponent(EditierenComponent);
|
|
component = fixture.componentInstance;
|
|
component.ngOnInit();
|
|
fixture.detectChanges();
|
|
}));
|
|
|
|
it('is EditierenComponent to be defined', () => {
|
|
expect(component).toBeDefined();
|
|
});
|
|
|
|
it('is form initially invalid', () => {
|
|
expect(component.feedForm.valid).toBeFalsy();
|
|
});
|
|
|
|
it('is invalid URL', () => {
|
|
component.feedForm.controls.url.setValue('ftp://rss.orf.at/news.xml');
|
|
expect(component.feedForm.controls.url.valid).toBeFalsy();
|
|
});
|
|
|
|
it('is valid URL', () => {
|
|
component.feedForm.controls.url.setValue('https://rss.orf.at/news.xml');
|
|
expect(component.feedForm.controls.url.valid).toBeTruthy();
|
|
});
|
|
|
|
it('is active set to true by default', () => {
|
|
expect(component.feedForm.controls.active.value).toEqual(true);
|
|
});
|
|
|
|
it('checks if keywords are of length > 2', () => {
|
|
component.feedForm.controls.keywords.setValue('Key, Wor, d');
|
|
expect(component.feedForm.controls.keywords.valid).toBeFalsy();
|
|
});
|
|
|
|
it('checks if keywords are of length > 2', () => {
|
|
component.feedForm.controls.keywords.setValue('Key, Wor, ddd');
|
|
expect(component.feedForm.controls.keywords.valid).toBeTruthy();
|
|
});
|
|
|
|
it('checks if max 3 keywords', () => {
|
|
component.feedForm.controls.keywords.setValue('Key, Word, ddd, ddd');
|
|
expect(component.feedForm.controls.keywords.valid).toBeFalsy();
|
|
});
|
|
|
|
it('checks if max 3 keywords with end comma', () => {
|
|
component.feedForm.controls.keywords.setValue('Key, Word, ddd,');
|
|
expect(component.feedForm.controls.keywords.valid).toBeFalsy();
|
|
});
|
|
});
|