Skip to content

Commit 66fb436

Browse files
author
Andrea Barbasso
committed
[DSC-2635] fix tests
1 parent c6fede5 commit 66fb436

11 files changed

Lines changed: 34 additions & 17 deletions

File tree

src/app/core/auth/auth.effects.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ describe('AuthEffects', () => {
198198
const expected = cold('--b-', { b: new AuthenticatedErrorAction(new Error('Message Error test')) });
199199

200200
expect(authEffects.authenticated$).toBeObservable(expected);
201+
done();
201202
});
202203
});
203204

src/app/core/breadcrumbs/dso-name.service.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ describe(`DSONameService`, () => {
192192
it(`should return 'person.familyName, person.givenName'`, () => {
193193
const result = (service as any).factories.Person(mockPersonWithTitle);
194194
expect(result).toBe('User Test');
195-
expect(mockPersonWithTitle.firstMetadataValue).toHaveBeenCalledWith('person.familyName');
196-
expect(mockPersonWithTitle.firstMetadataValue).toHaveBeenCalledWith('person.givenName');
197-
expect(mockPersonWithTitle.firstMetadataValue).toHaveBeenCalledWith('dc.title');
195+
expect(mockPersonWithTitle.firstMetadataValue).toHaveBeenCalledWith('person.familyName', undefined, undefined);
196+
expect(mockPersonWithTitle.firstMetadataValue).toHaveBeenCalledWith('person.givenName', undefined, undefined);
197+
expect(mockPersonWithTitle.firstMetadataValue).toHaveBeenCalledWith('dc.title', undefined, undefined);
198198
});
199199
});
200200

src/app/core/metadata/head-tag.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('HeadTagService', () => {
172172
},
173173
});
174174
tick();
175-
expect(meta.addTag).toHaveBeenCalledWith({
175+
expect(meta.updateTag).toHaveBeenCalledWith({
176176
name: 'robots',
177177
content: 'noindex',
178178
});

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

Lines changed: 2 additions & 2 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, undefined, limit);
5858
let shouldReturn;
5959
if (resultKind === 'boolean') {
6060
shouldReturn = expected;
@@ -306,7 +306,7 @@ describe('Metadata', () => {
306306

307307
describe('all method with limit', () => {
308308
const testAllWithLimit = (mapOrMaps, keyOrKeys, expected, limit) =>
309-
testMethod(Metadata.all, 'value', mapOrMaps, keyOrKeys, expected, undefined, limit);
309+
testMethod(Metadata.all, 'value', mapOrMaps, keyOrKeys, undefined, expected, undefined, limit);
310310

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ export class Metadata {
8787
} else {
8888
matches.push(candidate as MetadataValue);
8989
}
90+
if (hasValue(limit) && matches.length >= limit) {
91+
return matches;
92+
}
9093
}
9194
}
9295
}

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/date/date.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
TranslateLoader,
1010
TranslateModule,
1111
} from '@ngx-translate/core';
12+
import { of } from 'rxjs';
1213

1314
import { LayoutField } from '../../../../../../../core/layout/models/box.model';
1415
import { LocaleService } from '../../../../../../../core/locale/locale.service';
@@ -43,7 +44,7 @@ describe('DateComponent', () => {
4344
);
4445

4546
const localeServiceMock = Object.assign({
46-
getCurrentLanguageCode: () => 'en',
47+
getCurrentLanguageCode: () => of('en'),
4748
});
4849

4950
const mockField: LayoutField = {

src/app/cris-layout/pipes/ds-date.pipe.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { of } from 'rxjs';
2+
13
import { DsDatePipe } from './ds-date.pipe';
24

35
describe('DsDatePipe', () => {
@@ -8,7 +10,7 @@ describe('DsDatePipe', () => {
810
});
911

1012
const localeServiceInstance = Object.assign({
11-
getCurrentLanguageCode: () => 'en',
13+
getCurrentLanguageCode: () => of('en'),
1214
});
1315

1416
const date = '2020-08-24';

src/app/footer/footer.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ const siteService = jasmine.createSpyObj('siteService', {
4444
find: of(site),
4545
});
4646
const localeServiceStub = {
47-
getCurrentLanguageCode(): string {
48-
return 'en';
47+
getCurrentLanguageCode() {
48+
return of('en');
4949
},
5050
};
5151

src/app/info/cms-info/cms-info.component.spec.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
ComponentFixture,
3+
fakeAsync,
34
TestBed,
5+
tick,
46
} from '@angular/core/testing';
57
import { ActivatedRoute } from '@angular/router';
68
import { Store } from '@ngrx/store';
@@ -54,8 +56,10 @@ describe('CmsInfoComponent', () => {
5456
redirectUrl = 'redirect/url';
5557
token = new AuthTokenInfo('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9');
5658
authService = jasmine.createSpyObj('authService', {
57-
isAuthenticated: observableOf(true),
59+
isAuthenticated: observableOf(false),
60+
isAuthenticationLoaded: observableOf(true),
5861
getToken: token,
62+
getAuthenticatedUserFromStore: observableOf({}),
5963
});
6064
store = jasmine.createSpyObj('store', ['dispatch']);
6165
activatedRouteStub = {
@@ -95,20 +99,22 @@ describe('CmsInfoComponent', () => {
9599
expect(component).toBeTruthy();
96100
});
97101

98-
it('should set headLabel$ when data is successfully retrieved', () => {
102+
it('should set headLabel$ when data is successfully retrieved', fakeAsync(() => {
99103
const headLabelSpy = spyOn(component.headLabel$, 'next');
100104

101105
component.ngOnInit();
106+
tick();
102107

103108
expect(headLabelSpy).toHaveBeenCalledOnceWith('info.testQualifier.head');
104-
});
109+
}));
105110

106-
it('should log a warning to console if metadata content is missing', () => {
111+
it('should log a warning to console if metadata content is missing', fakeAsync(() => {
107112
spyOn(console, 'warn');
108113
site.metadata['cris.cms.testQualifier'] = undefined;
109114

110115
component.ngOnInit();
116+
tick();
111117

112118
expect(console.warn).toHaveBeenCalledWith('Metadata cris.cms.testQualifier has no content');
113-
});
119+
}));
114120
});

src/app/shared/explore/section-component/text-section/text-section.component.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
} from '@angular/core/testing';
66
import { By } from '@angular/platform-browser';
77

8+
import { of } from 'rxjs';
9+
810
import { LocaleService } from '../../../../core/locale/locale.service';
911
import { SearchService } from '../../../../core/shared/search/search.service';
1012
import { Site } from '../../../../core/shared/site.model';
@@ -16,8 +18,8 @@ describe('TextSectionComponent', () => {
1618
let fixture: ComponentFixture<TextSectionComponent>;
1719

1820
const localeServiceStub = {
19-
getCurrentLanguageCode(): string {
20-
return 'en';
21+
getCurrentLanguageCode() {
22+
return of('en');
2123
},
2224
};
2325

0 commit comments

Comments
 (0)