From 9b9785eceb41d6b25f43655974a2602aab3ff41e Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Fri, 21 Jun 2024 21:23:19 +0200 Subject: [PATCH] fix: move frontend unit test --- .../document-view.component.spec.ts | 21 +++++++++++------- .../src/app/models/found-document.spec.ts | 22 +------------------ frontend/src/mock-data/entity.ts | 3 +-- 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/frontend/src/app/document-view/document-view.component.spec.ts b/frontend/src/app/document-view/document-view.component.spec.ts index f59858f51..d669f30af 100644 --- a/frontend/src/app/document-view/document-view.component.spec.ts +++ b/frontend/src/app/document-view/document-view.component.spec.ts @@ -1,4 +1,4 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import * as _ from 'lodash'; import { mockCorpus, mockField } from '../../mock-data/corpus'; @@ -7,6 +7,7 @@ import { commonTestBed } from '../common-test-bed'; import { DocumentViewComponent } from './document-view.component'; import { makeDocument } from '../../mock-data/constructor-helpers'; +import { of } from 'rxjs'; describe('DocumentViewComponent', () => { let component: DocumentViewComponent; @@ -20,10 +21,9 @@ describe('DocumentViewComponent', () => { fixture = TestBed.createComponent(DocumentViewComponent); component = fixture.componentInstance; component.corpus = _.merge({ - scanImageType: 'farout_image_type', - fields: [mockField] + scanImageType: 'farout_image_type' }, mockCorpus); - component.document = makeDocument({ great_field: 'Hello world!' }); + component.document = makeDocument({ great_field: 'Hello world!', speech: 'Wally was last seen in Paris' }); fixture.detectChanges(); }); @@ -31,11 +31,8 @@ describe('DocumentViewComponent', () => { expect(component).toBeTruthy(); }); - it('should render fields', async () => { - await fixture.whenStable(); - + it('should render fields', () => { expect(component.propertyFields).toEqual([mockField]); - const debug = fixture.debugElement.queryAll(By.css('[data-test-field-value]')); expect(debug.length).toEqual(1); // number of fields const element = debug[0].nativeElement; @@ -48,4 +45,12 @@ describe('DocumentViewComponent', () => { expect(debug[0].attributes['id']).toBe('tab-speech'); expect(debug[1].attributes['id']).toBe('tab-scan'); }); + + it('shows a named entity legend if showEntities is true', () => { + expect(fixture.debugElement.query(By.css('ia-entity-legend'))).toBeFalsy(); + component.showEntities = true; + fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('ia-entity-legend'))).toBeTruthy(); + }); + }); diff --git a/frontend/src/app/models/found-document.spec.ts b/frontend/src/app/models/found-document.spec.ts index 2c2a21cd6..b17fe8d38 100644 --- a/frontend/src/app/models/found-document.spec.ts +++ b/frontend/src/app/models/found-document.spec.ts @@ -48,7 +48,7 @@ fdescribe('FoundDocument', () => { }); }); - fit('should construct from an elasticsearch response', () => { + it('should construct from an elasticsearch response', () => { const document = new FoundDocument(mockTagService, mockEntityService, mockCorpus, mockResponse, maxScore); expect(document.id).toBe('1994_troonrede'); @@ -95,24 +95,4 @@ fdescribe('FoundDocument', () => { }); })); - it('should fetch and display named entities', fakeAsync(() => { - const searchResponse = { - _index: 'test_index', - _id: 'my_identifier', - _score: 2.9113607, - _source: { - date: '1994-09-20', - id: 'my_identifier', - content: 'Wally was last seen in Paris.' - }, - highlight: { - content: [ - 'seen' - ] - } - }; - const document = new FoundDocument(mockTagService, mockEntityService, mockCorpus, searchResponse, maxScore); - expect(document.fieldValues['content']).toEqual( - 'Wally was last seen in Paris'); - })); }); diff --git a/frontend/src/mock-data/entity.ts b/frontend/src/mock-data/entity.ts index 7f6760916..3fefbfc25 100644 --- a/frontend/src/mock-data/entity.ts +++ b/frontend/src/mock-data/entity.ts @@ -5,7 +5,6 @@ import { Corpus, NamedEntitiesResult } from '../app/models'; export class EntityServiceMock { public getDocumentEntities(corpus: Corpus, id: string): Observable { - return of({annotations: [], entities: []}) - + return of({annotations: [{'content': 'Wally was last seen in Paris'}], entities: ['location', 'person']}) } }