Skip to content

Commit 3465c1f

Browse files
author
Andrea Barbasso
committed
[DSC-2730] fix jasmine tests
1 parent edbde77 commit 3465c1f

3 files changed

Lines changed: 23 additions & 31 deletions

File tree

src/app/core/shared/metadata.utils.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const testMethod = (fn, resultKind, mapOrMaps, keyOrKeys, hitHighlights, expecte
5454
const keys = keyOrKeys instanceof Array ? keyOrKeys : [keyOrKeys];
5555
describe('and key' + (keys.length === 1 ? (' ' + keys[0]) : ('s ' + JSON.stringify(keys)))
5656
+ ' with ' + (isUndefined(filter) ? 'no filter' : 'filter ' + JSON.stringify(filter)), () => {
57-
const result = fn(mapOrMaps, keys, hitHighlights, filter, limit);
57+
const result = fn(mapOrMaps, keys, hitHighlights, filter, false, limit);
5858
let shouldReturn;
5959
if (resultKind === 'boolean') {
6060
shouldReturn = expected;
@@ -304,10 +304,9 @@ describe('Metadata', () => {
304304

305305
});
306306

307-
// TODO: check why limit seems not to be working (it returns 2 elements instead of 1)
308-
xdescribe('all method with limit', () => {
307+
describe('all method with limit', () => {
309308
const testAllWithLimit = (mapOrMaps, keyOrKeys, expected, limit) =>
310-
testMethod(Metadata.all, 'value', mapOrMaps, keyOrKeys, expected, undefined, limit);
309+
testMethod(Metadata.all, 'value', mapOrMaps, keyOrKeys, undefined, expected, undefined, limit);
311310

312311
describe('with multiMap and limit', () => {
313312
testAllWithLimit(multiMap, 'dc.title', [dcTitle1], 1);

src/app/core/shared/metadata.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class Metadata {
6464
if (Metadata.valueMatches(candidate as MetadataValue, filter)) {
6565
matches.push(candidate as MetadataValue);
6666
if (hasValue(limit) && matches.length >= limit) {
67-
return matches;
67+
return matches;
6868
}
6969
}
7070
}
@@ -89,7 +89,7 @@ export class Metadata {
8989
}
9090
}
9191
}
92-
return matches;
92+
return matches.slice(0, hasValue(limit) ? limit : matches.length);
9393
}
9494

9595
/**

src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.spec.ts

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,21 @@ describe('ItemListPreviewComponent', () => {
152152
component.object = { hitHighlights: {} } as any;
153153
});
154154

155-
// TODO: Investigate why this test is failing with ExpressionChangedAfterItHasBeenCheckedError
156-
xdescribe('When showThumbnails is true', () => {
155+
describe('When showThumbnails is true', () => {
157156
beforeEach(() => {
158157
component.item = mockItemWithAuthorAndDate;
159-
fixture.detectChanges();
158+
fixture.detectChanges(false);
160159
});
161160
it('should add the thumbnail element', () => {
162161
const thumbnail = fixture.debugElement.query(By.css('ds-thumbnail'));
163162
expect(thumbnail).toBeTruthy();
164163
});
165164
});
166165

167-
// TODO: Investigate why this test is failing with ExpressionChangedAfterItHasBeenCheckedError
168-
xdescribe('When the item has an author', () => {
166+
describe('When the item has an author', () => {
169167
beforeEach(() => {
170168
component.item = mockItemWithAuthorAndDate;
171-
fixture.detectChanges();
169+
fixture.detectChanges(false);
172170
});
173171

174172
it('should show the author paragraph', () => {
@@ -180,7 +178,7 @@ describe('ItemListPreviewComponent', () => {
180178
describe('When the item has no author', () => {
181179
beforeEach(() => {
182180
component.item = mockItemWithoutAuthorAndDate;
183-
fixture.detectChanges();
181+
fixture.detectChanges(false);
184182
});
185183

186184
it('should not show the author paragraph', () => {
@@ -189,11 +187,10 @@ describe('ItemListPreviewComponent', () => {
189187
});
190188
});
191189

192-
// TODO: Investigate why this test is failing with ExpressionChangedAfterItHasBeenCheckedError
193-
xdescribe('When the item has an issuedate', () => {
190+
describe('When the item has an issuedate', () => {
194191
beforeEach(() => {
195192
component.item = mockItemWithAuthorAndDate;
196-
fixture.detectChanges();
193+
fixture.detectChanges(false);
197194
});
198195

199196
it('should show the issuedate span', () => {
@@ -205,7 +202,7 @@ describe('ItemListPreviewComponent', () => {
205202
describe('When the item has no issuedate', () => {
206203
beforeEach(() => {
207204
component.item = mockItemWithoutAuthorAndDate;
208-
fixture.detectChanges();
205+
fixture.detectChanges(false);
209206
});
210207

211208
it('should show the issuedate empty placeholder', () => {
@@ -218,7 +215,7 @@ describe('ItemListPreviewComponent', () => {
218215
beforeEach(() => {
219216
component.item = mockItemWithEntityType;
220217
component.showLabel = true;
221-
fixture.detectChanges();
218+
fixture.detectChanges(false);
222219
});
223220

224221
it('should show the badges', () => {
@@ -231,7 +228,7 @@ describe('ItemListPreviewComponent', () => {
231228
beforeEach(() => {
232229
component.item = mockItemWithEntityType;
233230
component.showLabel = false;
234-
fixture.detectChanges();
231+
fixture.detectChanges(false);
235232
});
236233

237234
it('should not show the badges', () => {
@@ -241,12 +238,11 @@ describe('ItemListPreviewComponent', () => {
241238
});
242239

243240

244-
// TODO: Investigate why this test is failing with ExpressionChangedAfterItHasBeenCheckedError
245-
xdescribe('When truncatable section is collapsed', () => {
241+
describe('When truncatable section is collapsed', () => {
246242
beforeEach(() => {
247243
component.isCollapsed$ = of(true);
248244
component.item = mockItemWithAuthorAndDate;
249-
fixture.detectChanges();
245+
fixture.detectChanges(false);
250246
});
251247

252248
it('should show limitedMetadata', () => {
@@ -255,12 +251,11 @@ describe('ItemListPreviewComponent', () => {
255251
});
256252
});
257253

258-
// TODO: Investigate why this test is failing with ExpressionChangedAfterItHasBeenCheckedError
259-
xdescribe('When truncatable section is expanded', () => {
254+
describe('When truncatable section is expanded', () => {
260255
beforeEach(() => {
261256
component.isCollapsed$ = of(false);
262257
component.item = mockItemWithAuthorAndDate;
263-
fixture.detectChanges();
258+
fixture.detectChanges(false);
264259
});
265260

266261
it('should show allMetadata', () => {
@@ -318,24 +313,22 @@ describe('ItemListPreviewComponent', () => {
318313
component.object = { hitHighlights: {} } as any;
319314
});
320315

321-
// TODO: Investigate why this test is failing with ExpressionChangedAfterItHasBeenCheckedError
322-
xdescribe('When showThumbnails is true', () => {
316+
describe('When showThumbnails is true', () => {
323317
beforeEach(() => {
324318
component.item = mockItemWithAuthorAndDate;
325-
fixture.detectChanges();
319+
fixture.detectChanges(false);
326320
});
327321
it('should add the thumbnail element', () => {
328322
const thumbnail = fixture.debugElement.query(By.css('ds-thumbnail'));
329323
expect(thumbnail).toBeFalsy();
330324
});
331325
});
332326

333-
// TODO: Investigate why this test is failing with ExpressionChangedAfterItHasBeenCheckedError
334-
xdescribe('When showCorrection is false', () => {
327+
describe('When showCorrection is false', () => {
335328
beforeEach(() => {
336329
component.item = mockItemWithAuthorAndDate;
337330
component.showCorrection = false;
338-
fixture.detectChanges();
331+
fixture.detectChanges(false);
339332
});
340333

341334
it('should not show the correction badge', () => {

0 commit comments

Comments
 (0)