mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
more tests
This commit is contained in:
@@ -8,6 +8,6 @@
|
|||||||
{{'submission.sections.describe.relationship-lookup.name-variant.notification.content' | translate: { value: value } }}
|
{{'submission.sections.describe.relationship-lookup.name-variant.notification.content' | translate: { value: value } }}
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer justify-content-between">
|
<div class="modal-footer justify-content-between">
|
||||||
<button type="button" class="btn btn-light" (click)="modal.close()">{{'submission.sections.describe.relationship-lookup.name-variant.notification.confirm' | translate }}</button>
|
<button type="button" class="btn btn-light confirm-button" (click)="modal.close()">{{'submission.sections.describe.relationship-lookup.name-variant.notification.confirm' | translate }}</button>
|
||||||
<button type="button" class="btn btn-light" (click)="modal.dismiss()">{{'submission.sections.describe.relationship-lookup.name-variant.notification.decline' | translate }}</button>
|
<button type="button" class="btn btn-light decline-button" (click)="modal.dismiss()">{{'submission.sections.describe.relationship-lookup.name-variant.notification.decline' | translate }}</button>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -3,16 +3,23 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { NameVariantModalComponent } from './name-variant-modal.component';
|
import { NameVariantModalComponent } from './name-variant-modal.component';
|
||||||
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
describe('NameVariantModalComponent', () => {
|
describe('NameVariantModalComponent', () => {
|
||||||
let component: NameVariantModalComponent;
|
let component: NameVariantModalComponent;
|
||||||
let fixture: ComponentFixture<NameVariantModalComponent>;
|
let fixture: ComponentFixture<NameVariantModalComponent>;
|
||||||
|
let debugElement;
|
||||||
|
let modal;
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
modal = jasmine.createSpyObj('modal', ['close', 'dismiss']);
|
||||||
|
}
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
|
init();
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [NameVariantModalComponent],
|
declarations: [NameVariantModalComponent],
|
||||||
imports: [NgbModule.forRoot(), TranslateModule.forRoot()],
|
imports: [NgbModule.forRoot(), TranslateModule.forRoot()],
|
||||||
providers: [NgbActiveModal]
|
providers: [{ provide: NgbActiveModal, useValue: modal }]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
}));
|
}));
|
||||||
@@ -20,10 +27,27 @@ describe('NameVariantModalComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(NameVariantModalComponent);
|
fixture = TestBed.createComponent(NameVariantModalComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
debugElement = fixture.debugElement;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create', () => {
|
it('should create', () => {
|
||||||
expect(component).toBeTruthy();
|
expect(component).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('when close button is clicked, dismiss should be called on the modal', () => {
|
||||||
|
debugElement.query(By.css('button.close')).triggerEventHandler('click', {});
|
||||||
|
expect(modal.dismiss).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('when confirm button is clicked, close should be called on the modal', () => {
|
||||||
|
debugElement.query(By.css('button.confirm-button')).triggerEventHandler('click', {});
|
||||||
|
expect(modal.close).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('when decline button is clicked, dismiss should be called on the modal', () => {
|
||||||
|
debugElement.query(By.css('button.decline-button')).triggerEventHandler('click', {});
|
||||||
|
expect(modal.dismiss).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -0,0 +1,58 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { DsDynamicDisabledComponent } from './dynamic-disabled.component';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
|
||||||
|
import { DynamicDisabledModel } from './dynamic-disabled.model';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
describe('DsDynamicDisabledComponent', () => {
|
||||||
|
let comp: DsDynamicDisabledComponent;
|
||||||
|
let fixture: ComponentFixture<DsDynamicDisabledComponent>;
|
||||||
|
let de: DebugElement;
|
||||||
|
let el: HTMLElement;
|
||||||
|
let model;
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
model = new DynamicDisabledModel({ value: 'test', repeatable: false, metadataFields: [], submissionId: '1234', id: '1' });
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
init();
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [DsDynamicDisabledComponent],
|
||||||
|
imports: [FormsModule, TranslateModule.forRoot()],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: DynamicFormLayoutService,
|
||||||
|
useValue: {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: DynamicFormValidationService,
|
||||||
|
useValue: {}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(DsDynamicDisabledComponent);
|
||||||
|
comp = fixture.componentInstance; // DsDynamicDisabledComponent test instance
|
||||||
|
de = fixture.debugElement;
|
||||||
|
el = de.nativeElement;
|
||||||
|
comp.model = model;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(comp).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a disabled input', () => {
|
||||||
|
const input = de.query(By.css('input'));
|
||||||
|
console.log(input.nativeElement.getAttribute('disabled'));
|
||||||
|
expect(input.nativeElement.getAttribute('disabled')).toEqual('');
|
||||||
|
});
|
||||||
|
});
|
@@ -3,7 +3,6 @@ import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|||||||
import { DynamicFormControlComponent, DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
|
import { DynamicFormControlComponent, DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
|
||||||
import { FormGroup } from '@angular/forms';
|
import { FormGroup } from '@angular/forms';
|
||||||
import { DynamicDisabledModel } from './dynamic-disabled.model';
|
import { DynamicDisabledModel } from './dynamic-disabled.model';
|
||||||
import { RelationshipTypeService } from '../../../../../../core/data/relationship-type.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dynamic-disabled',
|
selector: 'ds-dynamic-disabled',
|
||||||
@@ -21,8 +20,7 @@ export class DsDynamicDisabledComponent extends DynamicFormControlComponent {
|
|||||||
@Output() focus: EventEmitter<any> = new EventEmitter<any>();
|
@Output() focus: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
constructor(protected layoutService: DynamicFormLayoutService,
|
constructor(protected layoutService: DynamicFormLayoutService,
|
||||||
protected validationService: DynamicFormValidationService,
|
protected validationService: DynamicFormValidationService
|
||||||
protected relationshipTypeService: RelationshipTypeService
|
|
||||||
) {
|
) {
|
||||||
super(layoutService, validationService);
|
super(layoutService, validationService);
|
||||||
}
|
}
|
||||||
|
@@ -3,10 +3,10 @@
|
|||||||
[name]="'checkbox' + index"
|
[name]="'checkbox' + index"
|
||||||
[id]="'object' + index"
|
[id]="'object' + index"
|
||||||
[ngModel]="selected$ | async"
|
[ngModel]="selected$ | async"
|
||||||
(ngModelChange)="selectCheckbox($event, object)">
|
(ngModelChange)="selectCheckbox($event)">
|
||||||
<input *ngIf="!selectionConfig.repeatable" class="form-check-input" type="radio"
|
<input *ngIf="!selectionConfig.repeatable" class="form-check-input" type="radio"
|
||||||
[name]="'radio' + index"
|
[name]="'radio' + index"
|
||||||
[id]="'object' + index"
|
[id]="'object' + index"
|
||||||
[checked]="selected$ | async"
|
[checked]="selected$ | async"
|
||||||
(click)="selectRadio(!checked, object)">
|
(click)="selectRadio(!checked)">
|
||||||
</ng-container>
|
</ng-container>
|
@@ -0,0 +1,91 @@
|
|||||||
|
import { ComponentFixture, TestBed, async, tick, fakeAsync } from '@angular/core/testing';
|
||||||
|
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { SelectableListService } from '../../../object-list/selectable-list/selectable-list.service';
|
||||||
|
import { SelectableListItemControlComponent } from './selectable-list-item-control.component';
|
||||||
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { VarDirective } from '../../../utils/var.directive';
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { ListableObject } from '../listable-object.model';
|
||||||
|
|
||||||
|
describe('SelectableListItemControlComponent', () => {
|
||||||
|
let comp: SelectableListItemControlComponent;
|
||||||
|
let fixture: ComponentFixture<SelectableListItemControlComponent>;
|
||||||
|
let de: DebugElement;
|
||||||
|
let el: HTMLElement;
|
||||||
|
let object;
|
||||||
|
let otherObject;
|
||||||
|
let selectionConfig;
|
||||||
|
let listId;
|
||||||
|
let index;
|
||||||
|
let selectionService;
|
||||||
|
let selection: ListableObject[];
|
||||||
|
let uuid1: string;
|
||||||
|
let uuid2: string;
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
uuid1 = '0beb44f8-d2ed-459a-a1e7-ffbe059089a9';
|
||||||
|
uuid2 = 'e1dc80aa-c269-4aa5-b6bd-008d98056247';
|
||||||
|
listId = 'Test List ID';
|
||||||
|
object = Object.assign(new Item(), {uuid: uuid1});
|
||||||
|
otherObject = Object.assign(new Item(), {uuid: uuid2});
|
||||||
|
selectionConfig = {repeatable: false, listId};
|
||||||
|
index = 0;
|
||||||
|
selection = [otherObject];
|
||||||
|
selectionService = jasmine.createSpyObj('selectionService', {
|
||||||
|
selectSingle: jasmine.createSpy('selectSingle'),
|
||||||
|
deselectSingle: jasmine.createSpy('deselectSingle'),
|
||||||
|
isObjectSelected: observableOf(true),
|
||||||
|
getSelectableList: observableOf({ selection })
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
init();
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [SelectableListItemControlComponent, VarDirective],
|
||||||
|
imports: [FormsModule],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: SelectableListService,
|
||||||
|
useValue: selectionService
|
||||||
|
}
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(SelectableListItemControlComponent);
|
||||||
|
comp = fixture.componentInstance; // SelectableListItemControlComponent test instance
|
||||||
|
de = fixture.debugElement;
|
||||||
|
el = de.nativeElement;
|
||||||
|
comp.object = object;
|
||||||
|
comp.selectionConfig = selectionConfig;
|
||||||
|
comp.index = index;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call deselectSingle on the service when the object when selectCheckbox is called with value false', () => {
|
||||||
|
comp.selectCheckbox(false);
|
||||||
|
expect(selectionService.deselectSingle).toHaveBeenCalledWith(listId, object);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call selectSingle on the service when the object when selectCheckbox is called with value false', () => {
|
||||||
|
comp.selectCheckbox(true);
|
||||||
|
expect(selectionService.selectSingle).toHaveBeenCalledWith(listId, object);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call selectSingle on the service when the object when selectRadio is called with value true and deselect all others in the selection', () => {
|
||||||
|
comp.selectRadio(true );
|
||||||
|
expect(selectionService.deselectSingle).toHaveBeenCalledWith(listId, selection[0]);
|
||||||
|
expect(selectionService.selectSingle).toHaveBeenCalledWith(listId, object);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not call selectSingle on the service when the object when selectRadio is called with value false and not deselect all others in the selection', () => {
|
||||||
|
comp.selectRadio(false );
|
||||||
|
expect(selectionService.deselectSingle).not.toHaveBeenCalledWith(listId, selection[0]);
|
||||||
|
expect(selectionService.selectSingle).not.toHaveBeenCalledWith(listId, object);
|
||||||
|
});
|
||||||
|
});
|
@@ -49,15 +49,16 @@ export class SelectableListItemControlComponent implements OnInit {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
selectCheckbox(value: boolean, object: ListableObject) {
|
selectCheckbox(value: boolean) {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.selectionService.selectSingle(this.selectionConfig.listId, object);
|
this.selectionService.selectSingle(this.selectionConfig.listId, this.object);
|
||||||
} else {
|
} else {
|
||||||
this.selectionService.deselectSingle(this.selectionConfig.listId, object);
|
this.selectionService.deselectSingle(this.selectionConfig.listId, this.object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectRadio(value: boolean, object: ListableObject) {
|
selectRadio(value: boolean) {
|
||||||
|
if (value) {
|
||||||
const selected$ = this.selectionService.getSelectableList(this.selectionConfig.listId);
|
const selected$ = this.selectionService.getSelectableList(this.selectionConfig.listId);
|
||||||
selected$.pipe(
|
selected$.pipe(
|
||||||
take(1),
|
take(1),
|
||||||
@@ -68,10 +69,10 @@ export class SelectableListItemControlComponent implements OnInit {
|
|||||||
this.selectionService.deselectSingle(this.selectionConfig.listId, selectedObject);
|
this.selectionService.deselectSingle(this.selectionConfig.listId, selectedObject);
|
||||||
this.deselectObject.emit(selectedObject);
|
this.deselectObject.emit(selectedObject);
|
||||||
});
|
});
|
||||||
if (value) {
|
this.selectionService.selectSingle(this.selectionConfig.listId, this.object);
|
||||||
this.selectionService.selectSingle(this.selectionConfig.listId, object);
|
this.selectObject.emit(this.object);
|
||||||
this.selectObject.emit(object);
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,6 @@ import { By } from '@angular/platform-browser';
|
|||||||
import { DebugElement } from '@angular/core';
|
import { DebugElement } from '@angular/core';
|
||||||
import { SearchFormComponent } from './search-form.component';
|
import { SearchFormComponent } from './search-form.component';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
import { ResourceType } from '../../core/shared/resource-type';
|
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { Community } from '../../core/shared/community.model';
|
import { Community } from '../../core/shared/community.model';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
Reference in New Issue
Block a user