mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 21:07:39 -02:30
more job results controller tests
This commit is contained in:
committed by
jaredevantabor
parent
4bcbea6c45
commit
e863262e4d
@@ -178,6 +178,7 @@ export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count'
|
|||||||
// get the name in the same format as the data
|
// get the name in the same format as the data
|
||||||
// coming over the websocket
|
// coming over the websocket
|
||||||
event.event_name = event.event;
|
event.event_name = event.event;
|
||||||
|
delete event.event;
|
||||||
processEvent(event);
|
processEvent(event);
|
||||||
});
|
});
|
||||||
if (events.next) {
|
if (events.next) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ describe('Controller: jobResultsController', () => {
|
|||||||
// Setup
|
// Setup
|
||||||
let jobResultsController;
|
let jobResultsController;
|
||||||
|
|
||||||
let jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, eventDefer, populateResolve, $rScope;
|
let jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, eventResolve, populateResolve, $rScope, q;
|
||||||
|
|
||||||
jobData = {
|
jobData = {
|
||||||
related: {}
|
related: {}
|
||||||
@@ -20,7 +20,9 @@ describe('Controller: jobResultsController', () => {
|
|||||||
val: {},
|
val: {},
|
||||||
countFinished: false
|
countFinished: false
|
||||||
};
|
};
|
||||||
eventDefer = {};
|
eventResolve = {
|
||||||
|
results: []
|
||||||
|
};
|
||||||
populateResolve = {};
|
populateResolve = {};
|
||||||
|
|
||||||
let provideVals = () => {
|
let provideVals = () => {
|
||||||
@@ -53,9 +55,22 @@ describe('Controller: jobResultsController', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let injectVals = () => {
|
let injectVals = () => {
|
||||||
angular.mock.inject((_jobData_, _jobDataOptions_, _jobLabels_, _jobFinished_, _count_, _ParseTypeChange_, _ParseVariableString_, _jobResultsService_, _eventQueue_, _$compile_, $rootScope, $controller, $q) => {
|
angular.mock.inject((_jobData_, _jobDataOptions_, _jobLabels_, _jobFinished_, _count_, _ParseTypeChange_, _ParseVariableString_, _jobResultsService_, _eventQueue_, _$compile_, $rootScope, $controller, $q, $httpBackend) => {
|
||||||
|
// when you call $scope.$apply() (which you need to do to
|
||||||
|
// to get inside of .then blocks to test), something is
|
||||||
|
// causing a request for all static files.
|
||||||
|
//
|
||||||
|
// this is a hack to just pass those requests through
|
||||||
|
//
|
||||||
|
// from googling this is probably due to angular-router
|
||||||
|
// weirdness
|
||||||
|
$httpBackend.when("GET", (url) => (url
|
||||||
|
.indexOf("/static/") !== -1))
|
||||||
|
.respond('');
|
||||||
|
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$rScope = $rootScope;
|
$rScope = $rootScope;
|
||||||
|
q = $q;
|
||||||
jobData = _jobData_;
|
jobData = _jobData_;
|
||||||
jobDataOptions = _jobDataOptions_;
|
jobDataOptions = _jobDataOptions_;
|
||||||
jobLabels = _jobLabels_;
|
jobLabels = _jobLabels_;
|
||||||
@@ -65,14 +80,12 @@ describe('Controller: jobResultsController', () => {
|
|||||||
ParseVariableString = _ParseVariableString_;
|
ParseVariableString = _ParseVariableString_;
|
||||||
ParseVariableString.and.returnValue(jobData.extra_vars);
|
ParseVariableString.and.returnValue(jobData.extra_vars);
|
||||||
jobResultsService = _jobResultsService_;
|
jobResultsService = _jobResultsService_;
|
||||||
|
|
||||||
// TODO: neither one of these and.returnValue's work as
|
|
||||||
// expected, gotta figure out how to make these work
|
|
||||||
eventDefer = $q.defer();
|
|
||||||
jobResultsService.getEvents.and.returnValue($q.when(eventDefer));
|
|
||||||
|
|
||||||
eventQueue = _eventQueue_;
|
eventQueue = _eventQueue_;
|
||||||
eventQueue.populate.and.returnValue($q.when(populateResolve));
|
|
||||||
|
jobResultsService.getEvents.and
|
||||||
|
.returnValue($q.when(eventResolve));
|
||||||
|
eventQueue.populate.and
|
||||||
|
.returnValue($q.when(populateResolve));
|
||||||
|
|
||||||
$compile = _$compile_;
|
$compile = _$compile_;
|
||||||
|
|
||||||
@@ -347,9 +360,130 @@ describe('Controller: jobResultsController', () => {
|
|||||||
$rScope.$broadcast('ws-jobs', eventPayload);
|
$rScope.$broadcast('ws-jobs', eventPayload);
|
||||||
expect($scope.job.status).toBe(eventPayload.status);
|
expect($scope.job.status).toBe(eventPayload.status);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: test getEvents function
|
describe('getEvents and populate stuff', () => {
|
||||||
|
describe('getEvents', () => {
|
||||||
|
let event1 = {
|
||||||
|
event: 'foo'
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: test processEvent function
|
let event2 = {
|
||||||
|
event_name: 'bar'
|
||||||
|
};
|
||||||
|
|
||||||
|
let event1Processed = {
|
||||||
|
event_name: 'foo'
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
eventResolve = {
|
||||||
|
results: [
|
||||||
|
event1,
|
||||||
|
event2
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
bootstrapTest();
|
||||||
|
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should change the event name to event_name', () => {
|
||||||
|
expect(eventQueue.populate)
|
||||||
|
.toHaveBeenCalledWith(event1Processed);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pass through the event with event_name', () => {
|
||||||
|
expect(eventQueue.populate)
|
||||||
|
.toHaveBeenCalledWith(event2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have called populate twice', () => {
|
||||||
|
expect(eventQueue.populate.calls.count()).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: can't figure out how to a test of events.next...
|
||||||
|
// if you set events.next to true it causes the tests to
|
||||||
|
// stop running
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('populate - start time', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jobData.start = "";
|
||||||
|
|
||||||
|
populateResolve = {
|
||||||
|
startTime: 'foo',
|
||||||
|
changes: ['startTime']
|
||||||
|
};
|
||||||
|
|
||||||
|
bootstrapTest();
|
||||||
|
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets start time when passed as a change', () => {
|
||||||
|
expect($scope.job.start).toBe('foo');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('populate - start time already set', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jobData.start = "bar";
|
||||||
|
|
||||||
|
populateResolve = {
|
||||||
|
startTime: 'foo',
|
||||||
|
changes: ['startTime']
|
||||||
|
};
|
||||||
|
|
||||||
|
bootstrapTest();
|
||||||
|
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not set start time because already set', () => {
|
||||||
|
expect($scope.job.start).toBe('bar');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('populate - count already received', () => {
|
||||||
|
let receiveCount = {
|
||||||
|
ok: 2,
|
||||||
|
skipped: 2,
|
||||||
|
unreachable: 2,
|
||||||
|
failures: 2,
|
||||||
|
changed: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
let alreadyCount = {
|
||||||
|
ok: 3,
|
||||||
|
skipped: 3,
|
||||||
|
unreachable: 3,
|
||||||
|
failures: 3,
|
||||||
|
changed: 3
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
count.countFinished = true;
|
||||||
|
count.val = alreadyCount;
|
||||||
|
|
||||||
|
populateResolve = {
|
||||||
|
count: receiveCount,
|
||||||
|
changes: ['count']
|
||||||
|
};
|
||||||
|
|
||||||
|
bootstrapTest();
|
||||||
|
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('count does not change', () => {
|
||||||
|
expect($scope.count).toBe(alreadyCount);
|
||||||
|
expect($scope.hostCount).toBe(15);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: playCount, taskCount, finishedTime, countFinished, and
|
||||||
|
// stdout change tests
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user