From f4cbd6ceed509a4c58e931c456986607b9a8d407 Mon Sep 17 00:00:00 2001 From: 4gray <4gray@users.noreply.github.com> Date: Sun, 29 Nov 2020 12:44:48 +0000 Subject: [PATCH] test: extend unit test for video-player component --- .../video-player.component.spec.ts | 86 +++++++++++++++---- 1 file changed, 67 insertions(+), 19 deletions(-) diff --git a/src/app/video-player/video-player.component.spec.ts b/src/app/video-player/video-player.component.spec.ts index 2ae48779e..51f4012f4 100644 --- a/src/app/video-player/video-player.component.spec.ts +++ b/src/app/video-player/video-player.component.spec.ts @@ -1,28 +1,76 @@ /* tslint:disable:no-unused-variable */ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; -import { DebugElement } from '@angular/core'; - import { VideoPlayerComponent } from './video-player.component'; +import { MockComponent, MockModule } from 'ng-mocks'; +import { ChannelListContainerComponent } from '../channel-list-container/channel-list-container.component'; +import { VjsPlayerComponent } from '../vjs-player/vjs-player.component'; +import { MatSidenavModule } from '@angular/material/sidenav'; +import { MatIconModule } from '@angular/material/icon'; +import { MatToolbarModule } from '@angular/material/toolbar'; +import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; +import { ChannelStore } from '../state/channel.store'; +import * as MOCKED_PLAYLIST from '../../mocks/playlist.json'; +import { createChannel } from '../state'; + +class MatSnackBarStub { + open(): void {} +} describe('VideoPlayerComponent', () => { - let component: VideoPlayerComponent; - let fixture: ComponentFixture; + let component: VideoPlayerComponent; + let fixture: ComponentFixture; + let store: ChannelStore; + let channels; - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ VideoPlayerComponent ] - }) - .compileComponents(); - })); + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ + MockComponent(VjsPlayerComponent), + MockComponent(VideoPlayerComponent), + MockComponent(ChannelListContainerComponent), + VideoPlayerComponent, + ], + providers: [ + { provide: MatSnackBar, useClass: MatSnackBarStub }, + ], + imports: [ + MockModule(MatSidenavModule), + MockModule(MatIconModule), + MockModule(MatToolbarModule), + ], + }).compileComponents(); + })); - beforeEach(() => { - fixture = TestBed.createComponent(VideoPlayerComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + beforeEach(() => { + fixture = TestBed.createComponent(VideoPlayerComponent); + component = fixture.componentInstance; + store = TestBed.inject(ChannelStore); + // set channels + channels = MOCKED_PLAYLIST.playlist.items.map((element) => + createChannel(element) + ); + store.upsertMany(channels); + }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + it('should create and init component', () => { + expect(component).toBeTruthy(); + spyOn(component, 'applySettings'); + fixture.detectChanges(); + expect(component.applySettings).toBeCalledTimes(1); + }); + + it('should check default component settings', () => { + fixture.detectChanges(); + expect(component.videoPlayer).toBeDefined(); + expect(component.player).toEqual('html5'); + }); + + it('should update store after channel was faved', () => { + spyOn(store, 'updateFavorite'); + const [firstChannel] = channels; + component.addToFavorites(firstChannel); + fixture.detectChanges(); + expect(store.updateFavorite).toBeCalledTimes(1); + expect(store.updateFavorite).toBeCalledWith(firstChannel) + }); });