mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 03:23:07 +00:00
added create-from functionality
This commit is contained in:
86
src/app/process-page/form/process-form.component.spec.ts
Normal file
86
src/app/process-page/form/process-form.component.spec.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ProcessFormComponent } from './process-form.component';
|
||||
import { ScriptDataService } from '../../core/data/processes/script-data.service';
|
||||
import { ScriptParameter } from '../scripts/script-parameter.model';
|
||||
import { Script } from '../scripts/script.model';
|
||||
import { ProcessParameter } from '../processes/process-parameter.model';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||
import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock';
|
||||
import { RequestService } from '../../core/data/request.service';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
describe('NewProcessComponent', () => {
|
||||
let component: ProcessFormComponent;
|
||||
let fixture: ComponentFixture<ProcessFormComponent>;
|
||||
let scriptService;
|
||||
let parameterValues;
|
||||
let script;
|
||||
|
||||
function init() {
|
||||
const param1 = new ScriptParameter();
|
||||
const param2 = new ScriptParameter();
|
||||
script = Object.assign(new Script(), { parameters: [param1, param2] });
|
||||
parameterValues = [
|
||||
Object.assign(new ProcessParameter(), { name: '-a', value: 'bla' }),
|
||||
Object.assign(new ProcessParameter(), { name: '-b', value: '123' }),
|
||||
Object.assign(new ProcessParameter(), { name: '-c', value: 'value' }),
|
||||
];
|
||||
scriptService = jasmine.createSpyObj(
|
||||
'scriptService',
|
||||
{
|
||||
invoke: observableOf({
|
||||
response:
|
||||
{
|
||||
isSuccessful: true
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
beforeEach(async(() => {
|
||||
init();
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
FormsModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useClass: TranslateLoaderMock
|
||||
}
|
||||
})],
|
||||
declarations: [ProcessFormComponent],
|
||||
providers: [
|
||||
{ provide: ScriptDataService, useValue: scriptService },
|
||||
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
||||
{ provide: RequestService, useValue: {} },
|
||||
{ provide: Router, useValue: {} },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ProcessFormComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.parameters = parameterValues;
|
||||
component.selectedScript = script;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should call invoke on the scriptService on submit', () => {
|
||||
component.submitForm({ invalid: false } as any);
|
||||
expect(scriptService.invoke).toHaveBeenCalled();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user