Skip to content

Instantly share code, notes, and snippets.

@jlsherrill
Created September 6, 2013 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlsherrill/6469685 to your computer and use it in GitHub Desktop.
Save jlsherrill/6469685 to your computer and use it in GitHub Desktop.
/**
* Copyright 2013 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public
* License as published by the Free Software Foundation; either version
* 2 of the License (GPLv2) or (at your option) any later version.
* There is NO WARRANTY for this software, express or implied,
* including the implied warranties of MERCHANTABILITY,
* NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
* have received a copy of GPLv2 along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
**/
describe('Controller: SystemPackagesController', function() {
var $scope, Nutupane, SystemTask, SystemPackage, mockSystem, mockTask, i18nFilter, System;
beforeEach(module('Bastion.systems', 'Bastion.test-mocks'));
beforeEach(function() {
Nutupane = function() {
this.table = {
showColumns: function() {}
};
this.get = function() {};
};
System = {
tasks: function() {return []}
};
SystemTask = {
get: function(){},
poll: function(task, returnFunction){}
};
SystemPackage = {
get: function(success){return []},
remove: function(success){return mockTask},
install: function(success){return mockTask},
update: function(success){return mockTask},
updateAll: function(success){return mockTask}
};
mockSystem = {
id: 5
};
mockTask = {
id: 7
};
i18nFilter = function(){};
});
beforeEach(inject(function($controller, $rootScope) {
$scope = $rootScope.$new();
$scope.system = mockSystem;
$controller('SystemPackagesController', {$scope: $scope,
SystemPackage: SystemPackage,
SystemTask: SystemTask,
i18nFilter:i18nFilter,
Nutupane: Nutupane});
}));
it("Sets a table.", function() {
expect($scope.currentPackagesTable).toBeTruthy();
});
it("provides a way to open the event details panel.", function() {
spyOn($scope, "transitionTo");
$scope.currentPackagesTable.openEventInfo({ id: 2 });
expect($scope.transitionTo).toHaveBeenCalledWith('systems.details.events.details', {eventId: 2});
});
it("defaults to package install", function(){
expect($scope.packageAction.actionType).toBe('packageInstall');
});
it("properly recognizes a failed package remove task", function(){
expect($scope.currentPackagesTable.taskFailed({failed: true})).toBe(true);
expect($scope.currentPackagesTable.taskFailed({failed: false})).toBe(false);
expect($scope.currentPackagesTable.taskFailed({failed: false, affected_units: 0})).toBe(true);
expect($scope.currentPackagesTable.taskFailed({failed: false, affected_units: 1})).toBe(false);
});
it("Performs a package update", function(){
$scope.packageAction.actionType = "packageUpdate";
$scope.packageAction.term = "foo";
$scope.performPackageAction();
expect(SystemPackage).toHaveBeenCalledWith('update', {uuid: mockSystem.uuid, packages: ["foo"]})
});
it("", function(){
});
it("", function(){
});
it("", function(){
});
it("provides a way to upgrade all packages", function() {
spyOn(SystemPackage, "updateAll");
console.log($scope.updateAll);
$scope.updateAll().andCallThrough();
expect(SystemPackage).toHaveBeenCalledWith('updateAll', {uuid: mockSystem.uuid});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment