forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process-detail.component.spec.ts
210 lines (196 loc) · 7.14 KB
/
process-detail.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import { HttpClient } from '@angular/common/http';
import { AuthService } from '../../core/auth/auth.service';
import { BitstreamDataService } from '../../core/data/bitstream-data.service';
import { AuthServiceMock } from '../../shared/mocks/auth.service.mock';
import { ProcessDetailComponent } from './process-detail.component';
import {
async,
ComponentFixture,
discardPeriodicTasks,
fakeAsync,
flush,
flushMicrotasks,
TestBed,
tick
} from '@angular/core/testing';
import { VarDirective } from '../../shared/utils/var.directive';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ProcessDetailFieldComponent } from './process-detail-field/process-detail-field.component';
import { Process } from '../processes/process.model';
import { ActivatedRoute } from '@angular/router';
import { of as observableOf } from 'rxjs';
import { By } from '@angular/platform-browser';
import { FileSizePipe } from '../../shared/utils/file-size-pipe';
import { Bitstream } from '../../core/shared/bitstream.model';
import { ProcessDataService } from '../../core/data/processes/process-data.service';
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { createPaginatedList } from '../../shared/testing/utils.test';
describe('ProcessDetailComponent', () => {
let component: ProcessDetailComponent;
let fixture: ComponentFixture<ProcessDetailComponent>;
let processService: ProcessDataService;
let nameService: DSONameService;
let bitstreamDataService: BitstreamDataService;
let httpClient: HttpClient;
let process: Process;
let fileName: string;
let files: Bitstream[];
let processOutput;
function init() {
processOutput = 'Process Started'
process = Object.assign(new Process(), {
processId: 1,
scriptName: 'script-name',
processStatus: 'COMPLETED',
parameters: [
{
name: '-f',
value: 'file.xml'
},
{
name: '-i',
value: 'identifier'
}
],
_links: {
self: {
href: 'https://rest.api/processes/1'
},
output: {
href: 'https://rest.api/processes/1/output'
}
}
});
fileName = 'fake-file-name';
files = [
Object.assign(new Bitstream(), {
sizeBytes: 10000,
metadata: {
'dc.title': [
{
value: fileName,
language: null
}
]
},
_links: {
content: { href: 'file-selflink' }
}
})
];
const logBitstream = Object.assign(new Bitstream(), {
id: 'output.log',
_links: {
content: { href: 'log-selflink' }
}
});
processService = jasmine.createSpyObj('processService', {
getFiles: createSuccessfulRemoteDataObject$(createPaginatedList(files))
});
bitstreamDataService = jasmine.createSpyObj('bitstreamDataService', {
findByHref: createSuccessfulRemoteDataObject$(logBitstream)
});
nameService = jasmine.createSpyObj('nameService', {
getName: fileName
});
httpClient = jasmine.createSpyObj('httpClient', {
get: observableOf(processOutput)
});
}
beforeEach(async(() => {
init();
TestBed.configureTestingModule({
declarations: [ProcessDetailComponent, ProcessDetailFieldComponent, VarDirective, FileSizePipe],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
providers: [
{
provide: ActivatedRoute,
useValue: { data: observableOf({ process: createSuccessfulRemoteDataObject(process) }) }
},
{ provide: ProcessDataService, useValue: processService },
{ provide: BitstreamDataService, useValue: bitstreamDataService },
{ provide: DSONameService, useValue: nameService },
{ provide: AuthService, useValue: new AuthServiceMock() },
{ provide: HttpClient, useValue: httpClient },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ProcessDetailComponent);
component = fixture.componentInstance;
});
afterEach(fakeAsync(() => {
TestBed.resetTestingModule();
fixture.destroy();
flush();
flushMicrotasks();
discardPeriodicTasks();
component = null;
}));
it('should display the script\'s name', () => {
fixture.detectChanges();
const name = fixture.debugElement.query(By.css('#process-name')).nativeElement;
expect(name.textContent).toContain(process.scriptName);
});
it('should display the process\'s parameters', () => {
fixture.detectChanges();
const args = fixture.debugElement.query(By.css('#process-arguments')).nativeElement;
process.parameters.forEach((param) => {
expect(args.textContent).toContain(`${param.name} ${param.value}`)
});
});
it('should display the process\'s output files', () => {
fixture.detectChanges();
const processFiles = fixture.debugElement.query(By.css('#process-files')).nativeElement;
expect(processFiles.textContent).toContain(fileName);
});
describe('if press show output logs', () => {
beforeEach(fakeAsync(() => {
spyOn(component, 'showProcessOutputLogs').and.callThrough();
fixture.detectChanges();
const showOutputButton = fixture.debugElement.query(By.css('#showOutputButton'));
showOutputButton.triggerEventHandler('click', {
preventDefault: () => {/**/
}
});
tick();
}));
it('should trigger showProcessOutputLogs', () => {
expect(component.showProcessOutputLogs).toHaveBeenCalled();
});
it('should display the process\'s output logs', () => {
fixture.detectChanges();
const outputProcess = fixture.debugElement.query(By.css('#process-output pre'));
expect(outputProcess.nativeElement.textContent).toContain(processOutput);
});
});
describe('if press show output logs and process has no output logs', () => {
beforeEach(fakeAsync(() => {
jasmine.getEnv().allowRespy(true);
spyOn(httpClient, 'get').and.returnValue(observableOf(null));
fixture = TestBed.createComponent(ProcessDetailComponent);
component = fixture.componentInstance;
spyOn(component, 'showProcessOutputLogs').and.callThrough();
fixture.detectChanges();
const showOutputButton = fixture.debugElement.query(By.css('#showOutputButton'));
showOutputButton.triggerEventHandler('click', {
preventDefault: () => {/**/
}
});
tick();
fixture.detectChanges();
}));
it('should not display the process\'s output logs', () => {
const outputProcess = fixture.debugElement.query(By.css('#process-output pre'));
expect(outputProcess).toBeNull();
});
it('should display message saying there are no output logs', () => {
const noOutputProcess = fixture.debugElement.query(By.css('#no-output-logs-message')).nativeElement;
expect(noOutputProcess).toBeDefined();
});
});
});