Skip to content

Commit

Permalink
116466: fix tests and lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Buckingham committed Jul 29, 2024
1 parent 4b39e28 commit f12f7e7
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 145 deletions.
3 changes: 1 addition & 2 deletions src/app/shared/rss-feed/rss.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
*ngIf="(isEnabled$ | async) && (hasRoute('home') || hasRoute('exhibits') || hasRoute('workflow') || hasRoute('admin') || hasRoute('mydspace') || hasRoute('search') || hasRoute('collections') || hasRoute('communities'))">
<div *ngIf="route$ | async as route" class="d-inline-block float-right margin-right">
<a target="_blank" rel="noopener noreferrer" [href]="route" class="btn btn-secondary"
[title]="'feed.description' | translate" [attr.aria-label]="'feed.description' | translate"
(click)="copyLinkToClipboard(route)">
[title]="'feed.description' | translate" [attr.aria-label]="'feed.description' | translate">
<i class="fas fa-rss-square"></i>
</a>
</div>
Expand Down
210 changes: 86 additions & 124 deletions src/app/shared/rss-feed/rss.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
import {
ComponentFixture,
TestBed,
waitForAsync,
} from '@angular/core/testing';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { of as observableOf } from 'rxjs';

import {
SortDirection,
SortOptions,
} from '../../core/cache/models/sort-options.model';
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
import { RemoteData } from '../../core/data/remote-data';
import { GroupDataService } from '../../core/eperson/group-data.service';
Expand All @@ -9,175 +20,126 @@ import { Collection } from '../../core/shared/collection.model';
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
import { RouterMock } from '../mocks/router.mock';
import { getMockTranslateService } from '../mocks/translate.service.mock';
import { PaginationComponentOptions } from '../pagination/pagination-component-options.model';
import {
createSuccessfulRemoteDataObject,
createSuccessfulRemoteDataObject$,
} from '../remote-data.utils';
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
import { SearchFilter } from '../search/models/search-filter.model';
import { PaginationServiceStub } from '../testing/pagination-service.stub';
import { SearchConfigurationServiceStub } from '../testing/search-configuration-service.stub';
import { createPaginatedList } from '../testing/utils.test';
import { RSSComponent } from './rss.component';
import { of as observableOf } from 'rxjs';
import { SearchConfigurationServiceStub } from '../testing/search-configuration-service.stub';
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
import { Router } from '@angular/router';
import { RouterMock } from '../mocks/router.mock';
import { SearchFilter } from '../search/models/search-filter.model';
import { NotificationsService } from '../notifications/notifications.service';
import { NotificationsServiceStub } from '../testing/notifications-service.stub';
import { Clipboard } from '@angular/cdk/clipboard';
import { TranslateService } from '@ngx-translate/core';
import { getMockTranslateService } from '../mocks/translate.service.mock';

describe('RssComponent', () => {
let comp: RSSComponent;
let options: SortOptions;
let fixture: ComponentFixture<RSSComponent>;
let uuid: string;
let query: string;
let groupDataService: GroupDataService;
let linkHeadService: LinkHeadService;
let configurationDataService: ConfigurationDataService;
let paginationService;
let comp: RSSComponent;
let options: SortOptions;
let fixture: ComponentFixture<RSSComponent>;
let uuid: string;
let query: string;
let groupDataService: GroupDataService;
let linkHeadService: LinkHeadService;
let configurationDataService: ConfigurationDataService;
let paginationService;

beforeEach(waitForAsync(() => {
const mockCollection: Collection = Object.assign(new Collection(), {
id: 'ce41d451-97ed-4a9c-94a1-7de34f16a9f4',
name: 'test-collection',
_links: {
mappedItems: {
href: 'https://rest.api/collections/ce41d451-97ed-4a9c-94a1-7de34f16a9f4/mappedItems'
},
self: {
href: 'https://rest.api/collections/ce41d451-97ed-4a9c-94a1-7de34f16a9f4'
}
}
});
configurationDataService = jasmine.createSpyObj('configurationDataService', {
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
name: 'test',
values: [
'org.dspace.ctask.general.ProfileFormats = test'
]
}))
});
linkHeadService = jasmine.createSpyObj('linkHeadService', {
addTag: ''
});
const mockCollectionRD: RemoteData<Collection> = createSuccessfulRemoteDataObject(mockCollection);
const mockSearchOptions = observableOf(new PaginatedSearchOptions({
pagination: Object.assign(new PaginationComponentOptions(), {
id: 'search-page-configuration',
pageSize: 10,
currentPage: 1
}),
sort: new SortOptions('dc.title', SortDirection.ASC),
}));
groupDataService = jasmine.createSpyObj('groupsDataService', {
findListByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
getGroupRegistryRouterLink: '',
getUUIDFromString: '',
});
paginationService = new PaginationServiceStub();
const searchConfigService = {
paginatedSearchOptions: mockSearchOptions
};
TestBed.configureTestingModule({
providers: [
{ provide: GroupDataService, useValue: groupDataService },
{ provide: LinkHeadService, useValue: linkHeadService },
{ provide: ConfigurationDataService, useValue: configurationDataService },
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
{ provide: PaginationService, useValue: paginationService },
{ provide: Router, useValue: new RouterMock() },
{ provide: Clipboard, useValue: {} },
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: TranslateService, useValue: getMockTranslateService() },
],
declarations: [RSSComponent]
}).compileComponents();
}));

