mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Fix test without it's/it's not running because they are in a waitForAsync function
This commit is contained in:
@@ -12,14 +12,13 @@ describe('Item', () => {
|
||||
const bitstream1Path = 'document.pdf';
|
||||
const bitstream2Path = 'otherfile.doc';
|
||||
|
||||
const nonExistingBundleName = 'c1e568f7-d14e-496b-bdd7-07026998cc00';
|
||||
let bitstreams;
|
||||
let remoteDataThumbnail;
|
||||
let remoteDataThumbnailList;
|
||||
let remoteDataFiles;
|
||||
let remoteDataBundles;
|
||||
|
||||
beforeEach(() => {
|
||||
it('should be possible to create an Item without any errors', () => {
|
||||
const thumbnail = {
|
||||
content: thumbnailPath
|
||||
};
|
||||
@@ -51,5 +50,6 @@ describe('Item', () => {
|
||||
remoteDataBundles = createSuccessfulRemoteDataObject$(createPaginatedList(bundles));
|
||||
|
||||
item = Object.assign(new Item(), { bundles: remoteDataBundles });
|
||||
expect().nothing();
|
||||
});
|
||||
});
|
||||
|
@@ -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', () => {
|
||||
beforeEach((done) => {
|
||||
comp.dropBitstream(bundle, {
|
||||
|
@@ -37,8 +37,8 @@ describe('ItemPageFieldComponent', () => {
|
||||
}
|
||||
});
|
||||
|
||||
const buildTestEnvironment = async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
beforeEach(waitForAsync(() => {
|
||||
void TestBed.configureTestingModule({
|
||||
imports: [
|
||||
RouterTestingModule.withRoutes([]),
|
||||
TranslateModule.forRoot({
|
||||
@@ -65,19 +65,16 @@ describe('ItemPageFieldComponent', () => {
|
||||
comp.fields = mockFields;
|
||||
comp.label = mockLabel;
|
||||
fixture.detectChanges();
|
||||
};
|
||||
|
||||
it('should display display the correct metadata value', waitForAsync(async () => {
|
||||
await buildTestEnvironment();
|
||||
expect(fixture.nativeElement.innerHTML).toContain(mockValue);
|
||||
}));
|
||||
|
||||
describe('when markdown is disabled in the environment config', () => {
|
||||
it('should display display the correct metadata value', () => {
|
||||
expect(fixture.nativeElement.innerHTML).toContain(mockValue);
|
||||
});
|
||||
|
||||
beforeEach(waitForAsync(async () => {
|
||||
describe('when markdown is disabled in the environment config', () => {
|
||||
beforeEach( () => {
|
||||
appConfig.markdown.enabled = false;
|
||||
await buildTestEnvironment();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('and markdown is disabled in this component', () => {
|
||||
|
||||
@@ -105,11 +102,9 @@ describe('ItemPageFieldComponent', () => {
|
||||
});
|
||||
|
||||
describe('when markdown is enabled in the environment config', () => {
|
||||
|
||||
beforeEach(waitForAsync(async () => {
|
||||
beforeEach(() => {
|
||||
appConfig.markdown.enabled = true;
|
||||
await buildTestEnvironment();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('and markdown is disabled in this component', () => {
|
||||
|
||||
@@ -139,12 +134,13 @@ describe('ItemPageFieldComponent', () => {
|
||||
|
||||
describe('test rendering of configured browse links', () => {
|
||||
beforeEach(() => {
|
||||
appConfig.markdown.enabled = false;
|
||||
comp.enableMarkdown = true;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
waitForAsync(() => {
|
||||
it('should have a browse link', () => {
|
||||
expect(fixture.debugElement.query(By.css('a.ds-browse-link')).nativeElement.innerHTML).toContain(mockValue);
|
||||
});
|
||||
|
||||
it('should have a browse link', async () => {
|
||||
expect(fixture.debugElement.query(By.css('a.ds-browse-link')).nativeElement.innerHTML).toContain(mockValue);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -153,10 +149,9 @@ describe('ItemPageFieldComponent', () => {
|
||||
comp.urlRegex = '^test';
|
||||
fixture.detectChanges();
|
||||
});
|
||||
waitForAsync(() => {
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -165,14 +160,11 @@ describe('ItemPageFieldComponent', () => {
|
||||
comp.urlRegex = '^nope';
|
||||
fixture.detectChanges();
|
||||
});
|
||||
beforeEach(waitForAsync(() => {
|
||||
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();
|
||||
});
|
||||
}));
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
export function mockItemWithMetadataFieldsAndValue(fields: string[], value: string): Item {
|
||||
|
@@ -1,24 +1,36 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
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'), {
|
||||
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'), {
|
||||
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', () => {
|
||||
let comp: BrowseLinkMetadataListElementComponent;
|
||||
let fixture: ComponentFixture<BrowseLinkMetadataListElementComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
void TestBed.configureTestingModule({
|
||||
imports: [],
|
||||
declarations: [BrowseLinkMetadataListElementComponent],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
@@ -27,35 +39,40 @@ describe('BrowseLinkMetadataListElementComponent', () => {
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(BrowseLinkMetadataListElementComponent);
|
||||
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', () => {
|
||||
expect(fixture.debugElement.nativeElement.textContent).toContain(mockMetadataRepresentation.value);
|
||||
});
|
||||
|
||||
it('should NOT match isLink', () => {
|
||||
expect(comp.isLink).toBe(false);
|
||||
expect(comp.isLink()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
fixture = TestBed.createComponent(BrowseLinkMetadataListElementComponent);
|
||||
comp = fixture.componentInstance;
|
||||
comp.mdRepresentation = mockMetadataRepresentationWithUrl;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
describe('with metadata wit an url', () => {
|
||||
beforeEach(() => {
|
||||
comp.mdRepresentation = mockMetadataRepresentationWithUrl;
|
||||
spyOnProperty(comp.mdRepresentation, 'representationType', 'get').and.returnValue(MetadataRepresentationType.BrowseLink);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
waitForAsync(() => {
|
||||
it('should contain the value expected', () => {
|
||||
expect(fixture.debugElement.nativeElement.textContent).toContain(mockMetadataRepresentationWithUrl.value);
|
||||
});
|
||||
|
||||
it('should match isLink', () => {
|
||||
expect(comp.isLink).toBe(true);
|
||||
expect(comp.isLink()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user