Skip to content

Commit

Permalink
Fix repo discovery js tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iNecas committed Jan 15, 2014
1 parent 9d53d06 commit b542a49
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ describe('Controller: DiscoveryController', function() {
});


it('should fetch discovery task through org and set details', function() {
/* TODO: For now, we don't support loading the current disovery task
when reloading the page */
xit('should fetch discovery task through org and set details', function() {
expect($scope.discovery.url).toBe(mockTask.parameters.url);
expect($scope.discovery.pending).toBe(mockTask.pending);
expect($scope.discoveryTable.rows[0].url).toBe(mockTask.result[0]);
Expand All @@ -119,16 +121,27 @@ describe('Controller: DiscoveryController', function() {
$scope.discover();

expect(Task.get).not.toHaveBeenCalled();
expect($scope.discoveryTable.rows[0].url).toBe(Organization.mockDiscoveryTask.result[0]);

Task.simulateBulkSearch(Organization.mockDiscoveryTask);

expect($scope.discoveryTable.rows[0].url).toBe(Organization.mockDiscoveryTask.output[0]);
expect($scope.discoveryTable.rows[0].path).toBe('foo');
});

it('discovery should poll if task is pending', function() {
Organization.mockDiscoveryTask.pending = true;
spyOn(Task, 'poll');
$scope.discover();
Organization.mockDiscoveryTask.pending = true
spyOn(Task, 'unregisterSearch');
Task.simulateBulkSearch(Organization.mockDiscoveryTask);
expect(Task.unregisterSearch).not.toHaveBeenCalled();
});

it('discovery should stop polling if task is not pending', function() {
$scope.discover();
expect(Task.poll).toHaveBeenCalled();
Organization.mockDiscoveryTask.pending = false
spyOn(Task, 'unregisterSearch');
Task.simulateBulkSearch(Organization.mockDiscoveryTask);
expect(Task.unregisterSearch).toHaveBeenCalled();
});

});
Expand Down
23 changes: 20 additions & 3 deletions engines/bastion/test/test-mocks.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,28 @@ angular.module('Bastion.test-mocks').factory('MockForm', function() {
angular.module('Bastion.test-mocks').factory('MockTask', ['MockResource',
function(MockResource) {
var myMock = MockResource.$new();
var searchIdGenerator = 0;
myMock.registeredSearches = {};

myMock.poll = function(task, finishedCallBack) {
myMock.get(task, finishedCallBack);
};

myMock.registerSearch = function(searchParams, callback) {
searchIdGenerator += 1;
var searchId = searchIdGenerator;
myMock.registeredSearches[searchId] = callback;
};

myMock.unregisterSearch = function(id) {
delete myMock.registeredSearches[id];
};

myMock.simulateBulkSearch = function (taskData) {
_.each(myMock.registeredSearches, function (callback) {
callback(taskData);
});
};
return myMock;
}
]);
Expand All @@ -151,10 +169,9 @@ angular.module('Bastion.test-mocks').factory('MockOrganization', ['MockResource
var myMock = MockResource.$new();

myMock.mockDiscoveryTask = {
id: 'discovery_task',
pending: false,
parameters: {url: 'http://fake/'},
result: ['http://fake/foo']
input: 'http://fake/',
output: ['http://fake/foo']
};

myMock.cancelRepoDiscover = function(params, success) {
Expand Down

0 comments on commit b542a49

Please sign in to comment.