From 598894a7e498285512627df3a112b65a1fd31c80 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Wed, 12 May 2021 17:59:41 +0200 Subject: [PATCH] Add component tests for feed creation --- .../editieren/editieren.component.spec.ts | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 frontend/src/app/component/einstellungen/editieren/editieren.component.spec.ts diff --git a/frontend/src/app/component/einstellungen/editieren/editieren.component.spec.ts b/frontend/src/app/component/einstellungen/editieren/editieren.component.spec.ts new file mode 100644 index 0000000..759c008 --- /dev/null +++ b/frontend/src/app/component/einstellungen/editieren/editieren.component.spec.ts @@ -0,0 +1,76 @@ +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; + 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(); + }); +});