Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { APP_CONFIG } from '@dspace/config/app-config.interface';
import { BitstreamDataService } from '@dspace/core/data/bitstream-data.service';
import { LocaleService } from '@dspace/core/locale/locale.service';
import { NotificationsService } from '@dspace/core/notification-system/notifications.service';
import { PaginationService } from '@dspace/core/pagination/pagination.service';
import { Bitstream } from '@dspace/core/shared/bitstream.model';
Expand Down Expand Up @@ -37,6 +38,12 @@ import { FullFileSectionComponent } from './full-file-section.component';
describe('FullFileSectionComponent', () => {
let comp: FullFileSectionComponent;
let fixture: ComponentFixture<FullFileSectionComponent>;
let localeService: any;
const languageList = ['en;q=1', 'de;q=0.8'];
const mockLocaleService = jasmine.createSpyObj('LocaleService', {
getCurrentLanguageCode: jasmine.createSpy('getCurrentLanguageCode'),
getLanguageCodeList: of(languageList),
});

const mockBitstream: Bitstream = Object.assign(new Bitstream(),
{
Expand Down Expand Up @@ -93,6 +100,7 @@ describe('FullFileSectionComponent', () => {
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: SearchConfigurationService, useValue: jasmine.createSpyObj(['getCurrentConfiguration']) },
{ provide: PaginationService, useValue: paginationService },
{ provide: LocaleService, useValue: mockLocaleService },
{ provide: APP_CONFIG, useValue: environment },
],
schemas: [NO_ERRORS_SCHEMA],
Expand All @@ -104,6 +112,8 @@ describe('FullFileSectionComponent', () => {
}));

beforeEach(waitForAsync(() => {
localeService = TestBed.inject(LocaleService);
localeService.getCurrentLanguageCode.and.returnValue(of('en'));
fixture = TestBed.createComponent(FullFileSectionComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ActivatedRoute } from '@angular/router';
import { APP_CONFIG } from '@dspace/config/app-config.interface';
import { BitstreamDataService } from '@dspace/core/data/bitstream-data.service';
import { APP_DATA_SERVICES_MAP } from '@dspace/core/data-services-map-type';
import { LocaleService } from '@dspace/core/locale/locale.service';
import { NotificationsService } from '@dspace/core/notification-system/notifications.service';
import { Bitstream } from '@dspace/core/shared/bitstream.model';
import { PageInfo } from '@dspace/core/shared/page-info.model';
Expand Down Expand Up @@ -38,6 +39,12 @@ import { FileSectionComponent } from './file-section.component';
describe('FileSectionComponent', () => {
let comp: FileSectionComponent;
let fixture: ComponentFixture<FileSectionComponent>;
let localeService: any;
const languageList = ['en;q=1', 'de;q=0.8'];
const mockLocaleService = jasmine.createSpyObj('LocaleService', {
getCurrentLanguageCode: jasmine.createSpy('getCurrentLanguageCode'),
getLanguageCodeList: of(languageList),
});

const bitstreamDataService = jasmine.createSpyObj('bitstreamDataService', {
findAllByItemAndBundleName: createSuccessfulRemoteDataObject$(createPaginatedList([])),
Expand Down Expand Up @@ -88,6 +95,7 @@ describe('FileSectionComponent', () => {
{ provide: APP_CONFIG, useValue: environment },
{ provide: ThemeService, useValue: getMockThemeService() },
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
{ provide: LocaleService, useValue: mockLocaleService },
provideMockStore(),
],
schemas: [NO_ERRORS_SCHEMA],
Expand All @@ -103,6 +111,8 @@ describe('FileSectionComponent', () => {
}));

beforeEach(waitForAsync(() => {
localeService = TestBed.inject(LocaleService);
localeService.getCurrentLanguageCode.and.returnValue(of('en'));
fixture = TestBed.createComponent(FileSectionComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
Expand Down
11 changes: 11 additions & 0 deletions src/app/process-page/detail/process-detail.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DSONameService } from '@dspace/core/breadcrumbs/dso-name.service';
import { BitstreamDataService } from '@dspace/core/data/bitstream-data.service';
import { PaginatedList } from '@dspace/core/data/paginated-list.model';
import { ProcessDataService } from '@dspace/core/data/processes/process-data.service';
import { LocaleService } from '@dspace/core/locale/locale.service';
import { NotificationsService } from '@dspace/core/notification-system/notifications.service';
import { Process } from '@dspace/core/processes/process.model';
import { Bitstream } from '@dspace/core/shared/bitstream.model';
Expand Down Expand Up @@ -60,6 +61,12 @@ describe('ProcessDetailComponent', () => {
let router: RouterStub;
let modalService;
let notificationsService: NotificationsServiceStub;
let localeService: any;
const languageList = ['en;q=1', 'de;q=0.8'];
const mockLocaleService = jasmine.createSpyObj('LocaleService', {
getCurrentLanguageCode: jasmine.createSpy('getCurrentLanguageCode'),
getLanguageCodeList: of(languageList),
});

let process: Process;
let fileName: string;
Expand Down Expand Up @@ -169,6 +176,7 @@ describe('ProcessDetailComponent', () => {
{ provide: NgbModal, useValue: modalService },
{ provide: NotificationsService, useValue: notificationsService },
{ provide: Router, useValue: router },
{ provide: LocaleService, useValue: mockLocaleService },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
Expand All @@ -186,7 +194,10 @@ describe('ProcessDetailComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(ProcessDetailComponent);
component = fixture.componentInstance;
localeService = TestBed.inject(LocaleService);
localeService.getCurrentLanguageCode.and.returnValue(of('en'));
});

afterEach(fakeAsync(() => {
TestBed.resetTestingModule();
fixture.destroy();
Expand Down
17 changes: 16 additions & 1 deletion src/app/shared/utils/file-size-pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import {
Pipe,
PipeTransform,
} from '@angular/core';
import { LocaleService } from '@dspace/core/locale/locale.service';
import { filesize } from 'filesize';
import { take } from 'rxjs/operators';

/*
* Convert bytes into largest possible unit.
Expand All @@ -18,7 +20,20 @@ import { filesize } from 'filesize';
name: 'dsFileSize',
})
export class FileSizePipe implements PipeTransform {

private currentLocale: string;

constructor(private localeService: LocaleService) {
this.localeService.getCurrentLanguageCode().pipe(take(1)).subscribe(locale => {
this.currentLocale = locale;
});
}

transform(bytes: number = 0, precision: number = 2): string {
return filesize(bytes, { standard: 'jedec', round: precision });
return filesize(bytes, {
standard: 'jedec',
round: precision,
locale: this.currentLocale,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {
TestBed,
waitForAsync,
} from '@angular/core/testing';
import { LocaleService } from '@dspace/core/locale/locale.service';
import { Metadata } from '@dspace/core/shared/metadata.utils';
import { createTestComponent } from '@dspace/core/testing/utils.test';
import { TranslateModule } from '@ngx-translate/core';
import { of } from 'rxjs';

import { FormComponent } from '../../../../../shared/form/form.component';
import { TruncatePipe } from '../../../../../shared/utils/truncate.pipe';
Expand All @@ -24,6 +26,12 @@ describe('SubmissionSectionUploadFileViewComponent test suite', () => {
let comp: SubmissionSectionUploadFileViewComponent;
let compAsAny: any;
let fixture: ComponentFixture<SubmissionSectionUploadFileViewComponent>;
let localeService: any;
const languageList = ['en;q=1', 'de;q=0.8'];
const mockLocaleService = jasmine.createSpyObj('LocaleService', {
getCurrentLanguageCode: jasmine.createSpy('getCurrentLanguageCode'),
getLanguageCodeList: of(languageList),
});

const fileData: any = mockUploadFiles[0];

Expand All @@ -38,6 +46,7 @@ describe('SubmissionSectionUploadFileViewComponent test suite', () => {
],
providers: [
SubmissionSectionUploadFileViewComponent,
{ provide: LocaleService, useValue: mockLocaleService },
],
schemas: [NO_ERRORS_SCHEMA],
})
Expand All @@ -56,14 +65,15 @@ describe('SubmissionSectionUploadFileViewComponent test suite', () => {
let testComp: TestComponent;
let testFixture: ComponentFixture<TestComponent>;

// synchronous beforeEach
beforeEach(() => {
beforeEach(waitForAsync(async () => {
const html = `
<ds-submission-section-upload-file-view [fileData]="fileData"></ds-submission-section-upload-file-view>`;

testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
localeService = TestBed.inject(LocaleService);
localeService.getCurrentLanguageCode.and.returnValue(of('en'));
testComp = testFixture.componentInstance;
});
}));

afterEach(() => {
testFixture.destroy();
Expand All @@ -77,11 +87,13 @@ describe('SubmissionSectionUploadFileViewComponent test suite', () => {
});

describe('', () => {
beforeEach(() => {
beforeEach(waitForAsync(async () => {
localeService = TestBed.inject(LocaleService);
localeService.getCurrentLanguageCode.and.returnValue(of('en'));
fixture = TestBed.createComponent(SubmissionSectionUploadFileViewComponent);
comp = fixture.componentInstance;
compAsAny = comp;
});
}));

afterEach(() => {
fixture.destroy();
Expand Down
Loading