-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #724 from 4Science/CST-3091
DS-4514 start a new submission via file
- Loading branch information
Showing
12 changed files
with
312 additions
and
22 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/app/+my-dspace-page/collection-selector/collection-selector.component.html
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,11 @@ | ||
<div> | ||
<div class="modal-header">{{'dso-selector.create.submission.head' | translate}} | ||
<button type="button" class="close" (click)="close()" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<ds-collection-dropdown (selectionChange)="selectObject($event.collection)"> | ||
</ds-collection-dropdown> | ||
</div> | ||
</div> |
Empty file.
164 changes: 164 additions & 0 deletions
164
src/app/+my-dspace-page/collection-selector/collection-selector.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,164 @@ | ||
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; | ||
|
||
import { CollectionSelectorComponent } from './collection-selector.component'; | ||
import { CollectionDropdownComponent } from 'src/app/shared/collection-dropdown/collection-dropdown.component'; | ||
import { Collection } from 'src/app/core/shared/collection.model'; | ||
import { of, Observable } from 'rxjs'; | ||
import { RemoteData } from 'src/app/core/data/remote-data'; | ||
import { Community } from 'src/app/core/shared/community.model'; | ||
import { FindListOptions } from 'src/app/core/data/request.models'; | ||
import { FollowLinkConfig } from 'src/app/shared/utils/follow-link-config.model'; | ||
import { PaginatedList } from 'src/app/core/data/paginated-list'; | ||
import { createSuccessfulRemoteDataObject } from 'src/app/shared/remote-data.utils'; | ||
import { PageInfo } from 'src/app/core/shared/page-info.model'; | ||
import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; | ||
import { TranslateLoaderMock } from 'src/app/shared/mocks/translate-loader.mock'; | ||
import { CollectionDataService } from 'src/app/core/data/collection-data.service'; | ||
import { ChangeDetectorRef, ElementRef, NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { hot } from 'jasmine-marbles'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
describe('CollectionSelectorComponent', () => { | ||
let component: CollectionSelectorComponent; | ||
let fixture: ComponentFixture<CollectionSelectorComponent>; | ||
const modal = jasmine.createSpyObj('modal', ['close', 'dismiss']); | ||
|
||
const community: Community = Object.assign(new Community(), { | ||
id: 'ce64f48e-2c9b-411a-ac36-ee429c0e6a88', | ||
uuid: 'ce64f48e-2c9b-411a-ac36-ee429c0e6a88', | ||
name: 'Community 1' | ||
}); | ||
|
||
const collections: Collection[] = [ | ||
Object.assign(new Collection(), { | ||
id: 'ce64f48e-2c9b-411a-ac36-ee429c0e6a88', | ||
name: 'Collection 1', | ||
metadata: [ | ||
{ | ||
key: 'dc.title', | ||
language: 'en_US', | ||
value: 'Community 1-Collection 1' | ||
}], | ||
parentCommunity: of( | ||
new RemoteData(false, false, true, undefined, community, 200) | ||
) | ||
}), | ||
Object.assign(new Collection(), { | ||
id: '59ee713b-ee53-4220-8c3f-9860dc84fe33', | ||
name: 'Collection 2', | ||
metadata: [ | ||
{ | ||
key: 'dc.title', | ||
language: 'en_US', | ||
value: 'Community 1-Collection 2' | ||
}], | ||
parentCommunity: of( | ||
new RemoteData(false, false, true, undefined, community, 200) | ||
) | ||
}), | ||
Object.assign(new Collection(), { | ||
id: 'e9dbf393-7127-415f-8919-55be34a6e9ed', | ||
name: 'Collection 3', | ||
metadata: [ | ||
{ | ||
key: 'dc.title', | ||
language: 'en_US', | ||
value: 'Community 1-Collection 3' | ||
}], | ||
parentCommunity: of( | ||
new RemoteData(false, false, true, undefined, community, 200) | ||
) | ||
}), | ||
Object.assign(new Collection(), { | ||
id: '59da2ff0-9bf4-45bf-88be-e35abd33f304', | ||
name: 'Collection 4', | ||
metadata: [ | ||
{ | ||
key: 'dc.title', | ||
language: 'en_US', | ||
value: 'Community 1-Collection 4' | ||
}], | ||
parentCommunity: of( | ||
new RemoteData(false, false, true, undefined, community, 200) | ||
) | ||
}), | ||
Object.assign(new Collection(), { | ||
id: 'a5159760-f362-4659-9e81-e3253ad91ede', | ||
name: 'Collection 5', | ||
metadata: [ | ||
{ | ||
key: 'dc.title', | ||
language: 'en_US', | ||
value: 'Community 1-Collection 5' | ||
}], | ||
parentCommunity: of( | ||
new RemoteData(false, false, true, undefined, community, 200) | ||
) | ||
}) | ||
]; | ||
|
||
// tslint:disable-next-line: max-classes-per-file | ||
const collectionDataServiceMock = { | ||
getAuthorizedCollection(query: string, options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<Collection>>): Observable<RemoteData<PaginatedList<Collection>>> { | ||
return hot( 'a|', { | ||
a: createSuccessfulRemoteDataObject( | ||
new PaginatedList(new PageInfo(), collections) | ||
) | ||
}); | ||
} | ||
}; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
TranslateModule.forRoot({ | ||
loader: { | ||
provide: TranslateLoader, | ||
useClass: TranslateLoaderMock | ||
} | ||
}) | ||
], | ||
declarations: [ CollectionSelectorComponent, CollectionDropdownComponent ], | ||
providers: [ | ||
{provide: CollectionDataService, useValue: collectionDataServiceMock}, | ||
{provide: ChangeDetectorRef, useValue: {}}, | ||
{provide: ElementRef, userValue: {}}, | ||
{provide: NgbActiveModal, useValue: modal}, | ||
{provide: ActivatedRoute, useValue: {}} | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CollectionSelectorComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should call selectObject', fakeAsync(() => { | ||
spyOn(component, 'selectObject'); | ||
fixture.detectChanges(); | ||
tick(); | ||
fixture.whenStable().then(() => { | ||
const collectionItem = fixture.debugElement.query(By.css('.collection-item:nth-child(2)')); | ||
collectionItem.triggerEventHandler('click', { | ||
preventDefault: () => {/**/ | ||
} | ||
}); | ||
expect(component.selectObject).toHaveBeenCalled(); | ||
}); | ||
})); | ||
|
||
it('should close the dialog', () => { | ||
component.close(); | ||
expect((component as any).activeModal.close).toHaveBeenCalled(); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
src/app/+my-dspace-page/collection-selector/collection-selector.component.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,33 @@ | ||
import { Component } from '@angular/core'; | ||
import { DSpaceObject } from '../../core/shared/dspace-object.model'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
/** | ||
* This component displays the dialog that shows the list of selectable collections | ||
* on the MyDSpace page | ||
*/ | ||
@Component({ | ||
selector: 'ds-collection-selector', | ||
templateUrl: './collection-selector.component.html', | ||
styleUrls: ['./collection-selector.component.scss'] | ||
}) | ||
export class CollectionSelectorComponent { | ||
|
||
constructor(protected activeModal: NgbActiveModal) {} | ||
|
||
/** | ||
* Method called when an element has been selected from collection list. | ||
* Its close the active modal and send selected value to the component container | ||
* @param dso The selected DSpaceObject | ||
*/ | ||
selectObject(dso: DSpaceObject) { | ||
this.activeModal.close(dso); | ||
} | ||
|
||
/** | ||
* Close the modal | ||
*/ | ||
close() { | ||
this.activeModal.close(); | ||
} | ||
} |
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
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
Oops, something went wrong.