dynamic-lookup-relation-modal.component.spec.ts (dspace-angular-dspace-7.0) | : | dynamic-lookup-relation-modal.component.spec.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | |||
import { TranslateModule } from '@ngx-translate/core'; | import { TranslateModule } from '@ngx-translate/core'; | |||
import { RouterTestingModule } from '@angular/router/testing'; | import { RouterTestingModule } from '@angular/router/testing'; | |||
import { NgZone, NO_ERRORS_SCHEMA } from '@angular/core'; | import { NgZone, NO_ERRORS_SCHEMA, DebugElement, EventEmitter } from '@angular/c ore'; | |||
import { of as observableOf, Subscription } from 'rxjs'; | import { of as observableOf, Subscription } from 'rxjs'; | |||
import { DsDynamicLookupRelationModalComponent } from './dynamic-lookup-relation -modal.component'; | import { DsDynamicLookupRelationModalComponent } from './dynamic-lookup-relation -modal.component'; | |||
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap'; | import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap'; | |||
import { SelectableListService } from '../../../../object-list/selectable-list/s electable-list.service'; | import { SelectableListService } from '../../../../object-list/selectable-list/s electable-list.service'; | |||
import { RelationshipService } from '../../../../../core/data/relationship.servi ce'; | import { RelationshipService } from '../../../../../core/data/relationship.servi ce'; | |||
import { RelationshipTypeService } from '../../../../../core/data/relationship-t ype.service'; | import { RelationshipTypeService } from '../../../../../core/data/relationship-t ype.service'; | |||
import { Store } from '@ngrx/store'; | import { Store } from '@ngrx/store'; | |||
import { Item } from '../../../../../core/shared/item.model'; | import { Item } from '../../../../../core/shared/item.model'; | |||
import { ItemSearchResult } from '../../../../object-collection/shared/item-sear ch-result.model'; | import { ItemSearchResult } from '../../../../object-collection/shared/item-sear ch-result.model'; | |||
import { RelationshipOptions } from '../../models/relationship-options.model'; | import { RelationshipOptions } from '../../models/relationship-options.model'; | |||
skipping to change at line 26 | skipping to change at line 26 | |||
import { SearchConfigurationService } from '../../../../../core/shared/search/se arch-configuration.service'; | import { SearchConfigurationService } from '../../../../../core/shared/search/se arch-configuration.service'; | |||
import { PaginatedSearchOptions } from '../../../../search/paginated-search-opti ons.model'; | import { PaginatedSearchOptions } from '../../../../search/paginated-search-opti ons.model'; | |||
import { ExternalSource } from '../../../../../core/shared/external-source.model '; | import { ExternalSource } from '../../../../../core/shared/external-source.model '; | |||
import { createSuccessfulRemoteDataObject$ } from '../../../../remote-data.utils '; | import { createSuccessfulRemoteDataObject$ } from '../../../../remote-data.utils '; | |||
import { createPaginatedList } from '../../../../testing/utils.test'; | import { createPaginatedList } from '../../../../testing/utils.test'; | |||
import { ExternalSourceService } from '../../../../../core/data/external-source. service'; | import { ExternalSourceService } from '../../../../../core/data/external-source. service'; | |||
import { LookupRelationService } from '../../../../../core/data/lookup-relation. service'; | import { LookupRelationService } from '../../../../../core/data/lookup-relation. service'; | |||
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remot e-data-build.service'; | import { RemoteDataBuildService } from '../../../../../core/cache/builders/remot e-data-build.service'; | |||
import { WorkspaceItem } from '../../../../../core/submission/models/workspaceit em.model'; | import { WorkspaceItem } from '../../../../../core/submission/models/workspaceit em.model'; | |||
import { Collection } from '../../../../../core/shared/collection.model'; | import { Collection } from '../../../../../core/shared/collection.model'; | |||
import { By } from '@angular/platform-browser'; | ||||
describe('DsDynamicLookupRelationModalComponent', () => { | describe('DsDynamicLookupRelationModalComponent', () => { | |||
let component: DsDynamicLookupRelationModalComponent; | let component: DsDynamicLookupRelationModalComponent; | |||
let fixture: ComponentFixture<DsDynamicLookupRelationModalComponent>; | let fixture: ComponentFixture<DsDynamicLookupRelationModalComponent>; | |||
let debugElement: DebugElement; | ||||
let item; | let item; | |||
let item1; | let item1; | |||
let item2; | let item2; | |||
let testWSI; | let testWSI; | |||
let searchResult1; | let searchResult1; | |||
let searchResult2; | let searchResult2; | |||
let listID; | let listID; | |||
let selection$; | let selection$; | |||
let selectableListService; | let selectableListService; | |||
let relationship; | let relationship; | |||
skipping to change at line 138 | skipping to change at line 140 | |||
{ provide: NgZone, useValue: new NgZone({}) }, | { provide: NgZone, useValue: new NgZone({}) }, | |||
NgbActiveModal | NgbActiveModal | |||
], | ], | |||
schemas: [NO_ERRORS_SCHEMA] | schemas: [NO_ERRORS_SCHEMA] | |||
}) | }) | |||
.compileComponents(); | .compileComponents(); | |||
})); | })); | |||
beforeEach(() => { | beforeEach(() => { | |||
fixture = TestBed.createComponent(DsDynamicLookupRelationModalComponent); | fixture = TestBed.createComponent(DsDynamicLookupRelationModalComponent); | |||
debugElement = fixture.debugElement; | ||||
component = fixture.componentInstance; | component = fixture.componentInstance; | |||
component.listId = listID; | component.listId = listID; | |||
component.relationshipOptions = relationship; | component.relationshipOptions = relationship; | |||
component.item = item; | component.item = item; | |||
component.metadataFields = metadataField; | component.metadataFields = metadataField; | |||
component.submissionId = submissionId; | component.submissionId = submissionId; | |||
component.isEditRelationship = true; | ||||
component.currentItemIsLeftItem$ = observableOf(true); | ||||
component.toAdd = []; | ||||
component.toRemove = []; | ||||
fixture.detectChanges(); | fixture.detectChanges(); | |||
}); | }); | |||
it('should create', () => { | it('should create', () => { | |||
expect(component).toBeTruthy(); | expect(component).toBeTruthy(); | |||
}); | }); | |||
describe('close', () => { | describe('close', () => { | |||
beforeEach(() => { | beforeEach(() => { | |||
spyOn(component.modal, 'close'); | spyOn(component.modal, 'close'); | |||
skipping to change at line 193 | skipping to change at line 200 | |||
it('should dispatch an RemoveRelationshipAction for each deselected object', () => { | it('should dispatch an RemoveRelationshipAction for each deselected object', () => { | |||
component.deselect(searchResult1, searchResult2); | component.deselect(searchResult1, searchResult2); | |||
const action = new RemoveRelationshipAction(component.item, searchResult1. indexableObject, relationship.relationshipType, submissionId); | const action = new RemoveRelationshipAction(component.item, searchResult1. indexableObject, relationship.relationshipType, submissionId); | |||
const action2 = new RemoveRelationshipAction(component.item, searchResult2 .indexableObject, relationship.relationshipType, submissionId); | const action2 = new RemoveRelationshipAction(component.item, searchResult2 .indexableObject, relationship.relationshipType, submissionId); | |||
expect((component as any).store.dispatch).toHaveBeenCalledWith(action); | expect((component as any).store.dispatch).toHaveBeenCalledWith(action); | |||
expect((component as any).store.dispatch).toHaveBeenCalledWith(action2); | expect((component as any).store.dispatch).toHaveBeenCalledWith(action2); | |||
}); | }); | |||
}); | }); | |||
describe('when initialized and is relationship show the list of buttons', () = | ||||
> { | ||||
it('should show buttons container', () => { | ||||
expect(debugElement.query(By.css('.button-row'))).toBeTruthy(); | ||||
}); | ||||
it('submit button should be disabled', () => { | ||||
expect(debugElement.query(By.css('.submit')).nativeElement?.disabled).toBe | ||||
True(); | ||||
}); | ||||
it('discard button should be disabled', () => { | ||||
expect(debugElement.query(By.css('.discard')).nativeElement?.disabled).toB | ||||
eTrue(); | ||||
}); | ||||
}); | ||||
describe('when changes happen', () => { | ||||
beforeEach(() => { | ||||
component.toAdd.push(searchResult1); | ||||
component.toRemove.push(searchResult2); | ||||
fixture.detectChanges(); | ||||
}); | ||||
it('submit button should be enabled', () => { | ||||
expect(debugElement.query(By.css('.submit')).nativeElement?.disabled).toBe | ||||
False(); | ||||
}); | ||||
it('discard button should be enabled', () => { | ||||
expect(debugElement.query(By.css('.discard')).nativeElement?.disabled).toB | ||||
eFalse(); | ||||
}); | ||||
it('should call submitEv when submit clicked', () => { | ||||
const submitFunct = spyOn((component as any), 'submitEv'); | ||||
debugElement.query(By.css('.submit')).nativeElement.click(); | ||||
expect(submitFunct).toHaveBeenCalled(); | ||||
}); | ||||
it('should call discardEv when discard clicked', () => { | ||||
const discardFunct = spyOn((component as any), 'discardEv'); | ||||
debugElement.query(By.css('.discard')).nativeElement.click(); | ||||
expect(discardFunct).toHaveBeenCalled(); | ||||
}); | ||||
}); | ||||
describe('when request starts and isPending changes', () => { | ||||
beforeEach(() => { | ||||
component.isPending = true; | ||||
fixture.detectChanges(); | ||||
}); | ||||
it('there should show 1 spinner and disable all 3 buttons', () => { | ||||
expect(debugElement.queryAll(By.css('.spinner-border')).length).toEqual(1) | ||||
; | ||||
expect(debugElement.query(By.css('.submit')).nativeElement?.disabled).toBe | ||||
True(); | ||||
expect(debugElement.query(By.css('.discard')).nativeElement?.disabled).toB | ||||
eTrue(); | ||||
expect(debugElement.query(By.css('.close')).nativeElement?.disabled).toBeT | ||||
rue(); | ||||
}); | ||||
}); | ||||
}); | }); | |||
End of changes. 6 change blocks. | ||||
1 lines changed or deleted | 70 lines changed or added |