diff options
Diffstat (limited to '3rd_party/static/testapi-ui/assets/lib/angular-confirm-modal/test')
-rw-r--r-- | 3rd_party/static/testapi-ui/assets/lib/angular-confirm-modal/test/karma.conf.js | 81 | ||||
-rw-r--r-- | 3rd_party/static/testapi-ui/assets/lib/angular-confirm-modal/test/unit/confirmSpec.js | 244 |
2 files changed, 325 insertions, 0 deletions
diff --git a/3rd_party/static/testapi-ui/assets/lib/angular-confirm-modal/test/karma.conf.js b/3rd_party/static/testapi-ui/assets/lib/angular-confirm-modal/test/karma.conf.js new file mode 100644 index 0000000..886ed61 --- /dev/null +++ b/3rd_party/static/testapi-ui/assets/lib/angular-confirm-modal/test/karma.conf.js @@ -0,0 +1,81 @@ +// Karma configuration +// Generated on Tue Jul 14 2015 10:10:58 GMT-0400 (Eastern Daylight Time) + +module.exports = function(config) { + var configuration = { + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], + + + // list of files / patterns to load in the browser + files: [ + '../node_modules/angular/angular.js', + '../node_modules/angular-ui-bootstrap/ui-bootstrap-tpls.min.js', + '../node_modules/angular-mocks/angular-mocks.js', + '../angular-confirm.js', + 'unit/**/*Spec.js' + ], + + + // list of files to exclude + exclude: [ + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['Chrome'], + + customLaunchers: { + Chrome_travis_ci: { + base: 'Chrome', + flags: ['--no-sandbox'] + } + }, + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false + }; + + if(process.env.TRAVIS){ + configuration.browsers = ['Chrome_travis_ci']; + } + + config.set(configuration); +} diff --git a/3rd_party/static/testapi-ui/assets/lib/angular-confirm-modal/test/unit/confirmSpec.js b/3rd_party/static/testapi-ui/assets/lib/angular-confirm-modal/test/unit/confirmSpec.js new file mode 100644 index 0000000..8434de4 --- /dev/null +++ b/3rd_party/static/testapi-ui/assets/lib/angular-confirm-modal/test/unit/confirmSpec.js @@ -0,0 +1,244 @@ +describe('angular-confirm', function() { + + var $rootScope, $uibModal; + + beforeEach(angular.mock.module('angular-confirm', function ($provide) { + + $provide.decorator('$uibModal', function($delegate) { + $uibModal = { + open: jasmine.createSpy('$uibModal.open', function(settings) { + return {result: settings}; + }) + }; + return $uibModal; + }); + + $provide.decorator('$confirm', function($delegate) { + return jasmine.createSpy('$confirm', $delegate); + }); + + })); + + beforeEach(angular.mock.inject(function (_$rootScope_) { + $rootScope = _$rootScope_; + })); + + describe('ConfirmModalController', function() { + var $scope, controller, data = {testVal: 1}, $uibModalInstance; + + beforeEach(angular.mock.inject(function($controller) { + $scope = $rootScope.$new(); + $uibModalInstance = { + close: jasmine.createSpy('$uibModalInstance.close'), + dismiss: jasmine.createSpy('$uibModalInstance.dismiss'), + result: { + then: jasmine.createSpy('$uibModalInstance.result.then') + } + }; + controller = $controller('ConfirmModalController', {"$scope": $scope, "$uibModalInstance": $uibModalInstance, "data": data}); + })); + + it("should copy the data, not use it as a reference", function() { + data.testVal = 2; + expect($scope.data.testVal).toEqual(1); + }); + + it("should call close when $scope.ok is invoked", function() { + $scope.ok(); + expect($uibModalInstance.close).toHaveBeenCalled(); + }); + + it("should call dismiss when $scope.cancel is invoked", function() { + $scope.cancel(); + expect($uibModalInstance.dismiss).toHaveBeenCalledWith('cancel'); + }); + + }); + + describe('$confirm factory', function() { + + var $confirm, $confirmModalDefaults; + + beforeEach(angular.mock.inject(function(_$confirm_, _$confirmModalDefaults_) { + $confirm = _$confirm_; + $confirm.and.callThrough(); + $confirmModalDefaults = _$confirmModalDefaults_; + $uibModal.open.and.callThrough(); + })); + + it("should call $uibModal.open", function() { + $confirm(); + expect($uibModal.open).toHaveBeenCalled(); + }); + + it("should override the defaults with settings passed in", function() { + var settings = $confirm({}, {"template": "hello"}); + expect(settings.template).toEqual("hello"); + }); + + it("should not change the defaults", function() { + var settings = $confirm({}, {"templateUrl": "hello"}); + expect(settings.templateUrl).toEqual("hello"); + expect(settings.template).not.toBeDefined(); + expect($confirmModalDefaults.template).toBeDefined(); + expect($confirmModalDefaults.templateUrl).not.toBeDefined(); + }); + + it("should override the default labels with the data passed in", function() { + var settings = $confirm({title: "Title"}); + var data = settings.resolve.data(); + expect(data.title).toEqual("Title"); + expect(data.ok).toEqual('OK'); + }); + + it("should remove template if templateUrl is passed in", function() { + var settings = $confirm({}, {templateUrl: "abc.txt"}); + expect(settings.template).not.toBeDefined(); + }); + + }); + + describe('confirm directive', function() { + var $scope, element, $confirm, data; + + beforeEach(angular.mock.inject(function (_$confirm_, $compile) { + $confirm = _$confirm_; + + $confirm.and.callFake(function(d) { + data = d; + return {then: function() {}} + }); + + $scope = $rootScope.$new(); + $scope.click = jasmine.createSpy('$scope.click'); + })); + + describe('resolve properties in title', function() { + beforeEach(angular.mock.inject(function($compile) { + $scope.name = 'Joe'; + element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure, {{name}}?">Delete</button>'); + $compile(element)($scope); + $scope.$digest(); + })); + + it("should resolve the name to the text property", function() { + element.triggerHandler('click'); + expect(data.text).toEqual('Are you sure, Joe?'); + }); + }); + + describe('without confirmIf', function() { + + beforeEach(angular.mock.inject(function($compile) { + element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?">Delete</button>'); + $compile(element)($scope); + $scope.$digest(); + })); + + it("should call confirm on click and not call the function", function() { + element.triggerHandler('click'); + expect($scope.click).not.toHaveBeenCalled(); + expect($confirm).toHaveBeenCalled(); + }); + + }); + + describe('with confirmIf option', function() { + + beforeEach(angular.mock.inject(function($compile) { + element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-if="truthy">Delete</button>'); + $compile(element)($scope); + $scope.$digest(); + })); + + it("should call confirm on click and not call the function", function() { + $scope.truthy = true; + $scope.$apply(); + element.triggerHandler('click'); + expect($scope.click).not.toHaveBeenCalled(); + expect($confirm).toHaveBeenCalled(); + }); + + it("should call the function", function() { + $scope.truthy = false; + $scope.$apply(); + element.triggerHandler('click'); + expect($scope.click).toHaveBeenCalled(); + expect($confirm).not.toHaveBeenCalled(); + }); + + }); + + describe('with confirmTitle option', function() { + beforeEach(angular.mock.inject(function($compile) { + $scope.name = 'Joe'; + element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-title="Hello, {{name}}!">Delete</button>'); + $compile(element)($scope); + $scope.$digest(); + })); + + it("should resolve the confirmTitle to the title property", function() { + element.triggerHandler('click'); + expect(data.title).toEqual('Hello, Joe!'); + }); + + }); + + describe('with confirmOk option', function() { + beforeEach(angular.mock.inject(function($compile) { + $scope.name = 'Joe'; + element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-ok="Okie Dokie, {{name}}!">Delete</button>'); + $compile(element)($scope); + $scope.$digest(); + })); + + it("should resolve the confirmTitle to the title property", function() { + element.triggerHandler('click'); + expect(data.ok).toEqual('Okie Dokie, Joe!'); + }); + }); + + describe('with confirmCancel option', function() { + beforeEach(angular.mock.inject(function($compile) { + $scope.name = 'Joe'; + element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-cancel="No Way, {{name}}!">Delete</button>'); + $compile(element)($scope); + $scope.$digest(); + })); + + it("should resolve the confirmTitle to the title property", function() { + element.triggerHandler('click'); + expect(data.cancel).toEqual('No Way, Joe!'); + }); + }); + + describe('with confirmSettings option', function() { + beforeEach(angular.mock.inject(function($compile) { + $scope.settings = {name: 'Joe'}; + element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-settings="settings">Delete</button>'); + $compile(element)($scope); + $scope.$digest(); + })); + + it("should pass the settings to $confirm", function() { + element.triggerHandler('click'); + expect($confirm).toHaveBeenCalledWith({text: "Are you sure?"}, $scope.settings) + }); + }); + + describe('with confirmSettings option direct entry', function() { + beforeEach(angular.mock.inject(function($compile) { + element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-settings="{name: \'Joe\'}">Delete</button>'); + $compile(element)($scope); + $scope.$digest(); + })); + + it("should pass the settings to $confirm", function() { + element.triggerHandler('click'); + expect($confirm).toHaveBeenCalledWith({text: "Are you sure?"}, {name: "Joe"}) + }); + }); + + }); + +});
\ No newline at end of file |