-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'CST-5249_suggestion' of github.com:4Science/dspace-angu…
…lar into CST-5249_suggestion
- Loading branch information
Showing
5 changed files
with
398 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ons/reciter-suggestions/suggestion-list-element/suggestion-list-element.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { SuggestionListElementComponent } from './suggestion-list-element.component'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { TestScheduler } from 'rxjs/testing'; | ||
import { getTestScheduler } from 'jasmine-marbles'; | ||
import { mockSuggestionPublicationOne } from '../../../shared/mocks/reciter-suggestion.mock'; | ||
import { Item } from '../../../core/shared/item.model'; | ||
|
||
|
||
describe('SuggestionListElementComponent', () => { | ||
let component: SuggestionListElementComponent; | ||
let fixture: ComponentFixture<SuggestionListElementComponent>; | ||
let scheduler: TestScheduler; | ||
|
||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
TranslateModule.forRoot() | ||
], | ||
declarations: [SuggestionListElementComponent], | ||
providers: [ | ||
NgbModal | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).compileComponents().then(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SuggestionListElementComponent); | ||
component = fixture.componentInstance; | ||
scheduler = getTestScheduler(); | ||
|
||
component.object = mockSuggestionPublicationOne; | ||
}); | ||
|
||
describe('SuggestionListElementComponent test', () => { | ||
|
||
it('should create', () => { | ||
scheduler.schedule(() => fixture.detectChanges()); | ||
scheduler.flush(); | ||
const expectedIndexableObject = Object.assign(new Item(), { | ||
id: mockSuggestionPublicationOne.id, | ||
metadata: mockSuggestionPublicationOne.metadata | ||
}); | ||
expect(component).toBeTruthy(); | ||
expect(component.listableObject.hitHighlights).toEqual({}); | ||
expect(component.listableObject.indexableObject).toEqual(expectedIndexableObject); | ||
}); | ||
|
||
it('should check if has evidence', () => { | ||
expect(component.hasEvidences()).toBeTruthy(); | ||
}); | ||
|
||
it('should set seeEvidences', () => { | ||
component.onSeeEvidences(true); | ||
expect(component.seeEvidence).toBeTruthy(); | ||
}); | ||
|
||
it('should emit selection', () => { | ||
spyOn(component.selected, 'next'); | ||
component.changeSelected({target: { checked: true}}); | ||
expect(component.selected.next).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
it('should emit for deletion', () => { | ||
spyOn(component.notMineClicked, 'emit'); | ||
component.onNotMine('1234'); | ||
expect(component.notMineClicked.emit).toHaveBeenCalledWith('1234'); | ||
}); | ||
|
||
it('should emit for approve and import', () => { | ||
const event = {collectionId:'1234', suggestion: mockSuggestionPublicationOne}; | ||
spyOn(component.approveAndImport, 'emit'); | ||
component.onApproveAndImport(event); | ||
expect(component.approveAndImport.emit).toHaveBeenCalledWith(event); | ||
}); | ||
}); | ||
}); |
194 changes: 194 additions & 0 deletions
194
src/app/suggestion-notifications/reciter-suggestions/suggestion.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
import { SuggestionsService } from './suggestions.service'; | ||
import { AuthService } from '../../core/auth/auth.service'; | ||
import { ResearcherProfileDataService } from '../../core/profile/researcher-profile-data.service'; | ||
import { | ||
SuggestionsDataService | ||
} from '../../core/suggestion-notifications/reciter-suggestions/suggestions-data.service'; | ||
import { | ||
SuggestionSourceDataService | ||
} from '../../core/suggestion-notifications/reciter-suggestions/source/suggestion-source-data.service'; | ||
import { | ||
SuggestionTargetDataService | ||
} from '../../core/suggestion-notifications/reciter-suggestions/target/suggestion-target-data.service'; | ||
import { TestScheduler } from 'rxjs/testing'; | ||
import { getTestScheduler } from 'jasmine-marbles'; | ||
import { of as observableOf } from 'rxjs'; | ||
import { FindListOptions } from '../../core/data/find-list-options.model'; | ||
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; | ||
import { ResearcherProfile } from '../../core/profile/model/researcher-profile.model'; | ||
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; | ||
import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-data.service'; | ||
import { mockSuggestionPublicationOne } from '../../shared/mocks/reciter-suggestion.mock'; | ||
import { ResourceType } from '../../core/shared/resource-type'; | ||
|
||
|
||
import { | ||
SuggestionTarget | ||
} from '../../core/suggestion-notifications/reciter-suggestions/models/suggestion-target.model'; | ||
|
||
describe('SuggestionsService test', () => { | ||
let scheduler: TestScheduler; | ||
let service: SuggestionsService; | ||
let authService: AuthService; | ||
let researcherProfileService: ResearcherProfileDataService; | ||
let suggestionsDataService: SuggestionsDataService; | ||
let suggestionSourceDataService: SuggestionSourceDataService; | ||
let suggestionTargetDataService: SuggestionTargetDataService; | ||
let translateService: any = { | ||
instant: (str) => str, | ||
}; | ||
const suggestionTarget = { | ||
id: '1234:4321', | ||
display: 'display', | ||
source: 'source', | ||
total: 8, | ||
type: new ResourceType('suggestiontarget') | ||
}; | ||
|
||
const mockResercherProfile = { | ||
id: '1234', | ||
uuid: '1234', | ||
visible: true | ||
}; | ||
|
||
function initTestService() { | ||
return new SuggestionsService( | ||
authService, | ||
researcherProfileService, | ||
suggestionsDataService, | ||
suggestionSourceDataService, | ||
suggestionTargetDataService, | ||
translateService | ||
); | ||
} | ||
|
||
beforeEach(() => { | ||
scheduler = getTestScheduler(); | ||
|
||
|
||
suggestionSourceDataService = jasmine.createSpyObj('suggestionSourcesDataService', { | ||
getSources: observableOf(null), | ||
}); | ||
|
||
researcherProfileService = jasmine.createSpyObj('researcherProfileService', { | ||
findById: createSuccessfulRemoteDataObject$(mockResercherProfile as ResearcherProfile), | ||
findRelatedItemId: observableOf('1234'), | ||
}); | ||
|
||
suggestionTargetDataService = jasmine.createSpyObj('suggestionTargetsDataService', { | ||
getTargets: observableOf(null), | ||
findById: observableOf(null), | ||
}); | ||
|
||
suggestionsDataService = jasmine.createSpyObj('suggestionsDataService', { | ||
searchBy: observableOf(null), | ||
delete: observableOf(null), | ||
deleteSuggestion: createSuccessfulRemoteDataObject$({}), | ||
getSuggestionsByTargetAndSource : observableOf(null), | ||
clearSuggestionRequests : null, | ||
getTargetsByUser: observableOf(null), | ||
}); | ||
|
||
service = initTestService(); | ||
|
||
}); | ||
|
||
describe('Suggestion service', () => { | ||
it('should create', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
|
||
it('should get targets', () => { | ||
const sortOptions = new SortOptions('display', SortDirection.ASC); | ||
const findListOptions: FindListOptions = { | ||
elementsPerPage: 10, | ||
currentPage: 1, | ||
sort: sortOptions | ||
}; | ||
service.getTargets('source', 10, 1); | ||
expect(suggestionTargetDataService.getTargets).toHaveBeenCalledWith('source', findListOptions); | ||
}); | ||
|
||
it('should get suggestions', () => { | ||
const sortOptions = new SortOptions('display', SortDirection.ASC); | ||
const findListOptions: FindListOptions = { | ||
elementsPerPage: 10, | ||
currentPage: 1, | ||
sort: sortOptions | ||
}; | ||
service.getSuggestions('source:target', 10, 1, sortOptions); | ||
expect(suggestionsDataService.getSuggestionsByTargetAndSource).toHaveBeenCalledWith('target', 'source', findListOptions); | ||
}); | ||
|
||
it('should clear suggestions', () => { | ||
service.clearSuggestionRequests(); | ||
expect(suggestionsDataService.clearSuggestionRequests).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should delete reviewed suggestion', () => { | ||
service.deleteReviewedSuggestion('1234'); | ||
expect(suggestionsDataService.deleteSuggestion).toHaveBeenCalledWith('1234'); | ||
}); | ||
|
||
it('should retrieve current user suggestions', () => { | ||
service.retrieveCurrentUserSuggestions('1234'); | ||
expect(researcherProfileService.findById).toHaveBeenCalledWith('1234'); | ||
}); | ||
|
||
it('should approve and import suggestion', () => { | ||
spyOn(service, 'resolveCollectionId'); | ||
const workspaceitemService = {importExternalSourceEntry: (x,y) => observableOf(null)}; | ||
service.approveAndImport(workspaceitemService as unknown as WorkspaceitemDataService, mockSuggestionPublicationOne, '1234'); | ||
expect(service.resolveCollectionId).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should approve and import suggestions', () => { | ||
spyOn(service, 'approveAndImport'); | ||
const workspaceitemService = {importExternalSourceEntry: (x,y) => observableOf(null)}; | ||
service.approveAndImportMultiple(workspaceitemService as unknown as WorkspaceitemDataService, [mockSuggestionPublicationOne], '1234'); | ||
expect(service.approveAndImport).toHaveBeenCalledWith(workspaceitemService as unknown as WorkspaceitemDataService, mockSuggestionPublicationOne, '1234'); | ||
}); | ||
|
||
it('should delete suggestion', () => { | ||
spyOn(service, 'deleteReviewedSuggestion').and.returnValue(createSuccessfulRemoteDataObject$({})); | ||
service.notMine('1234'); | ||
expect(service.deleteReviewedSuggestion).toHaveBeenCalledWith('1234'); | ||
}); | ||
|
||
it('should delete suggestions', () => { | ||
spyOn(service, 'notMine'); | ||
service.notMineMultiple([mockSuggestionPublicationOne]); | ||
expect(service.notMine).toHaveBeenCalledWith(mockSuggestionPublicationOne.id); | ||
}); | ||
|
||
it('should get target Uuid', () => { | ||
expect(service.getTargetUuid(suggestionTarget as SuggestionTarget)).toBe('4321'); | ||
expect(service.getTargetUuid({id: ''} as SuggestionTarget)).toBe(null); | ||
}); | ||
|
||
it('should get suggestion interpolation', () => { | ||
const result = service.getNotificationSuggestionInterpolation(suggestionTarget as SuggestionTarget); | ||
expect(result.count).toEqual(suggestionTarget.total); | ||
expect(result.source).toEqual('reciter.suggestion.source.' + suggestionTarget.source); | ||
expect(result.type).toEqual('reciter.suggestion.type.' + suggestionTarget.source); | ||
expect(result.suggestionId).toEqual(suggestionTarget.id); | ||
expect(result.displayName).toEqual(suggestionTarget.display); | ||
}); | ||
|
||
it('should translate suggestion type', () => { | ||
expect(service.translateSuggestionType('source')).toEqual('reciter.suggestion.type.source'); | ||
}); | ||
|
||
it('should translate suggestion source', () => { | ||
expect(service.translateSuggestionSource('source')).toEqual('reciter.suggestion.source.source'); | ||
}); | ||
|
||
it('should resolve collection id', () => { | ||
expect(service.resolveCollectionId(mockSuggestionPublicationOne, '1234')).toEqual('1234'); | ||
}); | ||
|
||
it('should check if collection is fixed', () => { | ||
expect(service.isCollectionFixed([mockSuggestionPublicationOne])).toBeFalse(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.