mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 20:43:08 +00:00
Added unit test
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
// Load the implementations that should be tested
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, inject, TestBed, } from '@angular/core/testing';
|
||||
import 'rxjs/add/observable/of';
|
||||
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { SortablejsModule } from 'angular-sortablejs';
|
||||
import { DsDatePickerComponent } from './date-picker.component';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { DynamicDsDatePickerModel } from './date-picker.model';
|
||||
|
||||
function createTestComponent<T>(html: string, type: { new(...args: any[]): T }): ComponentFixture<T> {
|
||||
TestBed.overrideComponent(type, {
|
||||
set: {template: html}
|
||||
});
|
||||
const fixture = TestBed.createComponent(type);
|
||||
|
||||
fixture.detectChanges();
|
||||
return fixture as ComponentFixture<T>;
|
||||
}
|
||||
|
||||
describe('Date Picker component', () => {
|
||||
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
let html;
|
||||
|
||||
// async beforeEach
|
||||
beforeEach(async(() => {
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
NgbModule.forRoot()
|
||||
],
|
||||
declarations: [
|
||||
DsDatePickerComponent,
|
||||
TestComponent,
|
||||
], // declare the test component
|
||||
providers: [
|
||||
ChangeDetectorRef,
|
||||
DsDatePickerComponent,
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
html = `
|
||||
<ds-date-picker
|
||||
[bindId]='bindId'
|
||||
[group]='group'
|
||||
[model]='model'
|
||||
[showErrorMessages]='showErrorMessages'
|
||||
(blur)='onBlur($event)'
|
||||
(change)='onValueChange($event)'
|
||||
(focus)='onFocus($event)'></ds-date-picker>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should create DsDatePickerComponent', inject([DsDatePickerComponent], (app: DsDatePickerComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
group = new FormGroup({
|
||||
date: new FormControl(),
|
||||
});
|
||||
|
||||
inputDateModelConfig = {
|
||||
disabled: false,
|
||||
errorMessages: { required: 'You must enter at least the year.' },
|
||||
id: 'date',
|
||||
label: 'Date',
|
||||
name: 'date',
|
||||
placeholder: 'Date',
|
||||
readOnly: false,
|
||||
required: true,
|
||||
toggleIcon: 'fa fa-calendar'
|
||||
};
|
||||
|
||||
model = new DynamicDsDatePickerModel(this.inputDateModelConfig);
|
||||
|
||||
showErrorMessages = false;
|
||||
|
||||
}
|
@@ -12,8 +12,8 @@ import { hasValue } from '../../../../empty.util';
|
||||
import { FormFieldMetadataValueObject } from '../../models/form-field-metadata-value.model';
|
||||
|
||||
export interface DsDynamicInputModelConfig extends DynamicInputModelConfig {
|
||||
authorityOptions: AuthorityOptions;
|
||||
languageCodes: LanguageCode[];
|
||||
authorityOptions?: AuthorityOptions;
|
||||
languageCodes?: LanguageCode[];
|
||||
language?: string;
|
||||
value?: any;
|
||||
}
|
||||
|
@@ -0,0 +1,159 @@
|
||||
// Load the implementations that should be tested
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, inject, TestBed, } from '@angular/core/testing';
|
||||
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import 'rxjs/add/observable/of';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
import { DsDynamicGroupComponent } from './dynamic-group.components';
|
||||
import { DynamicGroupModel } from './dynamic-group.model';
|
||||
import { FormRowModel } from '../../../../../../core/shared/config/config-submission-forms.model';
|
||||
import { FormFieldModel } from '../../../models/form-field.model';
|
||||
import { FormBuilderService } from '../../../form-builder.service';
|
||||
import { FormService } from '../../../../form.service';
|
||||
import { GlobalConfig } from '../../../../../../../config/global-config.interface';
|
||||
import { GLOBAL_CONFIG } from '../../../../../../../config';
|
||||
import { FormComponent } from '../../../../form.component';
|
||||
import { DynamicFormValidationService } from '@ng-dynamic-forms/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppState } from '../../../../../../app.reducer';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
function createTestComponent<T>(html: string, type: { new(...args: any[]): T }): ComponentFixture<T> {
|
||||
TestBed.overrideComponent(type, {
|
||||
set: {template: html}
|
||||
});
|
||||
const fixture = TestBed.createComponent(type);
|
||||
|
||||
fixture.detectChanges();
|
||||
return fixture as ComponentFixture<T>;
|
||||
}
|
||||
|
||||
describe('Dynamic Group component', () => {
|
||||
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
let html;
|
||||
|
||||
const mockStore: Store<AppState> = jasmine.createSpyObj('store', {
|
||||
dispatch: {},
|
||||
select: Observable.of(true)
|
||||
});
|
||||
|
||||
// async beforeEach
|
||||
beforeEach(async(() => {
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
NgbModule.forRoot(),
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [
|
||||
FormComponent,
|
||||
DsDynamicGroupComponent,
|
||||
TestComponent,
|
||||
], // declare the test component
|
||||
providers: [
|
||||
ChangeDetectorRef,
|
||||
DsDynamicGroupComponent,
|
||||
DynamicFormValidationService,
|
||||
FormBuilderService,
|
||||
FormComponent,
|
||||
FormService,
|
||||
{provide: GLOBAL_CONFIG, useValue: {} as GlobalConfig},
|
||||
{provide: Store, useValue: mockStore},
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
html = `
|
||||
<ds-date-picker
|
||||
[bindId]='bindId'
|
||||
[group]='group'
|
||||
[model]='model'
|
||||
[showErrorMessages]='showErrorMessages'
|
||||
(blur)='onBlur($event)'
|
||||
(change)='onValueChange($event)'
|
||||
(focus)='onFocus($event)'></ds-date-picker>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should create DsDynamicGroupComponent', inject([DsDynamicGroupComponent], (app: DsDynamicGroupComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
group = new FormGroup({
|
||||
date: new FormControl(),
|
||||
});
|
||||
|
||||
groupModelConfig = {
|
||||
disabled: false,
|
||||
errorMessages: {required: 'You must specify at least one author.'},
|
||||
formConfiguration: [{
|
||||
fields: [{
|
||||
hints: 'Enter the name of the author.',
|
||||
input: {type: 'onebox'},
|
||||
label: 'Authors',
|
||||
languageCodes: [],
|
||||
mandatory: 'true',
|
||||
mandatoryMessage: 'Required field!',
|
||||
repeatable: false,
|
||||
selectableMetadata: [{
|
||||
authority: 'RPAuthority',
|
||||
closed: false,
|
||||
metadata: 'dc.contributor.author'
|
||||
}],
|
||||
} as FormFieldModel]
|
||||
} as FormRowModel, {
|
||||
fields: [{
|
||||
hints: 'Enter the affiliation of the author.',
|
||||
input: {type: 'onebox'},
|
||||
label: 'Affiliation',
|
||||
languageCodes: [],
|
||||
mandatory: 'false',
|
||||
repeatable: false,
|
||||
selectableMetadata: [{
|
||||
authority: 'OUAuthority',
|
||||
closed: false,
|
||||
metadata: 'local.contributor.affiliation'
|
||||
}]
|
||||
} as FormFieldModel]
|
||||
} as FormRowModel],
|
||||
id: 'date',
|
||||
label: 'Date',
|
||||
mandatoryField: 'dc.contributor.author',
|
||||
name: 'date',
|
||||
placeholder: 'Date',
|
||||
readOnly: false,
|
||||
relationFields: ['local.contributor.affiliation'],
|
||||
required: true,
|
||||
scopeUUID: '43fe1f8c-09a6-4fcf-9c78-5d4fed8f2c8f',
|
||||
submissionScope: undefined,
|
||||
validators: {required: null}
|
||||
};
|
||||
|
||||
model = new DynamicGroupModel(this.groupModelConfig);
|
||||
|
||||
showErrorMessages = false;
|
||||
|
||||
}
|
@@ -11,7 +11,7 @@ import { hasValue } from '../../../../../empty.util';
|
||||
|
||||
export interface DynamicListCheckboxGroupModelConfig extends DynamicFormGroupModelConfig {
|
||||
authorityOptions: AuthorityOptions;
|
||||
groupLength: number;
|
||||
groupLength?: number;
|
||||
repeatable: boolean;
|
||||
value?: any;
|
||||
}
|
||||
|
@@ -0,0 +1,126 @@
|
||||
// Load the implementations that should be tested
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { async, ComponentFixture, inject, TestBed, } from '@angular/core/testing';
|
||||
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
import { DsDynamicListComponent } from './dynamic-list.component';
|
||||
import { DynamicListCheckboxGroupModel } from './dynamic-list-checkbox-group.model';
|
||||
import { AuthorityOptions } from '../../../../../../core/integration/models/authority-options.model';
|
||||
import { FormBuilderService } from '../../../form-builder.service';
|
||||
import { DynamicFormControlLayout, DynamicFormsCoreModule, DynamicFormValidationService } from '@ng-dynamic-forms/core';
|
||||
import { DynamicFormsNGBootstrapUIModule } from '@ng-dynamic-forms/ui-ng-bootstrap';
|
||||
import { AuthorityService } from '../../../../../../core/integration/authority.service';
|
||||
import { AuthorityServiceStub } from '../../../../../testing/authority-service-stub';
|
||||
import { FormBuilderServiceStub } from '../../../../../testing/form-builder-service-stub';
|
||||
|
||||
function createTestComponent<T>(html: string, type: { new(...args: any[]): T }): ComponentFixture<T> {
|
||||
TestBed.overrideComponent(type, {
|
||||
set: {template: html}
|
||||
});
|
||||
const fixture = TestBed.createComponent(type);
|
||||
|
||||
fixture.detectChanges();
|
||||
return fixture as ComponentFixture<T>;
|
||||
}
|
||||
|
||||
describe('Dynamic List component', () => {
|
||||
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
let html;
|
||||
|
||||
// async beforeEach
|
||||
beforeEach(async(() => {
|
||||
const authorityServiceStub = new AuthorityServiceStub();
|
||||
const formBuilderServiceStub = new FormBuilderServiceStub();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
DynamicFormsCoreModule,
|
||||
DynamicFormsNGBootstrapUIModule,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
NgbModule.forRoot()
|
||||
],
|
||||
declarations: [
|
||||
DsDynamicListComponent,
|
||||
TestComponent,
|
||||
], // declare the test component
|
||||
providers: [
|
||||
AuthorityService,
|
||||
ChangeDetectorRef,
|
||||
DsDynamicListComponent,
|
||||
DynamicFormValidationService,
|
||||
FormBuilderService,
|
||||
{provide: AuthorityService, useValue: authorityServiceStub},
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
html = `
|
||||
<ds-dynamic-list
|
||||
[bindId]="bindId"
|
||||
[group]="group"
|
||||
[model]="model"
|
||||
[showErrorMessages]="showErrorMessages"
|
||||
(blur)="onBlur($event)"
|
||||
(change)="onValueChange($event)"
|
||||
(focus)="onFocus($event)"></ds-dynamic-list>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should create DsDynamicListComponent', inject([DsDynamicListComponent], (app: DsDynamicListComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
group: FormGroup = new FormGroup({
|
||||
list: new FormGroup({}),
|
||||
});
|
||||
|
||||
inputListModelConfig = {
|
||||
authorityOptions: {
|
||||
closed: false,
|
||||
metadata: 'list',
|
||||
name: 'type_programme',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
} as AuthorityOptions,
|
||||
disabled: false,
|
||||
errorMessages: {required: 'You must enter at least the year.'},
|
||||
id: 'list',
|
||||
label: 'Programme',
|
||||
name: 'list',
|
||||
placeholder: 'Programme',
|
||||
readOnly: false,
|
||||
required: true,
|
||||
repeatable: true
|
||||
};
|
||||
|
||||
layout: DynamicFormControlLayout = {
|
||||
element: {
|
||||
group: ''
|
||||
}
|
||||
};
|
||||
|
||||
model = new DynamicListCheckboxGroupModel(this.inputListModelConfig, this.layout);
|
||||
|
||||
showErrorMessages = false;
|
||||
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
// Load the implementations that should be tested
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { async, ComponentFixture, inject, TestBed, } from '@angular/core/testing';
|
||||
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
import { AuthorityOptions } from '../../../../../../core/integration/models/authority-options.model';
|
||||
import { DynamicFormsCoreModule } from '@ng-dynamic-forms/core';
|
||||
import { DynamicFormsNGBootstrapUIModule } from '@ng-dynamic-forms/ui-ng-bootstrap';
|
||||
import { AuthorityService } from '../../../../../../core/integration/authority.service';
|
||||
import { AuthorityServiceStub } from '../../../../../testing/authority-service-stub';
|
||||
import { FormBuilderServiceStub } from '../../../../../testing/form-builder-service-stub';
|
||||
import { DsDynamicLookupComponent } from './dynamic-lookup.component';
|
||||
import { DynamicLookupModel } from './dynamic-lookup.model';
|
||||
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
function createTestComponent<T>(html: string, type: { new(...args: any[]): T }): ComponentFixture<T> {
|
||||
TestBed.overrideComponent(type, {
|
||||
set: {template: html}
|
||||
});
|
||||
const fixture = TestBed.createComponent(type);
|
||||
|
||||
fixture.detectChanges();
|
||||
return fixture as ComponentFixture<T>;
|
||||
}
|
||||
|
||||
describe('Dynamic Lookup component', () => {
|
||||
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
let html;
|
||||
|
||||
// async beforeEach
|
||||
beforeEach(async(() => {
|
||||
const authorityServiceStub = new AuthorityServiceStub();
|
||||
const formBuilderServiceStub = new FormBuilderServiceStub();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
DynamicFormsCoreModule,
|
||||
DynamicFormsNGBootstrapUIModule,
|
||||
FormsModule,
|
||||
InfiniteScrollModule,
|
||||
ReactiveFormsModule,
|
||||
NgbModule.forRoot(),
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [
|
||||
DsDynamicLookupComponent,
|
||||
TestComponent,
|
||||
], // declare the test component
|
||||
providers: [
|
||||
ChangeDetectorRef,
|
||||
DsDynamicLookupComponent,
|
||||
{provide: AuthorityService, useValue: authorityServiceStub},
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
html = `
|
||||
<ds-dynamic-lookup
|
||||
[bindId]="bindId"
|
||||
[group]="group"
|
||||
[model]="model"
|
||||
[showErrorMessages]="showErrorMessages"
|
||||
(blur)="onBlur($event)"
|
||||
(change)="onValueChange($event)"
|
||||
(focus)="onFocus($event)"></ds-dynamic-lookup>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should create DsDynamicLookupComponent', inject([DsDynamicLookupComponent], (app: DsDynamicLookupComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
group: FormGroup = new FormGroup({
|
||||
lookup: new FormControl(),
|
||||
});
|
||||
|
||||
inputLookupModelConfig = {
|
||||
authorityOptions: {
|
||||
closed: false,
|
||||
metadata: 'lookup',
|
||||
name: 'RPAuthority',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
} as AuthorityOptions,
|
||||
disabled: false,
|
||||
errorMessages: {required: 'Required field.'},
|
||||
id: 'lookup',
|
||||
label: 'Author',
|
||||
maxOptions: 10,
|
||||
name: 'lookup',
|
||||
placeholder: 'Author',
|
||||
readOnly: false,
|
||||
required: true,
|
||||
repeatable: true,
|
||||
separator: ',',
|
||||
validators: {required: null},
|
||||
value: undefined
|
||||
};
|
||||
|
||||
model = new DynamicLookupModel(this.inputLookupModelConfig);
|
||||
|
||||
showErrorMessages = false;
|
||||
|
||||
}
|
@@ -0,0 +1,121 @@
|
||||
// Load the implementations that should be tested
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { async, ComponentFixture, inject, TestBed, } from '@angular/core/testing';
|
||||
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
import { AuthorityOptions } from '../../../../../../core/integration/models/authority-options.model';
|
||||
import { DynamicFormsCoreModule } from '@ng-dynamic-forms/core';
|
||||
import { DynamicFormsNGBootstrapUIModule } from '@ng-dynamic-forms/ui-ng-bootstrap';
|
||||
import { AuthorityService } from '../../../../../../core/integration/authority.service';
|
||||
import { AuthorityServiceStub } from '../../../../../testing/authority-service-stub';
|
||||
import { FormBuilderServiceStub } from '../../../../../testing/form-builder-service-stub';
|
||||
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DsDynamicScrollableDropdownComponent } from './dynamic-scrollable-dropdown.component';
|
||||
import { DynamicScrollableDropdownModel } from './dynamic-scrollable-dropdown.model';
|
||||
|
||||
function createTestComponent<T>(html: string, type: { new(...args: any[]): T }): ComponentFixture<T> {
|
||||
TestBed.overrideComponent(type, {
|
||||
set: {template: html}
|
||||
});
|
||||
const fixture = TestBed.createComponent(type);
|
||||
|
||||
fixture.detectChanges();
|
||||
return fixture as ComponentFixture<T>;
|
||||
}
|
||||
|
||||
describe('Dynamic Dynamic Scrollable Dropdown component', () => {
|
||||
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
let html;
|
||||
|
||||
// async beforeEach
|
||||
beforeEach(async(() => {
|
||||
const authorityServiceStub = new AuthorityServiceStub();
|
||||
const formBuilderServiceStub = new FormBuilderServiceStub();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
DynamicFormsCoreModule,
|
||||
DynamicFormsNGBootstrapUIModule,
|
||||
FormsModule,
|
||||
InfiniteScrollModule,
|
||||
ReactiveFormsModule,
|
||||
NgbModule.forRoot(),
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [
|
||||
DsDynamicScrollableDropdownComponent,
|
||||
TestComponent,
|
||||
], // declare the test component
|
||||
providers: [
|
||||
ChangeDetectorRef,
|
||||
DsDynamicScrollableDropdownComponent,
|
||||
{provide: AuthorityService, useValue: authorityServiceStub},
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
html = `
|
||||
<ds-dynamic-scrollable-dropdown [bindId]="bindId"
|
||||
[group]="group"
|
||||
[model]="model"
|
||||
[showErrorMessages]="showErrorMessages"
|
||||
(blur)="onBlur($event)"
|
||||
(change)="onValueChange($event)"
|
||||
(focus)="onFocus($event)"></ds-dynamic-scrollable-dropdown>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should create DsDynamicScrollableDropdownComponent', inject([DsDynamicScrollableDropdownComponent], (app: DsDynamicScrollableDropdownComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
group: FormGroup = new FormGroup({
|
||||
lookup: new FormControl(),
|
||||
});
|
||||
|
||||
inputDropdownModelConfig = {
|
||||
authorityOptions: {
|
||||
closed: false,
|
||||
metadata: 'lookup',
|
||||
name: 'common_iso_languages',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
} as AuthorityOptions,
|
||||
disabled: false,
|
||||
errorMessages: {required: 'Required field.'},
|
||||
id: 'dropdown',
|
||||
label: 'Language',
|
||||
maxOptions: 10,
|
||||
name: 'dropdown',
|
||||
placeholder: 'Language',
|
||||
readOnly: false,
|
||||
required: false,
|
||||
repeatable: false,
|
||||
value: undefined
|
||||
};
|
||||
|
||||
model = new DynamicScrollableDropdownModel(this.inputDropdownModelConfig);
|
||||
|
||||
showErrorMessages = false;
|
||||
|
||||
}
|
@@ -0,0 +1,117 @@
|
||||
// Load the implementations that should be tested
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { async, ComponentFixture, inject, TestBed, } from '@angular/core/testing';
|
||||
|
||||
import { AuthorityOptions } from '../../../../../../core/integration/models/authority-options.model';
|
||||
import { DynamicFormsCoreModule } from '@ng-dynamic-forms/core';
|
||||
import { DynamicFormsNGBootstrapUIModule } from '@ng-dynamic-forms/ui-ng-bootstrap';
|
||||
import { AuthorityService } from '../../../../../../core/integration/authority.service';
|
||||
import { AuthorityServiceStub } from '../../../../../testing/authority-service-stub';
|
||||
import { FormBuilderServiceStub } from '../../../../../testing/form-builder-service-stub';
|
||||
import { DsDynamicTagComponent } from './dynamic-tag.component';
|
||||
import { DynamicTagModel } from './dynamic-tag.model';
|
||||
import { GlobalConfig } from '../../../../../../../config/global-config.interface';
|
||||
import { GLOBAL_CONFIG } from '../../../../../../../config';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
function createTestComponent<T>(html: string, type: { new(...args: any[]): T }): ComponentFixture<T> {
|
||||
TestBed.overrideComponent(type, {
|
||||
set: {template: html}
|
||||
});
|
||||
const fixture = TestBed.createComponent(type);
|
||||
|
||||
fixture.detectChanges();
|
||||
return fixture as ComponentFixture<T>;
|
||||
}
|
||||
|
||||
describe('Dynamic Dynamic Tag component', () => {
|
||||
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
let html;
|
||||
|
||||
// async beforeEach
|
||||
beforeEach(async(() => {
|
||||
const authorityServiceStub = new AuthorityServiceStub();
|
||||
const formBuilderServiceStub = new FormBuilderServiceStub();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
DynamicFormsCoreModule,
|
||||
DynamicFormsNGBootstrapUIModule,
|
||||
FormsModule,
|
||||
NgbModule.forRoot(),
|
||||
ReactiveFormsModule,
|
||||
],
|
||||
declarations: [
|
||||
DsDynamicTagComponent,
|
||||
TestComponent,
|
||||
], // declare the test component
|
||||
providers: [
|
||||
ChangeDetectorRef,
|
||||
DsDynamicTagComponent,
|
||||
{provide: AuthorityService, useValue: authorityServiceStub},
|
||||
{provide: GLOBAL_CONFIG, useValue: {} as GlobalConfig},
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
html = `
|
||||
<ds-dynamic-tag [bindId]="bindId"
|
||||
[group]="group"
|
||||
[model]="model"
|
||||
[showErrorMessages]="showErrorMessages"
|
||||
(blur)="onBlur($event)"
|
||||
(change)="onValueChange($event)"
|
||||
(focus)="onFocus($event)"></ds-dynamic-tag>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should create DsDynamicTagComponent', inject([DsDynamicTagComponent], (app: DsDynamicTagComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
group: FormGroup = new FormGroup({
|
||||
lookup: new FormControl(),
|
||||
});
|
||||
|
||||
inputTagModelConfig = {
|
||||
authorityOptions: {
|
||||
closed: false,
|
||||
metadata: 'tag',
|
||||
name: 'common_iso_languages',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
} as AuthorityOptions,
|
||||
disabled: false,
|
||||
id: 'tag',
|
||||
label: 'Keywords',
|
||||
minChars: 3,
|
||||
name: 'tag',
|
||||
placeholder: 'Keywords',
|
||||
readOnly: false,
|
||||
required: false,
|
||||
repeatable: false
|
||||
};
|
||||
|
||||
model = new DynamicTagModel(this.inputTagModelConfig);
|
||||
|
||||
showErrorMessages = false;
|
||||
|
||||
}
|
@@ -1,143 +0,0 @@
|
||||
// import { AUTOCOMPLETE_OFF, DYNAMIC_FORM_CONTROL_INPUT_TYPE_TEXT } from '@ng-dynamic-forms/core';
|
||||
// import { Observable } from 'rxjs/Observable';
|
||||
//
|
||||
// import {
|
||||
// DYNAMIC_FORM_CONTROL_TYPE_TYPEAHEAD, DynamicTypeaheadModel,
|
||||
// DynamicTypeaheadResponseModel
|
||||
// } from './dynamic-tag.model';
|
||||
// import { PageInfo } from '../../../../../../core/shared/page-info.model';
|
||||
//
|
||||
// describe('DynamicTypeaheadModel test suite', () => {
|
||||
//
|
||||
// let model: any;
|
||||
// const search = (text: string): Observable<DynamicTypeaheadResponseModel> =>
|
||||
// Observable.of({
|
||||
// list: ['One', 'Two', 'Three'],
|
||||
// pageInfo: new PageInfo()
|
||||
// });
|
||||
// const config = {
|
||||
// id: 'input',
|
||||
// minChars: 3,
|
||||
// search: search
|
||||
// };
|
||||
//
|
||||
// beforeEach(() => model = new DynamicTypeaheadModel(config));
|
||||
//
|
||||
// it('tests if correct default type property is set', () => {
|
||||
//
|
||||
// expect(model.type).toEqual(DYNAMIC_FORM_CONTROL_TYPE_TYPEAHEAD);
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default input type property is set', () => {
|
||||
//
|
||||
// expect(model.inputType).toEqual(DYNAMIC_FORM_CONTROL_INPUT_TYPE_TEXT);
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default autoComplete property is set', () => {
|
||||
//
|
||||
// expect(model.autoComplete).toEqual(AUTOCOMPLETE_OFF);
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default autoFocus property is set', () => {
|
||||
//
|
||||
// expect(model.autoFocus).toBe(false);
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default cls properties aree set', () => {
|
||||
//
|
||||
// expect(model.cls).toBeDefined();
|
||||
// expect(model.cls.element.container).toEqual('');
|
||||
// expect(model.cls.element.control).toEqual('');
|
||||
// expect(model.cls.element.errors).toEqual('');
|
||||
// expect(model.cls.element.label).toEqual('');
|
||||
// expect(model.cls.grid.container).toEqual('');
|
||||
// expect(model.cls.grid.control).toEqual('');
|
||||
// expect(model.cls.grid.errors).toEqual('');
|
||||
// expect(model.cls.grid.label).toEqual('');
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default hint property is set', () => {
|
||||
//
|
||||
// expect(model.hint).toBeNull();
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default label property is set', () => {
|
||||
//
|
||||
// expect(model.label).toBeNull();
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default max property is set', () => {
|
||||
//
|
||||
// expect(model.max).toBeNull();
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default maxLength property is set', () => {
|
||||
//
|
||||
// expect(model.maxLength).toBeNull();
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default minLength property is set', () => {
|
||||
//
|
||||
// expect(model.minLength).toBeNull();
|
||||
// });
|
||||
//
|
||||
// it('tests if correct minChars property is set', () => {
|
||||
//
|
||||
// expect(model.minChars).toEqual(3);
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default min property is set', () => {
|
||||
//
|
||||
// expect(model.min).toBeNull();
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default placeholder property is set', () => {
|
||||
//
|
||||
// expect(model.placeholder).toEqual('');
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default readonly property is set', () => {
|
||||
//
|
||||
// expect(model.readOnly).toBe(false);
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default required property is set', () => {
|
||||
//
|
||||
// expect(model.required).toBe(false);
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default spellcheck property is set', () => {
|
||||
//
|
||||
// expect(model.spellCheck).toBe(false);
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default step property is set', () => {
|
||||
//
|
||||
// expect(model.step).toBeNull();
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default prefix property is set', () => {
|
||||
//
|
||||
// expect(model.prefix).toBeNull();
|
||||
// });
|
||||
//
|
||||
// it('tests if correct default suffix property is set', () => {
|
||||
//
|
||||
// expect(model.suffix).toBeNull();
|
||||
// });
|
||||
//
|
||||
// it('tests if correct search function is set', () => {
|
||||
//
|
||||
// expect(model.search).toBe(search);
|
||||
// });
|
||||
//
|
||||
// it('should serialize correctly', () => {
|
||||
//
|
||||
// const json = JSON.parse(JSON.stringify(model));
|
||||
//
|
||||
// expect(json.id).toEqual(model.id);
|
||||
// expect(json.disabled).toEqual(model.disabled);
|
||||
// expect(json.value).toBe(model.value);
|
||||
// expect(json.type).toEqual(DYNAMIC_FORM_CONTROL_TYPE_TYPEAHEAD);
|
||||
// });
|
||||
// });
|
@@ -0,0 +1,118 @@
|
||||
// Load the implementations that should be tested
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { async, ComponentFixture, inject, TestBed, } from '@angular/core/testing';
|
||||
|
||||
import { AuthorityOptions } from '../../../../../../core/integration/models/authority-options.model';
|
||||
import { DynamicFormsCoreModule } from '@ng-dynamic-forms/core';
|
||||
import { DynamicFormsNGBootstrapUIModule } from '@ng-dynamic-forms/ui-ng-bootstrap';
|
||||
import { AuthorityService } from '../../../../../../core/integration/authority.service';
|
||||
import { AuthorityServiceStub } from '../../../../../testing/authority-service-stub';
|
||||
import { FormBuilderServiceStub } from '../../../../../testing/form-builder-service-stub';
|
||||
import { GlobalConfig } from '../../../../../../../config/global-config.interface';
|
||||
import { GLOBAL_CONFIG } from '../../../../../../../config';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { DsDynamicTypeaheadComponent } from './dynamic-typeahead.component';
|
||||
import { DynamicTypeaheadModel } from './dynamic-typeahead.model';
|
||||
|
||||
function createTestComponent<T>(html: string, type: { new(...args: any[]): T }): ComponentFixture<T> {
|
||||
TestBed.overrideComponent(type, {
|
||||
set: {template: html}
|
||||
});
|
||||
const fixture = TestBed.createComponent(type);
|
||||
|
||||
fixture.detectChanges();
|
||||
return fixture as ComponentFixture<T>;
|
||||
}
|
||||
|
||||
describe('Dynamic Dynamic Typeahead component', () => {
|
||||
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
let html;
|
||||
|
||||
// async beforeEach
|
||||
beforeEach(async(() => {
|
||||
const authorityServiceStub = new AuthorityServiceStub();
|
||||
const formBuilderServiceStub = new FormBuilderServiceStub();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
DynamicFormsCoreModule,
|
||||
DynamicFormsNGBootstrapUIModule,
|
||||
FormsModule,
|
||||
NgbModule.forRoot(),
|
||||
ReactiveFormsModule,
|
||||
],
|
||||
declarations: [
|
||||
DsDynamicTypeaheadComponent,
|
||||
TestComponent,
|
||||
], // declare the test component
|
||||
providers: [
|
||||
ChangeDetectorRef,
|
||||
DsDynamicTypeaheadComponent,
|
||||
{provide: AuthorityService, useValue: authorityServiceStub},
|
||||
{provide: GLOBAL_CONFIG, useValue: {} as GlobalConfig},
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
html = `
|
||||
<ds-dynamic-typeahead [bindId]="bindId"
|
||||
[group]="group"
|
||||
[model]="model"
|
||||
[showErrorMessages]="showErrorMessages"
|
||||
(blur)="onBlur($event)"
|
||||
(change)="onValueChange($event)"
|
||||
(focus)="onFocus($event)"></ds-dynamic-typeahead>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should create DsDynamicTypeaheadComponent', inject([DsDynamicTypeaheadComponent], (app: DsDynamicTypeaheadComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
group: FormGroup = new FormGroup({
|
||||
typeahead: new FormControl(),
|
||||
});
|
||||
|
||||
inputTypeaheadModelConfig = {
|
||||
authorityOptions: {
|
||||
closed: false,
|
||||
metadata: 'typeahead',
|
||||
name: 'EVENTAuthority',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
} as AuthorityOptions,
|
||||
disabled: false,
|
||||
id: 'typeahead',
|
||||
label: 'Conference',
|
||||
minChars: 3,
|
||||
name: 'typeahead',
|
||||
placeholder: 'Conference',
|
||||
readOnly: false,
|
||||
required: false,
|
||||
repeatable: false,
|
||||
value: undefined
|
||||
}
|
||||
|
||||
model = new DynamicTypeaheadModel(this.inputTypeaheadModelConfig);
|
||||
|
||||
showErrorMessages = false;
|
||||
|
||||
}
|
12
src/app/shared/testing/authority-service-stub.ts
Normal file
12
src/app/shared/testing/authority-service-stub.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { IntegrationSearchOptions } from '../../core/integration/models/integration-options.model';
|
||||
import { IntegrationData } from '../../core/integration/integration-data';
|
||||
import { PageInfo } from '../../core/shared/page-info.model';
|
||||
|
||||
export class AuthorityServiceStub {
|
||||
|
||||
getEntriesByName(options: IntegrationSearchOptions) {
|
||||
const payload = [{id: 1, display: 'one', value: 1} as any, {id: 2, display: 'two', value: 2} as any];
|
||||
return Observable.of(new IntegrationData(new PageInfo(), payload));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user