From 25e2bb57667f6c3e432f56d810e945839bc774c5 Mon Sep 17 00:00:00 2001 From: Konstantin Schulz Date: Tue, 2 Jun 2020 16:49:20 +0200 Subject: [PATCH] added test for KWIC display --- .../app/exercise-list/exercise-list.page.html | 2 +- .../exercise-parameters.page.spec.ts | 25 +++++++++---------- mc_frontend/src/app/kwic/kwic.page.spec.ts | 11 +++++--- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/mc_frontend/src/app/exercise-list/exercise-list.page.html b/mc_frontend/src/app/exercise-list/exercise-list.page.html index 6037c23..d8458cc 100644 --- a/mc_frontend/src/app/exercise-list/exercise-list.page.html +++ b/mc_frontend/src/app/exercise-list/exercise-list.page.html @@ -100,7 +100,7 @@ - {{ 'APPLY' | translate }} diff --git a/mc_frontend/src/app/exercise-parameters/exercise-parameters.page.spec.ts b/mc_frontend/src/app/exercise-parameters/exercise-parameters.page.spec.ts index fef66dd..cb0d0de 100644 --- a/mc_frontend/src/app/exercise-parameters/exercise-parameters.page.spec.ts +++ b/mc_frontend/src/app/exercise-parameters/exercise-parameters.page.spec.ts @@ -54,27 +54,26 @@ describe('ExerciseParametersPage', () => { it('should generate an exercise', (done) => { exerciseParametersPage.corpusService.annisResponse = {solutions: []}; - exerciseParametersPage.corpusService.initCurrentCorpus().then(() => { + exerciseParametersPage.corpusService.initCurrentCorpus().then(async () => { exerciseParametersPage.corpusService.currentTextRange = new ReplaySubject(1); exerciseParametersPage.corpusService.currentTextRange.next(new TextRange({start: [], end: []})); const h5pSpy: Spy = spyOn(exerciseParametersPage, 'getH5Pexercise').and.returnValue(Promise.resolve()); + await exerciseParametersPage.generateExercise(); + expect(exerciseParametersPage.corpusService.annisResponse.solutions).toBeFalsy(); + expect(h5pSpy).toHaveBeenCalledTimes(1); + configMC.maxTextLength = 1; + exerciseParametersPage.corpusService.currentText = 'text'; exerciseParametersPage.generateExercise().then(() => { - expect(exerciseParametersPage.corpusService.annisResponse.solutions).toBeFalsy(); + }, () => { expect(h5pSpy).toHaveBeenCalledTimes(1); - configMC.maxTextLength = 1; - exerciseParametersPage.corpusService.currentText = 'text'; + configMC.maxTextLength = 0; + exerciseParametersPage.corpusService.exercise.queryItems[0].phenomenon = Phenomenon.Lemma; + exerciseParametersPage.corpusService.exercise.type = ExerciseType.matching; + exerciseParametersPage.corpusService.exercise.queryItems.push(new QueryMC({values: []})); exerciseParametersPage.generateExercise().then(() => { }, () => { expect(h5pSpy).toHaveBeenCalledTimes(1); - configMC.maxTextLength = 0; - exerciseParametersPage.corpusService.exercise.queryItems[0].phenomenon = Phenomenon.Lemma; - exerciseParametersPage.corpusService.exercise.type = ExerciseType.matching; - exerciseParametersPage.corpusService.exercise.queryItems.push(new QueryMC({values: []})); - exerciseParametersPage.generateExercise().then(() => { - }, () => { - expect(h5pSpy).toHaveBeenCalledTimes(1); - done(); - }); + done(); }); }); }); diff --git a/mc_frontend/src/app/kwic/kwic.page.spec.ts b/mc_frontend/src/app/kwic/kwic.page.spec.ts index 02b06a1..6e06d5b 100644 --- a/mc_frontend/src/app/kwic/kwic.page.spec.ts +++ b/mc_frontend/src/app/kwic/kwic.page.spec.ts @@ -9,7 +9,7 @@ import {TranslateTestingModule} from '../translate-testing/translate-testing.mod import {APP_BASE_HREF} from '@angular/common'; describe('KwicPage', () => { - let component: KwicPage; + let kwicPage: KwicPage; let fixture: ComponentFixture; beforeEach(async(() => { @@ -31,11 +31,16 @@ describe('KwicPage', () => { beforeEach(() => { fixture = TestBed.createComponent(KwicPage); - component = fixture.componentInstance; + kwicPage = fixture.componentInstance; fixture.detectChanges(); }); it('should create', () => { - expect(component).toBeTruthy(); + expect(kwicPage).toBeTruthy(); + const svgElement: SVGElement = document.querySelector(kwicPage.svgElementSelector); + expect(svgElement.innerHTML).toBeFalsy(); + kwicPage.exerciseService.kwicGraphs = ''; + kwicPage.initVisualization(); + expect(svgElement.innerHTML).toBeTruthy(); }); }); -- GitLab