Skip to content

Commit

Permalink
fix: move frontend unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
BeritJanssen committed Jun 21, 2024
1 parent 9b1bf19 commit 9b9785e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
21 changes: 13 additions & 8 deletions frontend/src/app/document-view/document-view.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand All @@ -20,22 +21,18 @@ 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();
});

it('should be created', () => {
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;
Expand All @@ -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();
});

});
22 changes: 1 addition & 21 deletions frontend/src/app/models/found-document.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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: [
'<em>seen</em>'
]
}
};
const document = new FoundDocument(mockTagService, mockEntityService, mockCorpus, searchResponse, maxScore);
expect(document.fieldValues['content']).toEqual(
'<mark class="entity-per">Wally</mark> was last seen in <mark class="entity-loc">Paris</mark>');
}));
});
3 changes: 1 addition & 2 deletions frontend/src/mock-data/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Corpus, NamedEntitiesResult } from '../app/models';
export class EntityServiceMock {

public getDocumentEntities(corpus: Corpus, id: string): Observable<NamedEntitiesResult> {
return of({annotations: [], entities: []})

return of({annotations: [{'content': '<span class="entity-person">Wally</span> was last seen in <span class="entity-location">Paris</span>'}], entities: ['location', 'person']})
}
}

0 comments on commit 9b9785e

Please sign in to comment.