2014-08-29 03:54:01 +04:00
|
|
|
module("Decorators")
|
|
|
|
|
|
|
|
var Utils = require("select2/utils");
|
|
|
|
|
2014-08-31 02:34:41 +04:00
|
|
|
test("overridden - method", function (assert) {
|
2014-09-21 23:05:00 +04:00
|
|
|
function BaseClass () {};
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
BaseClass.prototype.hello = function () {
|
|
|
|
return "A";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
function DecoratorClass () {};
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
DecoratorClass.prototype.hello = function () {
|
|
|
|
return "B";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var inst = new DecoratedClass();
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
assert.strictEqual(inst.hello(), "B");
|
2014-08-29 03:54:01 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
test("overridden - constructor", function (assert) {
|
2014-09-21 23:05:00 +04:00
|
|
|
function BaseClass () {
|
|
|
|
this.inherited = true;
|
|
|
|
};
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
BaseClass.prototype.hello = function () {
|
|
|
|
return "A";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
function DecoratorClass (decorated) {
|
|
|
|
this.called = true;
|
|
|
|
};
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
DecoratorClass.prototype.other = function () {
|
|
|
|
return "B";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var inst = new DecoratedClass();
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
assert.ok(inst.called);
|
|
|
|
assert.ok(!inst.inherited);
|
2014-08-29 03:54:01 +04:00
|
|
|
});
|
|
|
|
|
2014-08-31 02:34:41 +04:00
|
|
|
test("not overridden - method", function (assert) {
|
2014-09-21 23:05:00 +04:00
|
|
|
function BaseClass () {};
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
BaseClass.prototype.hello = function () {
|
|
|
|
return "A";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
function DecoratorClass () {};
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
DecoratorClass.prototype.other = function () {
|
|
|
|
return "B";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var inst = new DecoratedClass();
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
assert.strictEqual(inst.hello(), "A");
|
2014-08-29 03:54:01 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
test("not overridden - constructor", function (assert) {
|
2014-09-21 23:05:00 +04:00
|
|
|
function BaseClass () {
|
|
|
|
this.called = true;
|
|
|
|
};
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
BaseClass.prototype.hello = function () {
|
|
|
|
return "A";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
function DecoratorClass () {};
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
DecoratorClass.prototype.other = function () {
|
|
|
|
return "B";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var inst = new DecoratedClass();
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
assert.ok(inst.called);
|
2014-08-29 03:54:01 +04:00
|
|
|
});
|
|
|
|
|
2014-08-31 02:34:41 +04:00
|
|
|
test("inherited - method", function (assert) {
|
2014-09-21 23:05:00 +04:00
|
|
|
function BaseClass () { };
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
BaseClass.prototype.hello = function () {
|
|
|
|
return "A";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
function DecoratorClass (decorated) { };
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
DecoratorClass.prototype.hello = function (decorated) {
|
|
|
|
return "B" + decorated.call(this) + "C";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var inst = new DecoratedClass();
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
assert.strictEqual(inst.hello(), "BAC");
|
2014-08-29 03:54:01 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
test("inherited - constructor", function (assert) {
|
2014-09-21 23:05:00 +04:00
|
|
|
function BaseClass () {
|
|
|
|
this.inherited = true;
|
|
|
|
};
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
BaseClass.prototype.hello = function () {
|
|
|
|
return "A";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
function DecoratorClass (decorated) {
|
|
|
|
this.called = true;
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
decorated.call(this);
|
|
|
|
};
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
DecoratorClass.prototype.other = function () {
|
|
|
|
return "B";
|
|
|
|
}
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var DecoratedClass = Utils.Decorate(BaseClass, DecoratorClass);
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
var inst = new DecoratedClass();
|
2014-08-29 03:54:01 +04:00
|
|
|
|
2014-09-21 23:05:00 +04:00
|
|
|
assert.ok(inst.called);
|
|
|
|
assert.ok(inst.inherited);
|
2014-08-29 03:54:01 +04:00
|
|
|
});
|