Skip to content

Commit

Permalink
Merged in 2023_02_x_DSC-1437 (pull request DSpace#1492)
Browse files Browse the repository at this point in the history
[DSC-1437]

Approved-by: Giuseppe Digilio
  • Loading branch information
vins01-4science authored and atarix83 committed Mar 29, 2024
2 parents 234b490 + ffffb6f commit 6320a3d
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 103 deletions.
15 changes: 15 additions & 0 deletions src/app/lucky-search/search/lucky-search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ <h5 class="text-center">{{'lucky.search.results.notfound' | translate}} {{curren
</div>
</div>
</div>

<div class="w-100" *ngIf="(bitstreamFilters$ | async)?.length">
<div *ngFor="let attachment of (bitstreams$ | async)" class="mb-3 mx-auto" [style.width]="'33%'">
<ds-truncatable [id]="attachment.id">
<ds-file-download-link [bitstream]="attachment" [enableRequestACopy]="true" [item]="(item$ | async)" [showIcon]="true">
<span data-test="title" *ngIf="fileName(attachment)">
{{fileName(attachment)}} ({{getSize(attachment) | dsFileSize}})
</span>
</ds-file-download-link>
<ds-truncatable-part [id]="attachment.id" [minLines]="1">
<span *ngIf="getDescription(attachment)" data-test="description">{{getDescription(attachment)}}</span>
</ds-truncatable-part>
</ds-truncatable>
</div>
</div>
188 changes: 134 additions & 54 deletions src/app/lucky-search/search/lucky-search.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import { TranslateModule } from '@ngx-translate/core';
import { By } from '@angular/platform-browser';
import { SearchResult } from '../../shared/search/models/search-result.model';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { BitstreamDataService, MetadataFilter } from '../../core/data/bitstream-data.service';
import { Bitstream } from '../../core/shared/bitstream.model';
import { RouterMock } from '../../shared/mocks/router.mock';
import { MetadataMap, MetadataValue } from '../../core/shared/metadata.models';
import { FileSizePipe } from '../../shared/utils/file-size-pipe';

describe('SearchComponent', () => {
let fixture: ComponentFixture<LuckySearchComponent>;
Expand All @@ -39,6 +44,9 @@ describe('SearchComponent', () => {
}
]))
});
const bitstreamDataService = jasmine.createSpyObj('bitstreamDataService', {
findByItem: jasmine.createSpy('findByItem')
});
const mockSearchOptions = observableOf(new PaginatedSearchOptions({
pagination: Object.assign(new PaginationComponentOptions(), {
id: 'search-page-configuration',
Expand All @@ -52,27 +60,21 @@ describe('SearchComponent', () => {
};
let component: LuckySearchComponent;

const itemPageUrl = '/lucky-search?index=xxx&value=yyyy';
const urlTree = new UrlTree();
urlTree.queryParams = {
index: 'test',
'value': 'test'
};
const routerStub = jasmine.createSpyObj('router', {
parseUrl: urlTree,
createUrlTree: new UrlTree(),
url: itemPageUrl,
navigateByUrl: void {}
});
const routerStub = new RouterMock();
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [LuckySearchComponent],
declarations: [LuckySearchComponent, FileSizePipe],
imports: [TranslateModule.forRoot()],
providers: [
{provide: Router, useValue: routerStub},
{provide: SearchConfigurationService, useValue: searchConfigServiceStub},
{provide: LuckySearchService, useValue: searchServiceStub},

{provide: BitstreamDataService, useValue: bitstreamDataService}
],
})
.compileComponents();
Expand All @@ -84,61 +86,139 @@ describe('SearchComponent', () => {
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
describe('should search items', () => {

it('should show multiple results', () => {
expect(component.showMultipleSearchSection).toEqual(true);
});
beforeEach(() => {
spyOn(routerStub, 'parseUrl').and.returnValue(urlTree);
});

it('should display basic search form results', () => {
expect(fixture.debugElement.query(By.css('ds-search-results')))
.toBeTruthy();
});
it('should create', () => {
expect(component).toBeTruthy();
});

beforeEach(() => {
fixture = TestBed.createComponent(LuckySearchComponent);
component = fixture.componentInstance;
const firstSearchResult = Object.assign(new SearchResult(), {
indexableObject: Object.assign(new DSpaceObject(), {
id: 'd317835d-7b06-4219-91e2-1191900cb897',
uuid: 'd317835d-7b06-4219-91e2-1191900cb897',
name: 'My first publication',
metadata: {
'dspace.entity.type': [
{value: 'Publication'}
]
}
})
it('should show multiple results', () => {
expect(component.showMultipleSearchSection).toEqual(true);
});

const data = createSuccessfulRemoteDataObject(createPaginatedList([
firstSearchResult
]));
component.resultsRD$.next(data as any);
fixture.detectChanges();
});
it('should display basic search form results', () => {
expect(fixture.debugElement.query(By.css('ds-search-results')))
.toBeTruthy();
});

it('should call navigate or router', () => {
expect(routerStub.navigateByUrl).toHaveBeenCalled();
});
beforeEach(() => {
fixture = TestBed.createComponent(LuckySearchComponent);
component = fixture.componentInstance;
const firstSearchResult = Object.assign(new SearchResult(), {
indexableObject: Object.assign(new DSpaceObject(), {
id: 'd317835d-7b06-4219-91e2-1191900cb897',
uuid: 'd317835d-7b06-4219-91e2-1191900cb897',
name: 'My first publication',
metadata: {
'dspace.entity.type': [
{value: 'Publication'}
]
}
})
});

const data = createSuccessfulRemoteDataObject(createPaginatedList([
firstSearchResult
]));
component.resultsRD$.next(data as any);
fixture.detectChanges();
});

it('should call navigate or router', () => {
expect(routerStub.navigateByUrl).toHaveBeenCalled();
});

beforeEach(() => {
fixture = TestBed.createComponent(LuckySearchComponent);
component = fixture.componentInstance;
const data = createSuccessfulRemoteDataObject(createPaginatedList([]));
component.resultsRD$.next(data as any);
fixture.detectChanges();
});
beforeEach(() => {
fixture = TestBed.createComponent(LuckySearchComponent);
component = fixture.componentInstance;
const data = createSuccessfulRemoteDataObject(createPaginatedList([]));
component.resultsRD$.next(data as any);
fixture.detectChanges();
});

it('should not have results', () => {
expect(component.showEmptySearchSection).toEqual(true);
it('should not have results', () => {
expect(component.showEmptySearchSection).toEqual(true);
});

it('should display basic search form', () => {
expect(fixture.debugElement.query(By.css('ds-search-form')))
.toBeTruthy();
});
});

it('should display basic search form', () => {
expect(fixture.debugElement.query(By.css('ds-search-form')))
.toBeTruthy();
describe('should search bitstreams', () => {

const bitstreamMetadata = {
'dc.title': [{ value: 'test.pdf' } as MetadataValue],
'dc.description': [{ value: 'TestDescription' } as MetadataValue]
} as MetadataMap;
const bitstream = Object.assign(
new Bitstream(),
{ _name: 'test.pdf', sizeBytes: 15, uuid: 'fa272dbf-e458-4ad2-868b-b4a27c6eac15', metadata: bitstreamMetadata }
) as Bitstream;

beforeEach(() => {
fixture = TestBed.createComponent(LuckySearchComponent);
component = fixture.componentInstance;

const bitstreamSearchTree = new UrlTree();
bitstreamSearchTree.queryParams = {
index: 'testIndex',
value: 'testValue',
bitstreamMetadata: 'testMetadata',
bitstreamValue: 'testMetadataValue'
};

const itemUUID = 'd317835d-7b06-4219-91e2-1191900cb897';
const firstSearchResult = Object.assign(new SearchResult(), {
indexableObject: Object.assign(new DSpaceObject(), {
id: 'd317835d-7b06-4219-91e2-1191900cb897',
uuid: itemUUID,
name: 'My first publication',
metadata: {
'dspace.entity.type': [
{ value: 'Publication' }
]
}
})
});
const data = createSuccessfulRemoteDataObject(createPaginatedList([firstSearchResult]));
const metadataFilters = [{ metadataName: 'dc.title', metadataValue: 'test.pdf' }] as MetadataFilter[];
component.bitstreamFilters$.next(metadataFilters);
bitstreamDataService.findByItem.withArgs(itemUUID, 'ORIGINAL', metadataFilters, {})
.and.returnValue(createSuccessfulRemoteDataObject$(createPaginatedList([bitstream])));

spyOn(component, 'redirect');
spyOn(component.bitstreams$, 'next').and.callThrough();
spyOn(routerStub, 'parseUrl').and.returnValue(bitstreamSearchTree);

component.resultsRD$.next(data as any);

fixture.detectChanges();
});

it('should load item bitstreams', () => {
expect(component.bitstreams$.next).toHaveBeenCalledWith([bitstream]);
});

it('should redirect to bitstream', () => {
expect(component.redirect).toHaveBeenCalledWith(`/bitstreams/${bitstream.uuid}/download`);
});

it('should return bitstream filename', () => {
expect(component.fileName(bitstream)).toEqual('test.pdf');
});

it('should return bitstream description', () => {
expect(component.getDescription(bitstream)).toEqual('TestDescription');
});

it('should return bitstream file size', () => {
expect(component.getSize(bitstream)).toEqual(15);
});
});
});
Loading

0 comments on commit 6320a3d

Please sign in to comment.