Fix test without it's/it's not running because they are in a waitForAsync function

This commit is contained in:
Alexandre Vryghem
2023-07-29 19:18:58 +02:00
parent 8d84efb1a9
commit c4bff4d9c7
4 changed files with 61 additions and 66 deletions

View File

@@ -12,14 +12,13 @@ describe('Item', () => {
const bitstream1Path = 'document.pdf'; const bitstream1Path = 'document.pdf';
const bitstream2Path = 'otherfile.doc'; const bitstream2Path = 'otherfile.doc';
const nonExistingBundleName = 'c1e568f7-d14e-496b-bdd7-07026998cc00';
let bitstreams; let bitstreams;
let remoteDataThumbnail; let remoteDataThumbnail;
let remoteDataThumbnailList; let remoteDataThumbnailList;
let remoteDataFiles; let remoteDataFiles;
let remoteDataBundles; let remoteDataBundles;
beforeEach(() => { it('should be possible to create an Item without any errors', () => {
const thumbnail = { const thumbnail = {
content: thumbnailPath content: thumbnailPath
}; };
@@ -51,5 +50,6 @@ describe('Item', () => {
remoteDataBundles = createSuccessfulRemoteDataObject$(createPaginatedList(bundles)); remoteDataBundles = createSuccessfulRemoteDataObject$(createPaginatedList(bundles));
item = Object.assign(new Item(), { bundles: remoteDataBundles }); item = Object.assign(new Item(), { bundles: remoteDataBundles });
expect().nothing();
}); });
}); });

View File

