diff --git a/src/app/entity-groups/research-entities/submission/name-variant-modal/name-variant-modal.component.html b/src/app/entity-groups/research-entities/submission/name-variant-modal/name-variant-modal.component.html
index 9d2139621c..13ae884ccb 100644
--- a/src/app/entity-groups/research-entities/submission/name-variant-modal/name-variant-modal.component.html
+++ b/src/app/entity-groups/research-entities/submission/name-variant-modal/name-variant-modal.component.html
@@ -8,6 +8,6 @@
{{'submission.sections.describe.relationship-lookup.name-variant.notification.content' | translate: { value: value } }}
diff --git a/src/app/entity-groups/research-entities/submission/name-variant-modal/name-variant-modal.component.spec.ts b/src/app/entity-groups/research-entities/submission/name-variant-modal/name-variant-modal.component.spec.ts
index 4af7b8161a..b5043ea2d6 100644
--- a/src/app/entity-groups/research-entities/submission/name-variant-modal/name-variant-modal.component.spec.ts
+++ b/src/app/entity-groups/research-entities/submission/name-variant-modal/name-variant-modal.component.spec.ts
@@ -3,16 +3,23 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NameVariantModalComponent } from './name-variant-modal.component';
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
+import { By } from '@angular/platform-browser';
describe('NameVariantModalComponent', () => {
let component: NameVariantModalComponent;
let fixture: ComponentFixture;
+ let debugElement;
+ let modal;
+ function init() {
+ modal = jasmine.createSpyObj('modal', ['close', 'dismiss']);
+ }
beforeEach(async(() => {
+ init();
TestBed.configureTestingModule({
declarations: [NameVariantModalComponent],
imports: [NgbModule.forRoot(), TranslateModule.forRoot()],
- providers: [NgbActiveModal]
+ providers: [{ provide: NgbActiveModal, useValue: modal }]
})
.compileComponents();
}));
@@ -20,10 +27,27 @@ describe('NameVariantModalComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(NameVariantModalComponent);
component = fixture.componentInstance;
+ debugElement = fixture.debugElement;
fixture.detectChanges();
+
});
it('should create', () => {
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();
+ });
});
diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.spec.ts
new file mode 100644
index 0000000000..8e0c6fc20e
--- /dev/null
+++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.spec.ts
@@ -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;
+ 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('');
+ });
+});
diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.ts
index 173509acf9..f2553efb44 100644
--- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.ts
+++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.ts
@@ -3,7 +3,6 @@ import { Component, EventEmitter, Input, Output } from '@angular/core';
import { DynamicFormControlComponent, DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
import { FormGroup } from '@angular/forms';
import { DynamicDisabledModel } from './dynamic-disabled.model';
-import { RelationshipTypeService } from '../../../../../../core/data/relationship-type.service';
@Component({
selector: 'ds-dynamic-disabled',
@@ -21,8 +20,7 @@ export class DsDynamicDisabledComponent extends DynamicFormControlComponent {
@Output() focus: EventEmitter = new EventEmitter();
constructor(protected layoutService: DynamicFormLayoutService,
- protected validationService: DynamicFormValidationService,
- protected relationshipTypeService: RelationshipTypeService
+ protected validationService: DynamicFormValidationService
) {
super(layoutService, validationService);
}
diff --git a/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.html b/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.html
index 4455cedeb9..92d85d03f4 100644
--- a/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.html
+++ b/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.html
@@ -3,10 +3,10 @@
[name]="'checkbox' + index"
[id]="'object' + index"
[ngModel]="selected$ | async"
- (ngModelChange)="selectCheckbox($event, object)">
+ (ngModelChange)="selectCheckbox($event)">
-
\ No newline at end of file
+ (click)="selectRadio(!checked)">
+
diff --git a/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.spec.ts b/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.spec.ts
new file mode 100644
index 0000000000..25cf6b15f0
--- /dev/null
+++ b/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.spec.ts
@@ -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;
+ 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);
+ });
+});
diff --git a/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.ts b/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.ts
index 735f06fe5f..d1536c56e6 100644
--- a/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.ts
+++ b/src/app/shared/object-collection/shared/selectable-list-item-control/selectable-list-item-control.component.ts
@@ -49,29 +49,30 @@ export class SelectableListItemControlComponent implements OnInit {
})
}
- selectCheckbox(value: boolean, object: ListableObject) {
+ selectCheckbox(value: boolean) {
if (value) {
- this.selectionService.selectSingle(this.selectionConfig.listId, object);
+ this.selectionService.selectSingle(this.selectionConfig.listId, this.object);
} else {
- this.selectionService.deselectSingle(this.selectionConfig.listId, object);
+ this.selectionService.deselectSingle(this.selectionConfig.listId, this.object);
}
}
- selectRadio(value: boolean, object: ListableObject) {
- const selected$ = this.selectionService.getSelectableList(this.selectionConfig.listId);
- selected$.pipe(
- take(1),
- map((selected) => selected ? selected.selection : [])
- ).subscribe((selection) => {
- // First deselect any existing selections, this is a radio button
- selection.forEach((selectedObject) => {
- this.selectionService.deselectSingle(this.selectionConfig.listId, selectedObject);
- this.deselectObject.emit(selectedObject);
- });
- if (value) {
- this.selectionService.selectSingle(this.selectionConfig.listId, object);
- this.selectObject.emit(object);
- }
- });
+ selectRadio(value: boolean) {
+ if (value) {
+ const selected$ = this.selectionService.getSelectableList(this.selectionConfig.listId);
+ selected$.pipe(
+ take(1),
+ map((selected) => selected ? selected.selection : [])
+ ).subscribe((selection) => {
+ // First deselect any existing selections, this is a radio button
+ selection.forEach((selectedObject) => {
+ this.selectionService.deselectSingle(this.selectionConfig.listId, selectedObject);
+ this.deselectObject.emit(selectedObject);
+ });
+ this.selectionService.selectSingle(this.selectionConfig.listId, this.object);
+ this.selectObject.emit(this.object);
+ }
+ );
+ }
}
}
diff --git a/src/app/shared/search-form/search-form.component.spec.ts b/src/app/shared/search-form/search-form.component.spec.ts
index 03081e909e..74ed4bb913 100644
--- a/src/app/shared/search-form/search-form.component.spec.ts
+++ b/src/app/shared/search-form/search-form.component.spec.ts
@@ -3,7 +3,6 @@ import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { SearchFormComponent } from './search-form.component';
import { FormsModule } from '@angular/forms';
-import { ResourceType } from '../../core/shared/resource-type';
import { RouterTestingModule } from '@angular/router/testing';
import { Community } from '../../core/shared/community.model';
import { TranslateModule } from '@ngx-translate/core';