beforeEach(() => {
options = new SortOptions('dc.title', SortDirection.DESC);
uuid = '2cfcf65e-0a51-4bcb-8592-b8db7b064790';
query = 'test';
fixture = TestBed.createComponent(RSSComponent);
comp = fixture.componentInstance;
});

it('should formulate the correct url given params in url', () => {
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test');
});

it('should skip uuid if its null', () => {
const route = comp.formulateRoute(null, 'opensearch/search', options, query);
expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=test');
});

it('should default to query * if none provided', () => {
const route = comp.formulateRoute(null, 'opensearch/search', options, null);
expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=*');
beforeEach(waitForAsync(() => {
const mockCollection: Collection = Object.assign(new Collection(), {
id: 'ce41d451-97ed-4a9c-94a1-7de34f16a9f4',
name: 'test-collection',
_links: {
mappedItems: {
href: 'https://rest.api/collections/ce41d451-97ed-4a9c-94a1-7de34f16a9f4/mappedItems',
},
self: {
href: 'https://rest.api/collections/ce41d451-97ed-4a9c-94a1-7de34f16a9f4',
},
},
});

it('should include filters in opensearch url if provided', () => {
const filters = [
new SearchFilter('f.test', ['value','another value'], 'contains'), // should be split into two arguments, spaces should be URI-encoded
new SearchFilter('f.range', ['[1987 TO 1988]'], 'equals'), // value should be URI-encoded, ',equals' should not
];
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query, filters);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&f.test=value,contains&f.test=another%20value,contains&f.range=%5B1987%20TO%201988%5D,equals');
configurationDataService = jasmine.createSpyObj('configurationDataService', {
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
name: 'test',
values: [
'org.dspace.ctask.general.ProfileFormats = test',
],
})),
});

it('should include configuration in opensearch url if provided', () => {
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query, null, 'adminConfiguration');
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&configuration=adminConfiguration');
linkHeadService = jasmine.createSpyObj('linkHeadService', {
addTag: '',
});

it('should include rpp in opensearch url if provided', () => {
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query, null, null, 50);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&rpp=50');
const mockCollectionRD: RemoteData<Collection> = createSuccessfulRemoteDataObject(mockCollection);
const mockSearchOptions = observableOf(new PaginatedSearchOptions({
pagination: Object.assign(new PaginationComponentOptions(), {
id: 'search-page-configuration',
pageSize: 10,
currentPage: 1,
}),
sort: new SortOptions('dc.title', SortDirection.ASC),
}));
groupDataService = jasmine.createSpyObj('groupsDataService', {
findListByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])),
getGroupRegistryRouterLink: '',
getUUIDFromString: '',
});
paginationService = new PaginationServiceStub();
const searchConfigService = {
paginatedSearchOptions: mockSearchOptions,
};
TestBed.configureTestingModule({
imports: [RSSComponent],
providers: [
{ provide: GroupDataService, useValue: groupDataService },
{ provide: LinkHeadService, useValue: linkHeadService },
{ provide: ConfigurationDataService, useValue: configurationDataService },
{ provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() },
{ provide: PaginationService, useValue: paginationService },
{ provide: Router, useValue: new RouterMock() },
{ provide: TranslateService, useValue: getMockTranslateService() },
],
declarations: [],
}).compileComponents();
}));

