Skip to content

Commit d4bd7a5

Browse files
committed
feat: next test fix
feat: first test fix feat: fix unit
1 parent 1cb962b commit d4bd7a5

13 files changed

Lines changed: 114 additions & 33 deletions

src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.spec.ts

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import {
1616
DynamicFormService,
1717
DynamicInputModel,
1818
} from '@ng-dynamic-forms/core';
19-
import { TranslateModule } from '@ngx-translate/core';
19+
import {
20+
TranslateModule,
21+
TranslateService,
22+
} from '@ngx-translate/core';
2023
import { Operation } from 'fast-json-patch';
2124
import { of as observableOf } from 'rxjs';
2225

@@ -28,6 +31,7 @@ import { Community } from '../../../../core/shared/community.model';
2831
import { hasValue } from '../../../empty.util';
2932
import { FormComponent } from '../../../form/form.component';
3033
import { AuthServiceMock } from '../../../mocks/auth.service.mock';
34+
import { translateServiceStub } from '../../../mocks/translate.service.mock';
3135
import { NotificationsService } from '../../../notifications/notifications.service';
3236
import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils';
3337
import { NotificationsServiceStub } from '../../../testing/notifications-service.stub';
@@ -55,8 +59,8 @@ describe('ComColFormComponent', () => {
5559
const dcTitle = 'dc.title';
5660
const dcAbstract = 'dc.description.abstract';
5761

58-
const abstractMD = { [dcAbstract]: [{ value: 'Community description', language: null }] };
59-
const newTitleMD = { [dcTitle]: [{ value: 'New Community Title', language: null }] };
62+
const abstractMD = { [dcAbstract]: [{ value: 'Community description', language: 'en_US' }] };
63+
const newTitleMD = { [dcTitle]: [{ value: 'New Community Title', language: 'en_US' }] };
6064
const formModel = [
6165
new DynamicInputModel({
6266
id: 'title',
@@ -103,6 +107,7 @@ describe('ComColFormComponent', () => {
103107
{ provide: AuthService, useValue: new AuthServiceMock() },
104108
{ provide: RequestService, useValue: requestServiceStub },
105109
{ provide: ObjectCacheService, useValue: objectCacheStub },
110+
{ provide: TranslateService, useValue: translateServiceStub },
106111
],
107112
schemas: [NO_ERRORS_SCHEMA],
108113
})
@@ -132,7 +137,7 @@ describe('ComColFormComponent', () => {
132137
describe('onSubmit', () => {
133138
beforeEach(() => {
134139
spyOn(comp.submitForm, 'emit');
135-
comp.formModel = formModel;
140+
comp.formModels.set('en_US', formModel);
136141
});
137142

138143
it('should emit the new version of the community', () => {
@@ -143,37 +148,38 @@ describe('ComColFormComponent', () => {
143148
{
144149
op: 'replace',
145150
path: '/metadata/dc.title',
146-
value: {
151+
value: [{
147152
value: 'New Community Title',
148-
language: null,
149-
},
153+
language: 'en_US',
154+
}],
150155
},
151156
{
152157
op: 'replace',
153158
path: '/metadata/dc.description.abstract',
154-
value: {
159+
value: [{
155160
value: 'Community description',
156-
language: null,
157-
},
161+
language: 'en_US',
162+
}],
158163
},
159164
];
160165

166+
const expectedDso = Object.assign({}, comp.dso, {
167+
metadata: {
168+
'dc.title': [{
169+
value: 'New Community Title',
170+
language: 'en_US',
171+
}],
172+
'dc.description.abstract': [{
173+
value: 'Community description',
174+
language: 'en_US',
175+
}],
176+
},
177+
type: Community.type,
178+
});
179+
161180
expect(comp.submitForm.emit).toHaveBeenCalledWith(
162181
{
163-
dso: Object.assign({}, comp.dso, {
164-
metadata: {
165-
'dc.title': [{
166-
value: 'New Community Title',
167-
language: null,
168-
}],
169-
'dc.description.abstract': [{
170-
value: 'Community description',
171-
language: null,
172-
}],
173-
},
174-
type: Community.type,
175-
},
176-
),
182+
dso: expectedDso,
177183
operations: operations,
178184
},
179185
);
@@ -314,8 +320,16 @@ describe('ComColFormComponent', () => {
314320
function initComponent(dso: Community) {
315321
fixture = TestBed.createComponent(ComColFormComponent);
316322
comp = fixture.componentInstance;
317-
comp.formModel = [];
323+
comp.formModels.set('en_US', formModel);
324+
comp.defaultLanguageCode = 'en_US';
318325
comp.dso = dso;
326+
comp.dso.firstMetadataValue = (name, language) => {
327+
if (name === 'dc.title') {
328+
return newTitleMD[dcTitle][0].value;
329+
} else if (name === 'dc.description.abstract') {
330+
return abstractMD[dcAbstract][0].value;
331+
}
332+
};
319333
(comp as any).type = Community.type;
320334
comp.uploaderComponent = { uploader: {} } as any;
321335

src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class ComColFormComponent<T extends Collection | Community> implements On
158158
/**
159159
* All languages used by application
160160
*/
161-
languages: LangConfig[];
161+
languages: LangConfig[] = [];
162162

163163
/**
164164
* The uploader configuration options
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1+
import { EventEmitter } from '@angular/core';
12
import { TranslateService } from '@ngx-translate/core';
3+
import { of } from 'rxjs';
24

35
export function getMockTranslateService(): TranslateService {
46
return jasmine.createSpyObj('translateService', {
57
get: jasmine.createSpy('get'),
68
use: jasmine.createSpy('use'),
79
instant: jasmine.createSpy('instant'),
810
setDefaultLang: jasmine.createSpy('setDefaultLang'),
11+
currentLang: 'en_US',
912
});
1013
}
14+
15+
export const translateServiceStub = {
16+
get: () => of('translated-text'),
17+
instant: () => 'translated-text',
18+
onLangChange: new EventEmitter(),
19+
onTranslationChange: new EventEmitter(),
20+
onDefaultLangChange: new EventEmitter(),
21+
currentLang: 'en_US',
22+
};

src/app/shared/object-list/collection-list-element/collection-list-element.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<span class="pr-2">&nbsp;</span>
99
<span *ngIf="object.archivedItemsCount >= 0" class="badge badge-pill badge-secondary align-self-center archived-items-lead">{{object.archivedItemsCount}}</span>
1010
</div>
11-
<div *ngIf="object.shortDescription" class="text-muted abstract-text">
12-
{{object.shortDescription}}
11+
<div *ngIf="object.shortDescription(translateService.currentLang) as shortDescription" class="text-muted abstract-text">
12+
{{shortDescription}}
1313
</div>

src/app/shared/object-list/collection-list-element/collection-list-element.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import {
99
} from '@angular/core/testing';
1010
import { By } from '@angular/platform-browser';
1111
import { ActivatedRoute } from '@angular/router';
12+
import { TranslateService } from '@ngx-translate/core';
1213

1314
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
1415
import { Collection } from '../../../core/shared/collection.model';
1516
import { DSONameServiceMock } from '../../mocks/dso-name.service.mock';
17+
import { translateServiceStub } from '../../mocks/translate.service.mock';
1618
import { ActivatedRouteStub } from '../../testing/active-router.stub';
1719
import { CollectionListElementComponent } from './collection-list-element.component';
1820

@@ -72,6 +74,7 @@ describe('CollectionListElementComponent', () => {
7274
{ provide: DSONameService, useValue: new DSONameServiceMock() },
7375
{ provide: 'objectElementProvider', useValue: (mockCollectionWithAbstract) },
7476
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
77+
{ provide: TranslateService, useValue: translateServiceStub },
7578
],
7679
schemas: [NO_ERRORS_SCHEMA],
7780
}).overrideComponent(CollectionListElementComponent, {

src/app/shared/object-list/collection-list-element/collection-list-element.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { NgIf } from '@angular/common';
22
import { Component } from '@angular/core';
33
import { RouterLink } from '@angular/router';
4+
import { TranslateService } from '@ngx-translate/core';
45

6+
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
57
import { Collection } from '../../../core/shared/collection.model';
68
import { ViewMode } from '../../../core/shared/view-mode.model';
79
import { listableObjectComponent } from '../../object-collection/shared/listable-object/listable-object.decorator';
@@ -18,4 +20,11 @@ import { AbstractListableElementComponent } from '../../object-collection/shared
1820
* Component representing list element for a collection
1921
*/
2022
@listableObjectComponent(Collection, ViewMode.ListElement)
21-
export class CollectionListElementComponent extends AbstractListableElementComponent<Collection> {}
23+
export class CollectionListElementComponent extends AbstractListableElementComponent<Collection> {
24+
constructor(
25+
public dsoNameService: DSONameService,
26+
public translateService: TranslateService,
27+
) {
28+
super(dsoNameService);
29+
}
30+
}

src/app/shared/object-list/community-list-element/community-list-element.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import {
99
} from '@angular/core/testing';
1010
import { By } from '@angular/platform-browser';
1111
import { ActivatedRoute } from '@angular/router';
12+
import { TranslateService } from '@ngx-translate/core';
1213

1314
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
1415
import { Community } from '../../../core/shared/community.model';
1516
import { DSONameServiceMock } from '../../mocks/dso-name.service.mock';
17+
import { translateServiceStub } from '../../mocks/translate.service.mock';
1618
import { ActivatedRouteStub } from '../../testing/active-router.stub';
1719
import { CommunityListElementComponent } from './community-list-element.component';
1820

@@ -49,6 +51,7 @@ describe('CommunityListElementComponent', () => {
4951
{ provide: DSONameService, useValue: new DSONameServiceMock() },
5052
{ provide: 'objectElementProvider', useValue: (mockCommunityWithAbstract) },
5153
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
54+
{ provide: TranslateService, useValue: translateServiceStub },
5255
],
5356
schemas: [NO_ERRORS_SCHEMA],
5457
}).overrideComponent(CommunityListElementComponent, {

src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<ds-badges *ngIf="showLabel" [object]="dso" [context]="context"></ds-badges>
55
<a *ngIf="linkType !== linkTypes.None" [target]="(linkType === linkTypes.ExternalLink) ? '_blank' : '_self'" [attr.rel]="(linkType === linkTypes.ExternalLink) ? 'noopener noreferrer' : null" [routerLink]="['/collections/' + dso.id]" class="lead" [innerHTML]="dsoTitle"></a>
66
<span *ngIf="linkType === linkTypes.None" class="lead" [innerHTML]="dsoTitle"></span>
7-
<div *ngIf="dso.shortDescription" class="text-muted abstract-text" [innerHTML]="firstMetadataValue('dc.description.abstract')"></div>
7+
<div *ngIf="dso.shortDescription(translateService.currentLang)" class="text-muted abstract-text" [innerHTML]="firstMetadataValue('dc.description.abstract')"></div>
88
</div>
99
</div>

src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import {
1010
} from '@angular/core/testing';
1111
import { By } from '@angular/platform-browser';
1212
import { ActivatedRoute } from '@angular/router';
13+
import { TranslateService } from '@ngx-translate/core';
1314
import { of as observableOf } from 'rxjs';
1415

1516
import { APP_CONFIG } from '../../../../../config/app-config.interface';
1617
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
1718
import { Collection } from '../../../../core/shared/collection.model';
1819
import { DSONameServiceMock } from '../../../mocks/dso-name.service.mock';
20+
import { translateServiceStub } from '../../../mocks/translate.service.mock';
1921
import { CollectionSearchResult } from '../../../object-collection/shared/collection-search-result.model';
2022
import { ActivatedRouteStub } from '../../../testing/active-router.stub';
2123
import { TruncatableService } from '../../../truncatable/truncatable.service';
@@ -73,6 +75,7 @@ describe('CollectionSearchResultListElementComponent', () => {
7375
{ provide: APP_CONFIG, useValue: environmentUseThumbs },
7476
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
7577
{ provide: ThemeService, useValue: getMockThemeService() },
78+
{ provide: TranslateService, useValue: translateServiceStub },
7679
],
7780
schemas: [NO_ERRORS_SCHEMA],
7881
}).overrideComponent(CollectionSearchResultListElementComponent, {

src/app/shared/object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@ import {
22
NgClass,
33
NgIf,
44
} from '@angular/common';
5-
import { Component } from '@angular/core';
5+
import {
6+
Component,
7+
Inject,
8+
} from '@angular/core';
69
import { RouterLink } from '@angular/router';
10+
import { TranslateService } from '@ngx-translate/core';
711

12+
import {
13+
APP_CONFIG,
14+
AppConfig,
15+
} from '../../../../../config/app-config.interface';
16+
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
817
import { Collection } from '../../../../core/shared/collection.model';
918
import { ViewMode } from '../../../../core/shared/view-mode.model';
1019
import { ThemedBadgesComponent } from '../../../object-collection/shared/badges/themed-badges.component';
1120
import { CollectionSearchResult } from '../../../object-collection/shared/collection-search-result.model';
1221
import { listableObjectComponent } from '../../../object-collection/shared/listable-object/listable-object.decorator';
22+
import { TruncatableService } from '../../../truncatable/truncatable.service';
1323
import { SearchResultListElementComponent } from '../search-result-list-element.component';
1424

1525
@Component({
@@ -30,6 +40,13 @@ export class CollectionSearchResultListElementComponent extends SearchResultList
3040
*/
3141
showThumbnails: boolean;
3242

43+
constructor(protected truncatableService: TruncatableService,
44+
public dsoNameService: DSONameService,
45+
public translateService: TranslateService,
46+
@Inject(APP_CONFIG) protected appConfig?: AppConfig) {
47+
super(truncatableService, dsoNameService, appConfig);
48+
}
49+
3350
ngOnInit(): void {
3451
super.ngOnInit();
3552
this.showThumbnails = this.showThumbnails ?? this.appConfig.browseBy.showThumbnails;

0 commit comments

Comments
 (0)