Added FE test for tweets component
This commit is contained in:
parent
c3fbb09815
commit
f8b07c24d6
@ -1,11 +1,11 @@
|
|||||||
<app-navigation [activeLink]="'tweets'"></app-navigation>
|
<app-navigation [activeLink]="'tweets'"></app-navigation>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="text-center" *ngIf="feeds.length === 0">
|
<div class="text-center feeds" *ngIf="feeds.length === 0">
|
||||||
<span>Kein RSS-Feed vorhanden</span>
|
<span>Kein RSS-Feed vorhanden</span>
|
||||||
<br>
|
<br>
|
||||||
<a routerLink="/einstellungen/editieren">RSS-Feed erstellen</a>
|
<a routerLink="/einstellungen/editieren">RSS-Feed erstellen</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-center" *ngIf="!(tweets.length > 0)">
|
<div class="text-center tweets" *ngIf="!(tweets.length > 0)">
|
||||||
<span>Keine Tweets vorhanden</span>
|
<span>Keine Tweets vorhanden</span>
|
||||||
<br>
|
<br>
|
||||||
<span>Schau später noch einmal vorbei!</span>
|
<span>Schau später noch einmal vorbei!</span>
|
||||||
|
|||||||
130
frontend/src/app/component/tweets/tweets.component.spec.ts
Normal file
130
frontend/src/app/component/tweets/tweets.component.spec.ts
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
import {TweetsComponent} from './tweets.component';
|
||||||
|
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
|
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';
|
||||||
|
import {FeedService} from "../../services/feed.service";
|
||||||
|
import {Observable} from "rxjs";
|
||||||
|
import {IFeed} from "../../interfaces/feed.interface";
|
||||||
|
import {Tweet} from "../../interfaces/interface";
|
||||||
|
import {By} from "@angular/platform-browser";
|
||||||
|
|
||||||
|
|
||||||
|
class MockSnackBar {
|
||||||
|
}
|
||||||
|
|
||||||
|
class MockMatDialog {
|
||||||
|
}
|
||||||
|
|
||||||
|
class MockNGXLogger {
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fake Feed Service
|
||||||
|
export class MockFeedService {
|
||||||
|
|
||||||
|
getFeeds(): Observable<IFeed[]> {
|
||||||
|
return new Observable<IFeed[]>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function mockFillTweets() {
|
||||||
|
|
||||||
|
for (let i = 0; i < 6; i++) {
|
||||||
|
const tweet: Tweet = {tweet_id: i, created_date: null, text: "Mock", url: "Mock", icon: null}
|
||||||
|
this.tweets.push(tweet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Component: Tweets', () => {
|
||||||
|
let fixture: ComponentFixture<TweetsComponent>;
|
||||||
|
let component: TweetsComponent;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
|
||||||
|
//Cancelling initial load and mock http calls
|
||||||
|
TweetsComponent.prototype.ngOnInit = () => {
|
||||||
|
};
|
||||||
|
TweetsComponent.prototype.fillTweets = mockFillTweets;
|
||||||
|
TweetsComponent.prototype.loadMore = mockFillTweets;
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [HttpClientTestingModule],
|
||||||
|
providers: [
|
||||||
|
{provide: HttpClient, useClass: HttpClientTestingModule},
|
||||||
|
{provide: FeedService, useClass: MockFeedService},
|
||||||
|
{provide: MatSnackBar, useClass: MockSnackBar},
|
||||||
|
{provide: MatDialog, useClass: MockMatDialog},
|
||||||
|
{provide: NGXLogger, useClass: MockNGXLogger}
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(TweetsComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('is TweetsComponent to be defined', () => {
|
||||||
|
expect(component).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('Show text if feeds are empty', () => {
|
||||||
|
expect(fixture.debugElement.query(By.css('.feeds'))).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Do not show text if feeds are filled', () => {
|
||||||
|
|
||||||
|
const feed: IFeed = {active: true, icon: null, id: 1, keywords: null, match_all_keywords: "false", url: ""};
|
||||||
|
component.feeds.push(feed);
|
||||||
|
|
||||||
|
expect(fixture.debugElement.query(By.css('.feeds'))).toBeNull();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('initial Tweets empty', () => {
|
||||||
|
|
||||||
|
expect(component.tweets.length).toEqual(0);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('Show text if tweets are empty', () => {
|
||||||
|
expect(fixture.debugElement.query(By.css('.tweets'))).toBeDefined();
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it('Do not show text if tweets are filled', () => {
|
||||||
|
|
||||||
|
component.fillTweets();
|
||||||
|
expect(fixture.debugElement.query(By.css('.tweets'))).toBeNull();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('load initial six Tweets works', () => {
|
||||||
|
component.fillTweets();
|
||||||
|
expect(component.tweets.length).toEqual(6);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('load more Tweets works', () => {
|
||||||
|
|
||||||
|
component.fillTweets();
|
||||||
|
component.loadMore();
|
||||||
|
expect(component.tweets.length).toEqual(12);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('load more Tweets twice works', () => {
|
||||||
|
|
||||||
|
component.fillTweets()
|
||||||
|
component.loadMore();
|
||||||
|
component.loadMore();
|
||||||
|
expect(component.tweets.length).toEqual(18);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
@ -1,5 +1,4 @@
|
|||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {AuthService} from '../../services/auth.service';
|
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {FeedService} from '../../services/feed.service';
|
import {FeedService} from '../../services/feed.service';
|
||||||
import {IFeed} from '../../interfaces/feed.interface';
|
import {IFeed} from '../../interfaces/feed.interface';
|
||||||
@ -23,7 +22,6 @@ export class TweetsComponent implements OnInit {
|
|||||||
feeds: IFeed[] = [];
|
feeds: IFeed[] = [];
|
||||||
|
|
||||||
constructor(private http: HttpClient,
|
constructor(private http: HttpClient,
|
||||||
private authService: AuthService,
|
|
||||||
private _feedService: FeedService,
|
private _feedService: FeedService,
|
||||||
private _snackbarService: SnackbarService,
|
private _snackbarService: SnackbarService,
|
||||||
private _dialog: MatDialog,
|
private _dialog: MatDialog,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user