Skip to content

Commit c4bff4d

Browse files
Fix test without it's/it's not running because they are in a waitForAsync function
1 parent 8d84efb commit c4bff4d

4 files changed

Lines changed: 60 additions & 65 deletions

File tree

src/app/core/shared/item.model.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ describe('Item', () => {
1212
const bitstream1Path = 'document.pdf';
1313
const bitstream2Path = 'otherfile.doc';
1414

15-
const nonExistingBundleName = 'c1e568f7-d14e-496b-bdd7-07026998cc00';
1615
let bitstreams;
1716
let remoteDataThumbnail;
1817
let remoteDataThumbnailList;
1918
let remoteDataFiles;
2019
let remoteDataBundles;
2120

22-
beforeEach(() => {
21+
it('should be possible to create an Item without any errors', () => {
2322
const thumbnail = {
2423
content: thumbnailPath
2524
};
@@ -51,5 +50,6 @@ describe('Item', () => {
5150
remoteDataBundles = createSuccessfulRemoteDataObject$(createPaginatedList(bundles));
5251

5352
item = Object.assign(new Item(), { bundles: remoteDataBundles });
53+
expect().nothing();
5454
});
5555
});

src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.spec.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,6 @@ describe('ItemBitstreamsComponent', () => {
191191
});
192192
});
193193

194-
describe('when dropBitstream is called', () => {
195-
const event = {
196-
fromIndex: 0,
197-
toIndex: 50,
198-
// eslint-disable-next-line no-empty,@typescript-eslint/no-empty-function
199-
finish: () => {
200-
}
201-
};
202-
203-
beforeEach(() => {
204-
comp.dropBitstream(bundle, event);
205-
});
206-
});
207-
208194
describe('when dropBitstream is called', () => {
209195
beforeEach((done) => {
210196
comp.dropBitstream(bundle, {

src/app/item-page/simple/field-components/specific-field/item-page-field.component.spec.ts

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ describe('ItemPageFieldComponent', () => {
3737
}
3838
});
3939

40-
const buildTestEnvironment = async () => {
41-
await TestBed.configureTestingModule({
40+
beforeEach(waitForAsync(() => {
41+
void TestBed.configureTestingModule({
4242
imports: [
4343
RouterTestingModule.withRoutes([]),
4444
TranslateModule.forRoot({
@@ -65,19 +65,16 @@ describe('ItemPageFieldComponent', () => {
6565
comp.fields = mockFields;
6666
comp.label = mockLabel;
6767
fixture.detectChanges();
68-
};
68+
}));
6969

70-
it('should display display the correct metadata value', waitForAsync(async () => {
71-
await buildTestEnvironment();
70+
it('should display display the correct metadata value', () => {
7271
expect(fixture.nativeElement.innerHTML).toContain(mockValue);
73-
}));
72+
});
7473

7574
describe('when markdown is disabled in the environment config', () => {
76-
77-
beforeEach(waitForAsync(async () => {
75+
beforeEach( () => {
7876
appConfig.markdown.enabled = false;
79-
await buildTestEnvironment();
80-
}));
77+
});
8178

8279
describe('and markdown is disabled in this component', () => {
8380

@@ -105,11 +102,9 @@ describe('ItemPageFieldComponent', () => {
105102
});
106103

107104
describe('when markdown is enabled in the environment config', () => {
108-
109-
beforeEach(waitForAsync(async () => {
105+
beforeEach(() => {
110106
appConfig.markdown.enabled = true;
111-
await buildTestEnvironment();
112-
}));
107+
});
113108

114109
describe('and markdown is disabled in this component', () => {
115110

@@ -139,12 +134,13 @@ describe('ItemPageFieldComponent', () => {
139134

140135
describe('test rendering of configured browse links', () => {
141136
beforeEach(() => {
137+
appConfig.markdown.enabled = false;
138+
comp.enableMarkdown = true;
142139
fixture.detectChanges();
143140
});
144-
waitForAsync(() => {
145-
it('should have a browse link', () => {
146-
expect(fixture.debugElement.query(By.css('a.ds-browse-link')).nativeElement.innerHTML).toContain(mockValue);
147-
});
141+
142+
it('should have a browse link', async () => {
143+
expect(fixture.debugElement.query(By.css('a.ds-browse-link')).nativeElement.innerHTML).toContain(mockValue);
148144
});
149145
});
150146

@@ -153,10 +149,9 @@ describe('ItemPageFieldComponent', () => {
153149
comp.urlRegex = '^test';
154150
fixture.detectChanges();
155151
});
156-
waitForAsync(() => {
157-
it('should have a rendered (non-browse) link since the value matches ^test', () => {
158-
expect(fixture.debugElement.query(By.css('a.ds-simple-metadata-link')).nativeElement.innerHTML).toContain(mockValue);
159-
});
152+
153+
it('should have a rendered (non-browse) link since the value matches ^test', () => {
154+
expect(fixture.debugElement.query(By.css('a.ds-simple-metadata-link')).nativeElement.innerHTML).toContain(mockValue);
160155
});
161156
});
162157

@@ -165,14 +160,11 @@ describe('ItemPageFieldComponent', () => {
165160
comp.urlRegex = '^nope';
166161
fixture.detectChanges();
167162
});
168-
beforeEach(waitForAsync(() => {
169-
it('should NOT have a rendered (non-browse) link since the value matches ^test', () => {
170-
expect(fixture.debugElement.query(By.css('a.ds-simple-metadata-link'))).toBeNull();
171-
});
172-
}));
173-
});
174-
175163

164+
it('should NOT have a rendered (non-browse) link since the value matches ^test', () => {
165+
expect(fixture.debugElement.query(By.css('a.ds-simple-metadata-link'))).toBeNull();
166+
});
167+
});
176168
});
177169

178170
export function mockItemWithMetadataFieldsAndValue(fields: string[], value: string): Item {

src/app/shared/object-list/metadata-representation-list-element/browse-link/browse-link-metadata-list-element.component.spec.ts

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
22
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
33
import { BrowseLinkMetadataListElementComponent } from './browse-link-metadata-list-element.component';
4-
import { MetadatumRepresentation } from '../../../../core/shared/metadata-representation/metadatum/metadatum-representation.model';
4+
import {
5+
MetadatumRepresentation
6+
} from '../../../../core/shared/metadata-representation/metadatum/metadatum-representation.model';
7+
import {
8+
MetadataRepresentationType
9+
} from '../../../../core/shared/metadata-representation/metadata-representation.model';
10+
import { ValueListBrowseDefinition } from '../../../../core/shared/value-list-browse-definition.model';
511

612
const mockMetadataRepresentation = Object.assign(new MetadatumRepresentation('type'), {
713
key: 'dc.contributor.author',
8-
value: 'Test Author'
9-
});
14+
value: 'Test Author',
15+
browseDefinition: Object.assign(new ValueListBrowseDefinition(), {
16+
id: 'author',
17+
}),
18+
} as Partial<MetadatumRepresentation>);
1019

1120
const mockMetadataRepresentationWithUrl = Object.assign(new MetadatumRepresentation('type'), {
1221
key: 'dc.subject',
13-
value: 'http://purl.org/test/subject'
14-
});
22+
value: 'https://purl.org/test/subject',
23+
browseDefinition: Object.assign(new ValueListBrowseDefinition(), {
24+
id: 'subject',
25+
}),
26+
} as Partial<MetadatumRepresentation>);
1527

1628
describe('BrowseLinkMetadataListElementComponent', () => {
1729
let comp: BrowseLinkMetadataListElementComponent;
1830
let fixture: ComponentFixture<BrowseLinkMetadataListElementComponent>;
1931

2032
beforeEach(waitForAsync(() => {
21-
TestBed.configureTestingModule({
33+
void TestBed.configureTestingModule({
2234
imports: [],
2335
declarations: [BrowseLinkMetadataListElementComponent],
2436
schemas: [NO_ERRORS_SCHEMA]
@@ -27,35 +39,40 @@ describe('BrowseLinkMetadataListElementComponent', () => {
2739
}).compileComponents();
2840
}));
2941

30-
beforeEach(waitForAsync(() => {
42+
beforeEach(() => {
3143
fixture = TestBed.createComponent(BrowseLinkMetadataListElementComponent);
3244
comp = fixture.componentInstance;
33-
comp.mdRepresentation = mockMetadataRepresentation;
34-
fixture.detectChanges();
35-
}));
45+
});
46+
47+
describe('with normal metadata', () => {
48+
beforeEach(() => {
49+
comp.mdRepresentation = mockMetadataRepresentation;
50+
spyOnProperty(comp.mdRepresentation, 'representationType', 'get').and.returnValue(MetadataRepresentationType.BrowseLink);
51+
fixture.detectChanges();
52+
});
3653

37-
waitForAsync(() => {
3854
it('should contain the value as a browse link', () => {
3955
expect(fixture.debugElement.nativeElement.textContent).toContain(mockMetadataRepresentation.value);
4056
});
57+
4158
it('should NOT match isLink', () => {
42-
expect(comp.isLink).toBe(false);
59+
expect(comp.isLink()).toBe(false);
4360
});
4461
});
4562

46-
beforeEach(waitForAsync(() => {
47-
fixture = TestBed.createComponent(BrowseLinkMetadataListElementComponent);
48-
comp = fixture.componentInstance;
49-
comp.mdRepresentation = mockMetadataRepresentationWithUrl;
50-
fixture.detectChanges();
51-
}));
63+
describe('with metadata wit an url', () => {
64+
beforeEach(() => {
65+
comp.mdRepresentation = mockMetadataRepresentationWithUrl;
66+
spyOnProperty(comp.mdRepresentation, 'representationType', 'get').and.returnValue(MetadataRepresentationType.BrowseLink);
67+
fixture.detectChanges();
68+
});
5269

53-
waitForAsync(() => {
5470
it('should contain the value expected', () => {
5571
expect(fixture.debugElement.nativeElement.textContent).toContain(mockMetadataRepresentationWithUrl.value);
5672
});
73+
5774
it('should match isLink', () => {
58-
expect(comp.isLink).toBe(true);
75+
expect(comp.isLink()).toBe(true);
5976
});
6077
});
6178

0 commit comments

Comments
 (0)