mirror of
https://github.com/ansible/awx.git
synced 2024-10-30 22:21:13 +03:00
more parse stdout tests
This commit is contained in:
parent
fbefcf59ce
commit
8259bda68c
@ -60,7 +60,7 @@ export default ['$log', function($log){
|
||||
//end span
|
||||
line = line.replace(/\[0m/g, '');
|
||||
}
|
||||
|
||||
|
||||
return line;
|
||||
},
|
||||
// adds anchor tags and tooltips to host status lines
|
||||
@ -170,19 +170,22 @@ export default ['$log', function($log){
|
||||
return emptySpan;
|
||||
}
|
||||
},
|
||||
getLineArr: function(event) {
|
||||
return _
|
||||
.zip(_.range(event.start_line + 1,
|
||||
event.end_line + 1),
|
||||
event.stdout.replace("\t", " ").split("\r\n").slice(0, -1));
|
||||
},
|
||||
// public function that provides the parsed stdout line, given a
|
||||
// job_event
|
||||
parseStdout: function(event){
|
||||
// this utilizes the start/end lines and stdout blob
|
||||
// to create an array in the format:
|
||||
// [
|
||||
// [lineNum: lineText],
|
||||
// [lineNum: lineText],
|
||||
// [lineNum, lineText],
|
||||
// [lineNum, lineText],
|
||||
// ]
|
||||
var lineArr = _
|
||||
.zip(_.range(event.start_line + 1,
|
||||
event.end_line + 1),
|
||||
event.stdout.replace("\t", " ").split("\r\n").slice(0, -1));
|
||||
var lineArr = this.getLineArr(event);
|
||||
|
||||
// this takes each `[lineNum: lineText]` element and calls the
|
||||
// relevant helper functions in this service to build the
|
||||
|
@ -1,33 +1,118 @@
|
||||
'use strict';
|
||||
|
||||
describe('', () => {
|
||||
describe('parseStdoutService', () => {
|
||||
let parseStdoutService,
|
||||
$log;
|
||||
log;
|
||||
|
||||
beforeEach(angular.mock.module('Tower'));
|
||||
|
||||
beforeEach(angular.mock.module('jobResults', function($provide){
|
||||
// $log = jasmine.createSpyObj('$log', [
|
||||
// 'error'
|
||||
// ]);
|
||||
// $provide.value('$log', $log);
|
||||
beforeEach(angular.mock.module('jobResults',($provide) => {
|
||||
log = jasmine.createSpyObj('$log', [
|
||||
'error'
|
||||
]);
|
||||
|
||||
$provide.value('$log', log);
|
||||
}));
|
||||
|
||||
beforeEach(angular.mock.inject((_$log_, _parseStdoutService_) => {
|
||||
parseStdoutService = _parseStdoutService_;
|
||||
}));
|
||||
|
||||
describe('parseStdout()', () => {
|
||||
it('returns the line number and text from an event object', () => {
|
||||
var service = parseStdoutService,
|
||||
span = '<span class="JobResultsStdOut-lineExpander"></span>`',
|
||||
event = {
|
||||
describe('getCollapseIcon()', () => {
|
||||
let emptySpan = `
|
||||
<span class="JobResultsStdOut-lineExpander"></span>`;
|
||||
|
||||
it('returns empty expander for non-header event', () => {
|
||||
let nonHeaderEvent = {
|
||||
event_name: 'not_header',
|
||||
start_line: 0,
|
||||
end_line: 1,
|
||||
stdout:"PLAY [all] *********************************************************************"
|
||||
stdout:"line1"
|
||||
};
|
||||
expect(parseStdoutService.getCollapseIcon(nonHeaderEvent))
|
||||
.toBe(emptySpan);
|
||||
});
|
||||
});
|
||||
|
||||
expect(parseStdoutService.parseStdout(event)).toBe(span);
|
||||
})
|
||||
describe('getLineArr()', () => {
|
||||
it('returns stdout in array format', () => {
|
||||
let mockEvent = {
|
||||
start_line: 12,
|
||||
end_line: 14,
|
||||
stdout: "line1\r\nline2\r\n"
|
||||
};
|
||||
let expectedReturn = [[13, "line1"],[14, "line2"]];
|
||||
|
||||
let returnedEvent = parseStdoutService.getLineArr(mockEvent);
|
||||
|
||||
expect(returnedEvent).toEqual(expectedReturn);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseStdout()', () => {
|
||||
let mockEvent = {"foo": "bar"};
|
||||
|
||||
it('calls functions', function() {
|
||||
spyOn(parseStdoutService, 'getLineArr').and
|
||||
.returnValue([[13, 'line1'], [14, 'line2']]);
|
||||
spyOn(parseStdoutService, 'getLineClasses').and
|
||||
.returnValue("");
|
||||
spyOn(parseStdoutService, 'getCollapseIcon').and
|
||||
.returnValue("");
|
||||
spyOn(parseStdoutService, 'getAnchorTags').and
|
||||
.returnValue("");
|
||||
spyOn(parseStdoutService, 'prettify').and
|
||||
.returnValue("prettified_line");
|
||||
|
||||
parseStdoutService.parseStdout(mockEvent);
|
||||
|
||||
expect(parseStdoutService.getLineArr)
|
||||
.toHaveBeenCalledWith(mockEvent);
|
||||
expect(parseStdoutService.getLineClasses)
|
||||
.toHaveBeenCalledWith(mockEvent, 'line1', 13);
|
||||
expect(parseStdoutService.getCollapseIcon)
|
||||
.toHaveBeenCalledWith(mockEvent, 'line1');
|
||||
expect(parseStdoutService.getAnchorTags)
|
||||
.toHaveBeenCalledWith(mockEvent, "prettified_line");
|
||||
expect(parseStdoutService.prettify)
|
||||
.toHaveBeenCalledWith('line1');
|
||||
|
||||
// get line arr should be called once for the event
|
||||
expect(parseStdoutService.getLineArr.calls.count())
|
||||
.toBe(1);
|
||||
|
||||
// other functions should be called twice (once for each
|
||||
// line)
|
||||
expect(parseStdoutService.getLineClasses.calls.count())
|
||||
.toBe(2);
|
||||
expect(parseStdoutService.getCollapseIcon.calls.count())
|
||||
.toBe(2);
|
||||
expect(parseStdoutService.getAnchorTags.calls.count())
|
||||
.toBe(2);
|
||||
expect(parseStdoutService.prettify.calls.count())
|
||||
.toBe(2);
|
||||
});
|
||||
|
||||
it('returns dom-ified lines', function() {
|
||||
spyOn(parseStdoutService, 'getLineArr').and
|
||||
.returnValue([[13, 'line1']]);
|
||||
spyOn(parseStdoutService, 'getLineClasses').and
|
||||
.returnValue("line_classes");
|
||||
spyOn(parseStdoutService, 'getCollapseIcon').and
|
||||
.returnValue("collapse_icon_dom");
|
||||
spyOn(parseStdoutService, 'getAnchorTags').and
|
||||
.returnValue("anchor_tag_dom");
|
||||
spyOn(parseStdoutService, 'prettify').and
|
||||
.returnValue("prettified_line");
|
||||
|
||||
var returnedString = parseStdoutService.parseStdout(mockEvent);
|
||||
|
||||
var expectedString = `
|
||||
<div class="JobResultsStdOut-aLineOfStdOutline_classes">
|
||||
<div class="JobResultsStdOut-lineNumberColumn">collapse_icon_dom13</div>
|
||||
<div class="JobResultsStdOut-stdoutColumn">anchor_tag_dom</div>
|
||||
</div>`;
|
||||
expect(returnedString).toBe(expectedString);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user