Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 0389f4f

Browse files
committed
new tests for new attributes of classes
1 parent a0a6096 commit 0389f4f

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

angular-confirm.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ angular.module('angular-confirm', ['ui.bootstrap.modal'])
4141
defaultLabels: {
4242
title: 'Confirm',
4343
ok: 'OK',
44-
cancel: 'Cancel'
44+
cancel: 'Cancel',
45+
okClass: 'primary',
46+
cancelClass: 'default'
4547
}
4648
})
4749
.factory('$confirm', ["$uibModal", "$confirmModalDefaults", function ($uibModal, $confirmModalDefaults) {
@@ -114,13 +116,9 @@ angular.module('angular-confirm', ['ui.bootstrap.modal'])
114116
}
115117
if (scope.confirmOkClass) {
116118
data.okClass = scope.confirmOkClass;
117-
} else {
118-
data.okClass = 'primary';
119119
}
120120
if (scope.confirmCancelClass) {
121121
data.cancelClass = scope.confirmCancelClass;
122-
} else {
123-
data.cancelClass = 'default';
124122
}
125123
$confirm(data, scope.confirmSettings || {}).then(onSuccess);
126124
} else {

test/unit/confirmSpec.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ describe('angular-confirm', function() {
9696
expect(settings.template).not.toBeDefined();
9797
});
9898

99+
it("should provide default button class names", function(){
100+
expect($confirmModalDefaults.defaultLabels.okClass).toEqual('primary');
101+
expect($confirmModalDefaults.defaultLabels.cancelClass).toEqual('default');
102+
var settings = $confirm({});
103+
var data = settings.resolve.data();
104+
expect(data.okClass).toEqual('primary');
105+
expect(data.cancelClass).toEqual('default');
106+
});
107+
108+
it("should override default class names", function(){
109+
var settings = $confirm({okClass: "danger", cancelClass: "warning"});
110+
var data = settings.resolve.data();
111+
expect(data.okClass).toEqual('danger');
112+
expect(data.cancelClass).toEqual('warning');
113+
});
114+
99115
});
100116

101117
describe('confirm directive', function() {
@@ -205,6 +221,25 @@ describe('angular-confirm', function() {
205221
});
206222
});
207223

224+
describe('with confirmOk and confirmOkClass option', function() {
225+
beforeEach(angular.mock.inject(function($compile) {
226+
$scope.name = 'Joe';
227+
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-ok="Okie Dokie, {{name}}!" confirm-ok-class="danger">Delete</button>');
228+
$compile(element)($scope);
229+
$scope.$digest();
230+
}));
231+
232+
it("should resolve the confirmTitle to the title property", function() {
233+
element.triggerHandler('click');
234+
$timeout.flush();
235+
expect(data.ok).toEqual('Okie Dokie, Joe!');
236+
});
237+
238+
it("should use confirmOkClass to the provided value", function(){
239+
expect(data.okClass).toEqual('danger');
240+
});
241+
});
242+
208243
describe('with confirmCancel option', function() {
209244
beforeEach(angular.mock.inject(function($compile) {
210245
$scope.name = 'Joe';
@@ -220,6 +255,25 @@ describe('angular-confirm', function() {
220255
});
221256
});
222257

258+
describe('with confirmCancel and cancelClass option', function() {
259+
beforeEach(angular.mock.inject(function($compile) {
260+
$scope.name = 'Joe';
261+
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-cancel="No Way, {{name}}!" confirm-cancel-class="warning">Delete</button>');
262+
$compile(element)($scope);
263+
$scope.$digest();
264+
}));
265+
266+
it("should resolve the confirmTitle to the title property", function() {
267+
element.triggerHandler('click');
268+
$timeout.flush();
269+
expect(data.cancel).toEqual('No Way, Joe!');
270+
});
271+
272+
it("should use confirmCancelClass to the provided value", function(){
273+
expect(data.cancelClass).toEqual('warning');
274+
});
275+
});
276+
223277
describe('with confirmSettings option', function() {
224278
beforeEach(angular.mock.inject(function($compile) {
225279
$scope.settings = {name: 'Joe'};
@@ -231,7 +285,7 @@ describe('angular-confirm', function() {
231285
it("should pass the settings to $confirm", function() {
232286
element.triggerHandler('click');
233287
$timeout.flush();
234-
expect($confirm).toHaveBeenCalledWith({text: "Are you sure?", okClass: "primary", cancelClass: "default"}, $scope.settings)
288+
expect($confirm).toHaveBeenCalledWith({text: "Are you sure?"}, $scope.settings)
235289
});
236290
});
237291

@@ -245,7 +299,7 @@ describe('angular-confirm', function() {
245299
it("should pass the settings to $confirm", function() {
246300
element.triggerHandler('click');
247301
$timeout.flush();
248-
expect($confirm).toHaveBeenCalledWith({text: "Are you sure?", okClass: "primary", cancelClass: "default"}, {name: "Joe"})
302+
expect($confirm).toHaveBeenCalledWith({text: "Are you sure?"}, {name: "Joe"})
249303
});
250304
});
251305

0 commit comments

Comments
 (0)