Skip to content

Commit 42b0efb

Browse files
committed
Updated spec tests.
1 parent 076bcac commit 42b0efb

4 files changed

Lines changed: 150 additions & 18 deletions

File tree

src/app/item-page/simple/field-components/extended-file-section/extended-file-section.component.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import '../../../../../styles/variables.scss';
2+
13
.file-section {
24
padding: 1rem;
35
background-color: var(--bs-gray-200);
Lines changed: 138 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,154 @@
1-
import { ComponentFixture, TestBed } from '@angular/core/testing';
1+
import { NO_ERRORS_SCHEMA } from '@angular/core';
2+
import {
3+
ComponentFixture,
4+
TestBed,
5+
waitForAsync,
6+
} from '@angular/core/testing';
7+
import { By } from '@angular/platform-browser';
8+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
9+
import { ActivatedRoute } from '@angular/router';
10+
import { APP_CONFIG } from '@dspace/config/app-config.interface';
11+
import { BitstreamDataService } from '@dspace/core/data/bitstream-data.service';
12+
import { BitstreamFormatDataService } from '@dspace/core/data/bitstream-format-data.service';
13+
import { LocaleService } from '@dspace/core/locale/locale.service';
14+
import { NotificationsService } from '@dspace/core/notification-system/notifications.service';
15+
import { PaginationService } from '@dspace/core/pagination/pagination.service';
16+
import { Bitstream } from '@dspace/core/shared/bitstream.model';
17+
import { BitstreamFormat } from '@dspace/core/shared/bitstream-format.model';
18+
import { Item } from '@dspace/core/shared/item.model';
19+
import { ActivatedRouteStub } from '@dspace/core/testing/active-router.stub';
20+
import { NotificationsServiceStub } from '@dspace/core/testing/notifications-service.stub';
21+
import { PaginationServiceStub } from '@dspace/core/testing/pagination-service.stub';
22+
import { TranslateLoaderMock } from '@dspace/core/testing/translate-loader.mock';
23+
import { createPaginatedList } from '@dspace/core/testing/utils.test';
24+
import { createSuccessfulRemoteDataObject$ } from '@dspace/core/utilities/remote-data.utils';
25+
import { XSRFService } from '@dspace/core/xsrf/xsrf.service';
26+
import { provideMockStore } from '@ngrx/store/testing';
27+
import {
28+
TranslateLoader,
29+
TranslateModule,
30+
} from '@ngx-translate/core';
31+
import { of } from 'rxjs';
232

33+
import { environment } from '../../../../../environments/environment';
34+
import { ThemedFileDownloadLinkComponent } from '../../../../shared/file-download-link/themed-file-download-link.component';
35+
import { PaginationComponent } from '../../../../shared/pagination/pagination.component';
36+
import { SearchConfigurationService } from '../../../../shared/search/search-configuration.service';
37+
import { getMockThemeService } from '../../../../shared/theme-support/test/theme-service.mock';
38+
import { ThemeService } from '../../../../shared/theme-support/theme.service';
39+
import { FileSizePipe } from '../../../../shared/utils/file-size-pipe';
40+
import { VarDirective } from '../../../../shared/utils/var.directive';
341
import { ExtendedFileSectionComponent } from './extended-file-section.component';
442

543
describe('ExtendedFileSectionComponent', () => {
644
let component: ExtendedFileSectionComponent;
745
let fixture: ComponentFixture<ExtendedFileSectionComponent>;
46+
let localeService: any;
47+
const languageList = ['en;q=1', 'de;q=0.8'];
48+
const mockLocaleService = jasmine.createSpyObj('LocaleService', {
49+
getCurrentLanguageCode: jasmine.createSpy('getCurrentLanguageCode'),
50+
getLanguageCodeList: of(languageList),
51+
});
52+
53+
const paginationServiceStub = new PaginationServiceStub();
54+
55+
const mockItem = Object.assign(new Item(), {
56+
id: 'test-item-id',
57+
uuid: 'test-item-id',
58+
_links: {
59+
self: { href: 'test-item-selflink' },
60+
},
61+
});
62+
63+
const mockBitstream = Object.assign(new Bitstream(), {
64+
id: 'test-bitstream-id',
65+
uuid: 'test-bitstream-id',
66+
name: 'test-bitstream.pdf',
67+
sizeBytes: 1024,
68+
_links: {
69+
self: { href: 'test-bitstream-selflink' },
70+
},
71+
});
72+
73+
const mockBitstreamFormat = Object.assign(new BitstreamFormat(), {
74+
resourceType: 'testResourceType',
75+
shortDescription: 'testShortDescription',
76+
description: 'testDescription',
77+
mimetype: 'test/mimeType',
78+
});
79+
80+
const paginatedList = createPaginatedList([mockBitstream]);
81+
82+
paginatedList.pageInfo.elementsPerPage = environment.item.bitstream.pageSize;
883

9-
beforeEach(async () => {
10-
await TestBed.configureTestingModule({
11-
imports: [ExtendedFileSectionComponent]
12-
})
13-
.compileComponents();
84+
const bitstreamDataService = jasmine.createSpyObj('bitstreamDataService', {
85+
findAllByItemAndBundleName: createSuccessfulRemoteDataObject$(paginatedList),
86+
});
87+
88+
const bitstreamFormatDataService = jasmine.createSpyObj('bitstreamFormatDataService', {
89+
findByBitstream: createSuccessfulRemoteDataObject$(mockBitstreamFormat),
90+
});
91+
92+
beforeEach(waitForAsync(() => {
93+
94+
TestBed.configureTestingModule({
95+
imports: [
96+
TranslateModule.forRoot({
97+
loader: {
98+
provide: TranslateLoader,
99+
useClass: TranslateLoaderMock,
100+
},
101+
}),
102+
BrowserAnimationsModule,
103+
ExtendedFileSectionComponent,
104+
VarDirective,
105+
FileSizePipe,
106+
],
107+
providers: [
108+
provideMockStore(),
109+
{ provide: XSRFService, useValue: {} },
110+
{ provide: BitstreamDataService, useValue: bitstreamDataService },
111+
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
112+
{ provide: BitstreamFormatDataService, useValue: bitstreamFormatDataService },
113+
{ provide: ThemeService, useValue: getMockThemeService() },
114+
{ provide: SearchConfigurationService, useValue: jasmine.createSpyObj(['getCurrentConfiguration']) },
115+
{ provide: PaginationService, useValue: paginationServiceStub },
116+
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
117+
{ provide: LocaleService, useValue: mockLocaleService },
118+
{ provide: APP_CONFIG, useValue: environment },
119+
],
120+
schemas: [NO_ERRORS_SCHEMA],
121+
}).overrideComponent(ExtendedFileSectionComponent, {
122+
remove: {
123+
imports: [
124+
PaginationComponent,
125+
ThemedFileDownloadLinkComponent,
126+
],
127+
},
128+
}).compileComponents();
129+
}));
14130

131+
beforeEach(waitForAsync(() => {
132+
localeService = TestBed.inject(LocaleService);
133+
localeService.getCurrentLanguageCode.and.returnValue(of('en'));
15134
fixture = TestBed.createComponent(ExtendedFileSectionComponent);
16135
component = fixture.componentInstance;
136+
component.item = mockItem;
17137
fixture.detectChanges();
18-
});
138+
}));
19139

20140
it('should create', () => {
21141
expect(component).toBeTruthy();
22142
});
143+
144+
it('should set pageSize from appConfig', () => {
145+
expect(component.pageSize).toEqual(environment.item.bitstream.pageSize);
146+
});
147+
148+
describe('when the extended file section gets loaded with bitstreams available', () => {
149+
it('should contain a list with bitstream', () => {
150+
const fileSection = fixture.debugElement.queryAll(By.css('.file-section-entry'));
151+
expect(fileSection.length).toEqual(1);
152+
});
153+
});
23154
});

src/app/item-page/simple/field-components/extended-file-section/extended-file-section.component.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { PaginationComponentOptions } from '@dspace/core/pagination/pagination-c
1919
import { Bitstream } from '@dspace/core/shared/bitstream.model';
2020
import { followLink } from '@dspace/core/shared/follow-link-config.model';
2121
import { Item } from '@dspace/core/shared/item.model';
22-
import { TranslatePipe } from '@ngx-translate/core';
22+
import { TranslateModule } from '@ngx-translate/core';
2323
import {
2424
from,
2525
Observable,
@@ -38,7 +38,7 @@ import { VarDirective } from '../../../../shared/utils/var.directive';
3838
FileSizePipe,
3939
PaginationComponent,
4040
ThemedFileDownloadLinkComponent,
41-
TranslatePipe,
41+
TranslateModule,
4242
VarDirective,
4343
],
4444
templateUrl: './extended-file-section.component.html',
@@ -52,18 +52,18 @@ export class ExtendedFileSectionComponent implements OnInit {
5252

5353
@Input() label = 'item.page.extended-file-section';
5454

55-
pageSize = 10;
56-
5755
bitstreamsRD$: Observable<RemoteData<PaginatedList<Bitstream>>>;
5856

57+
pageSize = this.appConfig.item.bitstream.pageSize;
58+
5959

6060
/**
6161
* The current pagination configuration for the page
6262
*/
6363
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
64-
id: 'afs',
65-
pageSize: this.pageSize,
66-
pageSizeOptions: [10, 20, 40, 60, 80, 100],
64+
id: 'efs',
65+
currentPage: 1,
66+
pageSize: this.appConfig.item.bitstream.pageSize,
6767
});
6868

