|
@@ -1,6 +1,6 @@
|
|
(function() {
|
|
(function() {
|
|
- describe("Bootstrap Switch", function() {
|
|
|
|
- var createElement, getOptions;
|
|
|
|
|
|
+ describe("Bootstrap Switch:", function() {
|
|
|
|
+ var createCheckbox, createRadio, getOptions;
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
$.support.transition = false;
|
|
$.support.transition = false;
|
|
return $.fx.off = true;
|
|
return $.fx.off = true;
|
|
@@ -8,29 +8,100 @@
|
|
afterEach(function() {
|
|
afterEach(function() {
|
|
return $("." + $.fn.bootstrapSwitch.defaults.baseClass).bootstrapSwitch("destroy");
|
|
return $("." + $.fn.bootstrapSwitch.defaults.baseClass).bootstrapSwitch("destroy");
|
|
});
|
|
});
|
|
- createElement = function() {
|
|
|
|
|
|
+ createCheckbox = function() {
|
|
return $("<input>", {
|
|
return $("<input>", {
|
|
type: "checkbox",
|
|
type: "checkbox",
|
|
"class": "switch"
|
|
"class": "switch"
|
|
}).appendTo("body");
|
|
}).appendTo("body");
|
|
};
|
|
};
|
|
|
|
+ createRadio = function() {
|
|
|
|
+ return $("<input>", {
|
|
|
|
+ type: "radio",
|
|
|
|
+ name: "name",
|
|
|
|
+ "class": "switch"
|
|
|
|
+ }).appendTo("body");
|
|
|
|
+ };
|
|
getOptions = function($element) {
|
|
getOptions = function($element) {
|
|
return $element.data("bootstrap-switch").options;
|
|
return $element.data("bootstrap-switch").options;
|
|
};
|
|
};
|
|
it("should set the default options as element options, except state", function() {
|
|
it("should set the default options as element options, except state", function() {
|
|
var $switch;
|
|
var $switch;
|
|
- $switch = createElement().prop("checked", true).bootstrapSwitch();
|
|
|
|
|
|
+ $switch = createCheckbox().prop("checked", true).bootstrapSwitch();
|
|
return expect(getOptions($switch)).toEqual($.fn.bootstrapSwitch.defaults);
|
|
return expect(getOptions($switch)).toEqual($.fn.bootstrapSwitch.defaults);
|
|
});
|
|
});
|
|
- return it("should override default options with initialization ones", function() {
|
|
|
|
|
|
+ it("should override default options with initialization ones", function() {
|
|
var $switch, $switch2;
|
|
var $switch, $switch2;
|
|
- $switch = createElement().prop("checked", false).bootstrapSwitch();
|
|
|
|
- $switch2 = createElement().bootstrapSwitch({
|
|
|
|
|
|
+ $switch = createCheckbox().prop("checked", false).bootstrapSwitch();
|
|
|
|
+ $switch2 = createCheckbox().bootstrapSwitch({
|
|
state: false
|
|
state: false
|
|
});
|
|
});
|
|
expect(getOptions($switch).state).toBe(false);
|
|
expect(getOptions($switch).state).toBe(false);
|
|
return expect(getOptions($switch2).state).toBe(false);
|
|
return expect(getOptions($switch2).state).toBe(false);
|
|
});
|
|
});
|
|
|
|
+ describe("The Checkbox Bootstrap Switch", function() {
|
|
|
|
+ it("should conserve its state if onSwitchChange returns false", function() {
|
|
|
|
+ var $indeterminateSwitch, $switch;
|
|
|
|
+ $switch = createCheckbox().bootstrapSwitch({
|
|
|
|
+ onSwitchChange: function(e, s) {
|
|
|
|
+ expect(s).toEqual(true);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ $indeterminateSwitch = createCheckbox().data("indeterminate", true).bootstrapSwitch({
|
|
|
|
+ onSwitchChange: function(e, s) {
|
|
|
|
+ expect(s).toEqual(true);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ $switch.click();
|
|
|
|
+ $indeterminateSwitch.click();
|
|
|
|
+ expect($switch.bootstrapSwitch('state')).toEqual(false);
|
|
|
|
+ return expect($indeterminateSwitch.bootstrapSwitch('state')).toEqual(false);
|
|
|
|
+ });
|
|
|
|
+ return it("should change its state if onSwitchChange not returns false", function() {
|
|
|
|
+ var $switch;
|
|
|
|
+ $switch = createCheckbox().bootstrapSwitch({
|
|
|
|
+ onSwitchChange: function(e, s) {
|
|
|
|
+ return expect(s).toEqual(true);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ $switch.click();
|
|
|
|
+ return expect($switch.bootstrapSwitch('state')).toEqual(true);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ return describe("The Radio Bootstrap Switch", function() {
|
|
|
|
+ it("should conserve its state if onSwitchChange returns false", function() {
|
|
|
|
+ var $radio1, $radio2, $radio3;
|
|
|
|
+ $radio1 = createRadio().prop("checked", true);
|
|
|
|
+ $radio2 = createRadio().prop("checked", false);
|
|
|
|
+ $radio3 = createRadio().prop("checked", false);
|
|
|
|
+ $('[name="name"]').bootstrapSwitch({
|
|
|
|
+ onSwitchChange: function(e, s) {
|
|
|
|
+ expect(s).toEqual(true);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ $radio2.click();
|
|
|
|
+ expect($radio1.bootstrapSwitch('state')).toEqual(true);
|
|
|
|
+ expect($radio2.bootstrapSwitch('state')).toEqual(false);
|
|
|
|
+ return expect($radio3.bootstrapSwitch('state')).toEqual(false);
|
|
|
|
+ });
|
|
|
|
+ return it("should change its state if onSwitchChange not returns false", function() {
|
|
|
|
+ var $radio1, $radio2, $radio3;
|
|
|
|
+ $radio1 = createRadio().prop("checked", true);
|
|
|
|
+ $radio2 = createRadio().prop("checked", false);
|
|
|
|
+ $radio3 = createRadio().prop("checked", false);
|
|
|
|
+ $('[name="name"]').bootstrapSwitch({
|
|
|
|
+ onSwitchChange: function(e, s) {
|
|
|
|
+ return expect(s).toEqual(true);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ $radio2.click();
|
|
|
|
+ expect($radio1.bootstrapSwitch('state')).toEqual(false);
|
|
|
|
+ expect($radio2.bootstrapSwitch('state')).toEqual(true);
|
|
|
|
+ return expect($radio3.bootstrapSwitch('state')).toEqual(false);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
});
|
|
});
|
|
|
|
|
|
}).call(this);
|
|
}).call(this);
|