beforeEach(() => {
options = new SortOptions('dc.title', SortDirection.DESC);
uuid = '2cfcf65e-0a51-4bcb-8592-b8db7b064790';
query = 'test';
fixture = TestBed.createComponent(RSSComponent);
comp = fixture.componentInstance;
});

it('should formulate the correct url given params in url', () => {
const route = comp.formulateRoute(uuid, 'opensearch/search', query);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&query=test');
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test');
});

it('should skip uuid if its null', () => {
const route = comp.formulateRoute(null, 'opensearch/search', query);
expect(route).toBe('/opensearch/search?format=atom&query=test');
const route = comp.formulateRoute(null, 'opensearch/search', options, query);
expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=test');
});

it('should default to query * if none provided', () => {
const route = comp.formulateRoute(null, 'opensearch/search', null);
expect(route).toBe('/opensearch/search?format=atom&query=*');
const route = comp.formulateRoute(null, 'opensearch/search', options, null);
expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=*');
});

it('should include filters in opensearch url if provided', () => {
const filters = [
new SearchFilter('f.test', ['value','another value'], 'contains'), // should be split into two arguments, spaces should be URI-encoded
new SearchFilter('f.range', ['[1987 TO 1988]'], 'equals'), // value should be URI-encoded, ',equals' should not
];
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query, filters);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&f.test=value,contains&f.test=another%20value,contains&f.range=%5B1987%20TO%201988%5D,equals');
});

it('should include configuration in opensearch url if provided', () => {
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query, null, 'adminConfiguration');
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&configuration=adminConfiguration');
});

it('should include rpp in opensearch url if provided', () => {
const route = comp.formulateRoute(uuid, 'opensearch/search', options, query, null, null, 50);
expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&rpp=50');
});
});

35 changes: 18 additions & 17 deletions src/app/shared/rss-feed/rss.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ import {
OnInit,
ViewEncapsulation,
} from '@angular/core';
import { BehaviorSubject, Subscription } from 'rxjs';
import { Router } from '@angular/router';
import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import {
BehaviorSubject,
Subscription,
} from 'rxjs';
import {
map,
switchMap,
} from 'rxjs/operators';

import { environment } from '../../../environments/environment';
import { SortOptions } from '../../core/cache/models/sort-options.model';
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
import { RemoteData } from '../../core/data/remote-data';
import { GroupDataService } from '../../core/eperson/group-data.service';
import { PaginationService } from '../../core/pagination/pagination.service';
import { LinkHeadService } from '../../core/services/link-head.service';
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
import { SortOptions } from '../../core/cache/models/sort-options.model';
import { Router } from '@angular/router';
import { map, switchMap } from 'rxjs/operators';
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
import { RemoteData } from '../../core/data/remote-data';
import { SearchFilter } from '../search/models/search-filter.model';
import { Clipboard } from '@angular/cdk/clipboard';
import { NotificationsService } from '../notifications/notifications.service';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
import { environment } from '../../../environments/environment';
/**
* The Rss feed button component.
*/
Expand Down Expand Up @@ -55,8 +63,6 @@ export class RSSComponent implements OnInit, OnDestroy {
private searchConfigurationService: SearchConfigurationService,
private router: Router,
protected paginationService: PaginationService,
protected clipboard: Clipboard,
protected notificationService: NotificationsService,
protected translateService: TranslateService) {
}
/**
Expand Down Expand Up @@ -184,9 +190,4 @@ export class RSSComponent implements OnInit, OnDestroy {
});
}

copyLinkToClipboard(linkToCopy: string) {
this.clipboard.copy(linkToCopy);
this.notificationService.success(this.translateService.get('rss.button.notification'));
}

}
2 changes: 0 additions & 2 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6739,7 +6739,5 @@
"item.page.cc.license.disclaimer": "Except where otherwised noted, this item's license is described as",

"browse.search-form.placeholder": "Search the repository",

"rss.button.notification": "RSS link for this search has been copied to clipboard",

}

0 comments on commit f12f7e7

Please sign in to comment.