6969

@@ -74,7 +74,6 @@ export class ExtendedFileSectionComponent implements OnInit {
7474
@Inject(APP_CONFIG) protected appConfig: AppConfig,
7575
private paginationService: PaginationService,
7676
) {
77-
this.pageSize = appConfig.item.bitstream.pageSize;
7877
this.bitstreamsRD$ = from([]);
7978
}
8079

src/app/item-page/simple/item-types/dataset/dataset.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ import { ThemedThumbnailComponent } from '../../../../thumbnail/themed-thumbnail
6060
import { CollectionsComponent } from '../../../field-components/collections/collections.component';
6161
import { ThemedMediaViewerComponent } from '../../../media-viewer/themed-media-viewer.component';
6262
import { MiradorViewerComponent } from '../../../mirador-viewer/mirador-viewer.component';
63-
import { ThemedFileSectionComponent } from '../../field-components/file-section/themed-file-section.component';
63+
import { ExtendedFileSectionComponent } from '../../field-components/extended-file-section/extended-file-section.component';
6464
import { ItemPageAbstractFieldComponent } from '../../field-components/specific-field/abstract/item-page-abstract-field.component';
6565
import { ItemPageDateFieldComponent } from '../../field-components/specific-field/date/item-page-date-field.component';
6666
import { GenericItemPageFieldComponent } from '../../field-components/specific-field/generic/generic-item-page-field.component';
67+
import { GeospatialItemPageFieldComponent } from '../../field-components/specific-field/geospatial/geospatial-item-page-field.component';
6768
import { ThemedItemPageTitleFieldComponent } from '../../field-components/specific-field/title/themed-item-page-field.component';
6869
import { ItemPageUriFieldComponent } from '../../field-components/specific-field/uri/item-page-uri-field.component';
6970
import { ThemedMetadataRepresentationListComponent } from '../../metadata-representation-list/themed-metadata-representation-list.component';
@@ -136,8 +137,7 @@ describe('DatasetComponent', () => {
136137
}).overrideComponent(DatasetComponent, {
137138
add: { changeDetection: ChangeDetectionStrategy.Default },
138139
remove: {
139-
imports: [ThemedResultsBackButtonComponent, MiradorViewerComponent, ThemedItemPageTitleFieldComponent, DsoEditMenuComponent, MetadataFieldWrapperComponent, ThemedThumbnailComponent, ThemedMediaViewerComponent, ThemedFileSectionComponent, ItemPageDateFieldComponent, ThemedMetadataRepresentationListComponent, GenericItemPageFieldComponent, RelatedItemsComponent, ItemPageAbstractFieldComponent, ItemPageUriFieldComponent, CollectionsComponent,
140-
],
140+
imports: [ThemedResultsBackButtonComponent, MiradorViewerComponent, ThemedItemPageTitleFieldComponent, DsoEditMenuComponent, MetadataFieldWrapperComponent, ThemedThumbnailComponent, ThemedMediaViewerComponent, ExtendedFileSectionComponent, ItemPageDateFieldComponent, ThemedMetadataRepresentationListComponent, GenericItemPageFieldComponent, RelatedItemsComponent, ItemPageAbstractFieldComponent, ItemPageUriFieldComponent, CollectionsComponent, GeospatialItemPageFieldComponent],
141141
},
142142
});
143143
}));

0 commit comments

Comments
 (0)