@@ -191,20 +191,6 @@ describe('ItemBitstreamsComponent', () => {
}); });
}); });
describe('when dropBitstream is called', () => {
const event = {
fromIndex: 0,
toIndex: 50,
// eslint-disable-next-line no-empty,@typescript-eslint/no-empty-function
finish: () => {
}
};
beforeEach(() => {
comp.dropBitstream(bundle, event);
});
});
describe('when dropBitstream is called', () => { describe('when dropBitstream is called', () => {
beforeEach((done) => { beforeEach((done) => {
comp.dropBitstream(bundle, { comp.dropBitstream(bundle, {

View File

@@ -37,8 +37,8 @@ describe('ItemPageFieldComponent', () => {
} }
}); });
const buildTestEnvironment = async () => { beforeEach(waitForAsync(() => {
await TestBed.configureTestingModule({ void TestBed.configureTestingModule({
imports: [ imports: [
RouterTestingModule.withRoutes([]), RouterTestingModule.withRoutes([]),
TranslateModule.forRoot({ TranslateModule.forRoot({
@@ -65,19 +65,16 @@ describe('ItemPageFieldComponent', () => {
comp.fields = mockFields; comp.fields = mockFields;
comp.label = mockLabel; comp.label = mockLabel;
fixture.detectChanges(); fixture.detectChanges();
};
it('should display display the correct metadata value', waitForAsync(async () => {
await buildTestEnvironment();
expect(fixture.nativeElement.innerHTML).toContain(mockValue);
})); }));
it('should display display the correct metadata value', () => {
expect(fixture.nativeElement.innerHTML).toContain(mockValue);
});
describe('when markdown is disabled in the environment config', () => { describe('when markdown is disabled in the environment config', () => {
beforeEach( () => {
beforeEach(waitForAsync(async () => {
appConfig.markdown.enabled = false; appConfig.markdown.enabled = false;
await buildTestEnvironment(); });
}));
describe('and markdown is disabled in this component', () => { describe('and markdown is disabled in this component', () => {
@@ -105,11 +102,9 @@ describe('ItemPageFieldComponent', () => {
}); });
describe('when markdown is enabled in the environment config', () => { describe('when markdown is enabled in the environment config', () => {
beforeEach(() => {
beforeEach(waitForAsync(async () => {
appConfig.markdown.enabled = true; appConfig.markdown.enabled = true;
await buildTestEnvironment(); });
}));
describe('and markdown is disabled in this component', () => { describe('and markdown is disabled in this component', () => {
@@ -139,40 +134,37 @@ describe('ItemPageFieldComponent', () => {
describe('test rendering of configured browse links', () => { describe('test rendering of configured browse links', () => {
beforeEach(() => { beforeEach(() => {
appConfig.markdown.enabled = false;
comp.enableMarkdown = true;
fixture.detectChanges(); fixture.detectChanges();
}); });
waitForAsync(() => {
it('should have a browse link', () => { it('should have a browse link', async () => {
expect(fixture.debugElement.query(By.css('a.ds-browse-link')).nativeElement.innerHTML).toContain(mockValue); expect(fixture.debugElement.query(By.css('a.ds-browse-link')).nativeElement.innerHTML).toContain(mockValue);
}); });
}); });
});
describe('test rendering of configured regex-based links', () => { describe('test rendering of configured regex-based links', () => {
beforeEach(() => { beforeEach(() => {
comp.urlRegex = '^test'; comp.urlRegex = '^test';
fixture.detectChanges(); fixture.detectChanges();
}); });
waitForAsync(() => {
it('should have a rendered (non-browse) link since the value matches ^test', () => { it('should have a rendered (non-browse) link since the value matches ^test', () => {
expect(fixture.debugElement.query(By.css('a.ds-simple-metadata-link')).nativeElement.innerHTML).toContain(mockValue); expect(fixture.debugElement.query(By.css('a.ds-simple-metadata-link')).nativeElement.innerHTML).toContain(mockValue);
}); });
}); });
});
describe('test skipping of configured links that do NOT match regex', () => { describe('test skipping of configured links that do NOT match regex', () => {
beforeEach(() => { beforeEach(() => {
comp.urlRegex = '^nope'; comp.urlRegex = '^nope';
fixture.detectChanges(); fixture.detectChanges();
}); });
beforeEach(waitForAsync(() => {
it('should NOT have a rendered (non-browse) link since the value matches ^test', () => { it('should NOT have a rendered (non-browse) link since the value matches ^test', () => {
expect(fixture.debugElement.query(By.css('a.ds-simple-metadata-link'))).toBeNull(); expect(fixture.debugElement.query(By.css('a.ds-simple-metadata-link'))).toBeNull();
}); });
}));
}); });
}); });
export function mockItemWithMetadataFieldsAndValue(fields: string[], value: string): Item { export function mockItemWithMetadataFieldsAndValue(fields: string[], value: string): Item {

View File

@@ -1,24 +1,36 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { BrowseLinkMetadataListElementComponent } from './browse-link-metadata-list-element.component'; import { BrowseLinkMetadataListElementComponent } from './browse-link-metadata-list-element.component';
import { MetadatumRepresentation } from '../../../../core/shared/metadata-representation/metadatum/metadatum-representation.model'; import {
MetadatumRepresentation
} from '../../../../core/shared/metadata-representation/metadatum/metadatum-representation.model';
import {
MetadataRepresentationType
} from '../../../../core/shared/metadata-representation/metadata-representation.model';
import { ValueListBrowseDefinition } from '../../../../core/shared/value-list-browse-definition.model';
const mockMetadataRepresentation = Object.assign(new MetadatumRepresentation('type'), { const mockMetadataRepresentation = Object.assign(new MetadatumRepresentation('type'), {
key: 'dc.contributor.author', key: 'dc.contributor.author',
value: 'Test Author' value: 'Test Author',
}); browseDefinition: Object.assign(new ValueListBrowseDefinition(), {
id: 'author',
}),
} as Partial<MetadatumRepresentation>);
const mockMetadataRepresentationWithUrl = Object.assign(new MetadatumRepresentation('type'), { const mockMetadataRepresentationWithUrl = Object.assign(new MetadatumRepresentation('type'), {
key: 'dc.subject', key: 'dc.subject',
value: 'http://purl.org/test/subject' value: 'https://purl.org/test/subject',
}); browseDefinition: Object.assign(new ValueListBrowseDefinition(), {
id: 'subject',
}),
} as Partial<MetadatumRepresentation>);
describe('BrowseLinkMetadataListElementComponent', () => { describe('BrowseLinkMetadataListElementComponent', () => {
let comp: BrowseLinkMetadataListElementComponent; let comp: BrowseLinkMetadataListElementComponent;
let fixture: ComponentFixture<BrowseLinkMetadataListElementComponent>; let fixture: ComponentFixture<BrowseLinkMetadataListElementComponent>;
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ void TestBed.configureTestingModule({
imports: [], imports: [],
declarations: [BrowseLinkMetadataListElementComponent], declarations: [BrowseLinkMetadataListElementComponent],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
@@ -27,35 +39,40 @@ describe('BrowseLinkMetadataListElementComponent', () => {
}).compileComponents(); }).compileComponents();
})); }));
beforeEach(waitForAsync(() => { beforeEach(() => {
fixture = TestBed.createComponent(BrowseLinkMetadataListElementComponent); fixture = TestBed.createComponent(BrowseLinkMetadataListElementComponent);
comp = fixture.componentInstance; comp = fixture.componentInstance;
comp.mdRepresentation = mockMetadataRepresentation; });
fixture.detectChanges();
})); describe('with normal metadata', () => {
beforeEach(() => {
comp.mdRepresentation = mockMetadataRepresentation;
spyOnProperty(comp.mdRepresentation, 'representationType', 'get').and.returnValue(MetadataRepresentationType.BrowseLink);
fixture.detectChanges();
});
waitForAsync(() => {
it('should contain the value as a browse link', () => { it('should contain the value as a browse link', () => {
expect(fixture.debugElement.nativeElement.textContent).toContain(mockMetadataRepresentation.value); expect(fixture.debugElement.nativeElement.textContent).toContain(mockMetadataRepresentation.value);
}); });
it('should NOT match isLink', () => { it('should NOT match isLink', () => {
expect(comp.isLink).toBe(false); expect(comp.isLink()).toBe(false);
}); });
}); });
beforeEach(waitForAsync(() => { describe('with metadata wit an url', () => {
fixture = TestBed.createComponent(BrowseLinkMetadataListElementComponent); beforeEach(() => {
comp = fixture.componentInstance;
comp.mdRepresentation = mockMetadataRepresentationWithUrl; comp.mdRepresentation = mockMetadataRepresentationWithUrl;
spyOnProperty(comp.mdRepresentation, 'representationType', 'get').and.returnValue(MetadataRepresentationType.BrowseLink);
fixture.detectChanges(); fixture.detectChanges();
})); });
waitForAsync(() => {
it('should contain the value expected', () => { it('should contain the value expected', () => {
expect(fixture.debugElement.nativeElement.textContent).toContain(mockMetadataRepresentationWithUrl.value); expect(fixture.debugElement.nativeElement.textContent).toContain(mockMetadataRepresentationWithUrl.value);
}); });
it('should match isLink', () => { it('should match isLink', () => {
expect(comp.isLink).toBe(true); expect(comp.isLink()).toBe(true);
}); });
}); });