From 4afa509867d84455d03910cf3ed29af383754efd Mon Sep 17 00:00:00 2001 From: rhenck <richard.henck@iqb.hu-berlin.de> Date: Wed, 1 Jun 2022 23:38:57 +0200 Subject: [PATCH] [player] Fix tests to use the new Page class --- .../components/page/page.component.spec.ts | 12 ++--------- .../pipes/always-visible-page.pipe.spec.ts | 8 ++++---- .../src/app/pipes/page-index.pipe.spec.ts | 20 +++++++++---------- .../src/app/pipes/scroll-pages.pipe.spec.ts | 6 +++--- .../src/app/pipes/valid-pages.pipe.spec.ts | 4 ++-- 5 files changed, 21 insertions(+), 29 deletions(-) diff --git a/projects/player/src/app/components/page/page.component.spec.ts b/projects/player/src/app/components/page/page.component.spec.ts index 8c1a3fa59..7c13e5629 100644 --- a/projects/player/src/app/components/page/page.component.spec.ts +++ b/projects/player/src/app/components/page/page.component.spec.ts @@ -1,5 +1,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { PageComponent } from './page.component'; +import { Page } from 'common/models/page'; describe('PageComponent', () => { let component: PageComponent; @@ -15,16 +16,7 @@ describe('PageComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(PageComponent); component = fixture.componentInstance; - component.page = { - sections: [], - hasMaxWidth: false, - maxWidth: 0, - margin: 0, - backgroundColor: 'white', - alwaysVisible: false, - alwaysVisiblePagePosition: 'left', - alwaysVisibleAspectRatio: 50 - }; + component.page = new Page(); fixture.detectChanges(); }); diff --git a/projects/player/src/app/pipes/always-visible-page.pipe.spec.ts b/projects/player/src/app/pipes/always-visible-page.pipe.spec.ts index bab9c940d..52565511c 100644 --- a/projects/player/src/app/pipes/always-visible-page.pipe.spec.ts +++ b/projects/player/src/app/pipes/always-visible-page.pipe.spec.ts @@ -4,7 +4,7 @@ import { Page } from 'common/models/page'; describe('AlwaysVisiblePagePipe', () => { - const page: Page = { + const page: Page = new Page({ hasMaxWidth: false, maxWidth: 0, margin: 0, @@ -13,13 +13,13 @@ describe('AlwaysVisiblePagePipe', () => { alwaysVisiblePagePosition: 'left', alwaysVisibleAspectRatio: 50, sections: [] - }; + }); const pipe = new AlwaysVisiblePagePipe(); it('should transform an array of pages to the always visible page of the array', () => { - const pages = [page, page, { ...page, alwaysVisible: true }]; - expect(pipe.transform(pages)).toEqual({ ...page, alwaysVisible: true }); + const pages = [page, page, { ...page, alwaysVisible: true } as Page]; + expect(pipe.transform(pages)).toEqual({ ...page, alwaysVisible: true } as Page); }); it('should transform an array of pages without any always visible page to null', () => { diff --git a/projects/player/src/app/pipes/page-index.pipe.spec.ts b/projects/player/src/app/pipes/page-index.pipe.spec.ts index 072180916..3acb646a6 100644 --- a/projects/player/src/app/pipes/page-index.pipe.spec.ts +++ b/projects/player/src/app/pipes/page-index.pipe.spec.ts @@ -3,7 +3,7 @@ import { Page } from 'common/models/page'; describe('PageIndexPipe', () => { - const page: Page = { + const page: Page = new Page({ hasMaxWidth: false, maxWidth: 0, margin: 0, @@ -12,9 +12,9 @@ describe('PageIndexPipe', () => { alwaysVisiblePagePosition: 'left', alwaysVisibleAspectRatio: 50, sections: [] - }; + }); - const page2: Page = { + const page2: Page = new Page({ hasMaxWidth: false, maxWidth: 0, margin: 0, @@ -23,33 +23,33 @@ describe('PageIndexPipe', () => { alwaysVisiblePagePosition: 'left', alwaysVisibleAspectRatio: 50, sections: [] - }; + }); const pipe = new PageIndexPipe(); it('should transform pages to the index of given page (0)', () => { - const pages = [page, page2, { ...page2, alwaysVisible: true }]; + const pages = [page, page2, { ...page2, alwaysVisible: true } as Page]; expect(pipe.transform(pages, page)).toEqual(0); }); it('should transform pages to the index of given page (not 1)', () => { - const pages = [page, page2, { ...page2, alwaysVisible: true }]; + const pages = [page, page2, { ...page2, alwaysVisible: true } as Page]; expect(pipe.transform(pages, page)).not.toEqual(1); }); it('should transform pages to the index of given page2 (1)', () => { - const pages = [page, page2, { ...page2, alwaysVisible: true }]; + const pages = [page, page2, { ...page2, alwaysVisible: true } as Page]; expect(pipe.transform(pages, page2)).toEqual(1); }); it('should transform pages to the index of unknown page (-1)', () => { - const pages = [page, { ...page2, alwaysVisible: true }]; + const pages = [page, { ...page2, alwaysVisible: true } as Page]; expect(pipe.transform(pages, page2)).toEqual(-1); }); it('should transform pages to the index of unknown page (-1)', () => { - const pages = [page, { ...page2, alwaysVisible: true }]; - expect(pipe.transform(pages, { ...page2, alwaysVisible: true })).toEqual(-1); + const pages = [page, { ...page2, alwaysVisible: true } as Page]; + expect(pipe.transform(pages, { ...page2, alwaysVisible: true } as Page)).toEqual(-1); }); }); diff --git a/projects/player/src/app/pipes/scroll-pages.pipe.spec.ts b/projects/player/src/app/pipes/scroll-pages.pipe.spec.ts index e0620054a..5c2868096 100644 --- a/projects/player/src/app/pipes/scroll-pages.pipe.spec.ts +++ b/projects/player/src/app/pipes/scroll-pages.pipe.spec.ts @@ -3,7 +3,7 @@ import { Page } from 'common/models/page'; describe('ScrollPagesPipe', () => { - const page: Page = { + const page: Page = new Page({ hasMaxWidth: false, maxWidth: 0, margin: 0, @@ -12,12 +12,12 @@ describe('ScrollPagesPipe', () => { alwaysVisiblePagePosition: 'left', alwaysVisibleAspectRatio: 50, sections: [] - }; + }); const pipe = new ScrollPagesPipe(); it('should transform 3 pages to 2 scroll pages', () => { - const pages = [page, page, { ...page, alwaysVisible: true }]; + const pages = [page, page, { ...page, alwaysVisible: true } as Page]; expect(pipe.transform(pages).length).toBe(2); }); diff --git a/projects/player/src/app/pipes/valid-pages.pipe.spec.ts b/projects/player/src/app/pipes/valid-pages.pipe.spec.ts index 88eebb0e3..ff7227170 100644 --- a/projects/player/src/app/pipes/valid-pages.pipe.spec.ts +++ b/projects/player/src/app/pipes/valid-pages.pipe.spec.ts @@ -13,7 +13,7 @@ describe('ValidPagesPipe', () => { } }; - const page: Page = { + const page = new Page({ hasMaxWidth: false, maxWidth: 0, margin: 0, @@ -22,7 +22,7 @@ describe('ValidPagesPipe', () => { alwaysVisiblePagePosition: 'left', alwaysVisibleAspectRatio: 50, sections: [] - }; + }); beforeEach(() => { TestBed -- GitLab