mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 03:47:36 -02:30
more parse stdout tests
This commit is contained in:
committed by
jaredevantabor
parent
fbefcf59ce
commit
8259bda68c
@@ -60,7 +60,7 @@ export default ['$log', function($log){
|
|||||||
//end span
|
//end span
|
||||||
line = line.replace(/\[0m/g, '');
|
line = line.replace(/\[0m/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
},
|
},
|
||||||
// adds anchor tags and tooltips to host status lines
|
// adds anchor tags and tooltips to host status lines
|
||||||
@@ -170,19 +170,22 @@ export default ['$log', function($log){
|
|||||||
return emptySpan;
|
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
|
// public function that provides the parsed stdout line, given a
|
||||||
// job_event
|
// job_event
|
||||||
parseStdout: function(event){
|
parseStdout: function(event){
|
||||||
// this utilizes the start/end lines and stdout blob
|
// this utilizes the start/end lines and stdout blob
|
||||||
// to create an array in the format:
|
// to create an array in the format:
|
||||||
// [
|
// [
|
||||||
// [lineNum: lineText],
|
// [lineNum, lineText],
|
||||||
// [lineNum: lineText],
|
// [lineNum, lineText],
|
||||||
// ]
|
// ]
|
||||||
var lineArr = _
|
var lineArr = this.getLineArr(event);
|
||||||
.zip(_.range(event.start_line + 1,
|
|
||||||
event.end_line + 1),
|
|
||||||
event.stdout.replace("\t", " ").split("\r\n").slice(0, -1));
|
|
||||||
|
|
||||||
// this takes each `[lineNum: lineText]` element and calls the
|
// this takes each `[lineNum: lineText]` element and calls the
|
||||||
// relevant helper functions in this service to build the
|
// relevant helper functions in this service to build the
|
||||||
|
|||||||
@@ -1,33 +1,118 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
describe('', () => {
|
describe('parseStdoutService', () => {
|
||||||
let parseStdoutService,
|
let parseStdoutService,
|
||||||
$log;
|
log;
|
||||||
|
|
||||||
beforeEach(angular.mock.module('Tower'));
|
beforeEach(angular.mock.module('Tower'));
|
||||||
|
|
||||||
beforeEach(angular.mock.module('jobResults', function($provide){
|
beforeEach(angular.mock.module('jobResults',($provide) => {
|
||||||
// $log = jasmine.createSpyObj('$log', [
|
log = jasmine.createSpyObj('$log', [
|
||||||
// 'error'
|
'error'
|
||||||
// ]);
|
]);
|
||||||
// $provide.value('$log', $log);
|
|
||||||
|
$provide.value('$log', log);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(angular.mock.inject((_$log_, _parseStdoutService_) => {
|
beforeEach(angular.mock.inject((_$log_, _parseStdoutService_) => {
|
||||||
parseStdoutService = _parseStdoutService_;
|
parseStdoutService = _parseStdoutService_;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('parseStdout()', () => {
|
describe('getCollapseIcon()', () => {
|
||||||
it('returns the line number and text from an event object', () => {
|
let emptySpan = `
|
||||||
var service = parseStdoutService,
|
<span class="JobResultsStdOut-lineExpander"></span>`;
|
||||||
span = '<span class="JobResultsStdOut-lineExpander"></span>`',
|
|
||||||
event = {
|
it('returns empty expander for non-header event', () => {
|
||||||
|
let nonHeaderEvent = {
|
||||||
|
event_name: 'not_header',
|
||||||
start_line: 0,
|
start_line: 0,
|
||||||
end_line: 1,
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user