event-synthetic-tests.js revision 01ee8296240295151986080669aad0d4f58b3f88
};
function initTestbed() {
body;
if (!testbed) {
}
'<div id="outer">' +
'<button id="button1">Button 1 text</button>' +
'<ul class="nested">' +
'<li id="item1">Item 1</li>' +
'<li id="item2" class="nested">Item 2</li>' +
'<li id="item3"><p>Item 3</p></li>' +
'</ul>' +
'<div id="inner">' +
'<p id="p1_no">no</p>' +
'<p id="p2_yes">yes</p>' +
'<div id="inner_1">' +
'<p id="inner_1_p1_no"><em>no</em></p>' +
'<p id="inner_1_p2_yes">yes</p>' +
'</div>' +
'<p id="p3_no">no</p>' +
'</div>' +
'</div>');
}
function initSynth() {
},
delegate: function () {
},
},
detachDelegate: function () {
}
}, true);
}
function setUp() {
initTestbed();
initSynth();
}
function destroyTestbed() {
if (testbed) {
}
}
function undefineSynth() {
}
function tearDown() {
}
/******************************************************************************/
/****************************** Tests begin here ****************************/
/******************************************************************************/
name: "Y.Event.define",
"Y.Event.define(name) should add to DOM_EVENTS": function () {
},
"Y.Event.define([name1, name2]) should add to DOM_EVENTS": function () {
},
"Y.Event.define(type, {...}) should register a new synth in DOM_EVENTS": function () {
index: 0
});
},
"Subsequent Y.Event.define() should not overwrite existing synth": function () {
index: 1
});
},
"Y.Event.define(..., true) should overwrite existing synth": function () {
index: 2
}, true);
},
"Y.Event.define({ type: ...}) should register a new synth in DOM_EVENTS": function () {
type: 'synth',
index: 3
});
},
"Y.Event.define({...}, true) should overwrite existing synth": function () {
type: 'synth',
index: 2
}, true);
}
}));
name: "Y.on",
"test Y.on('synth', fn, node)": function () {
Y.on('synth', function (e) {
thisObj = this;
}, target);
},
"test Y.on('synth', fn, node, thisObj)": function () {
Y.on('synth', function (e) {
thisObj = this;
},
"test Y.on('synth', fn, node, thisObj, arg)": function () {
Y.on('synth', function (e, x) {
thisObj = this;
arg = x;
},
"test Y.on('synth', fn, node, null, arg)": function () {
Y.on('synth', function (e, x) {
thisObj = this;
arg = x;
}, target, null, 'arg!');
},
"test Y.on('synth', fn, el)": function () {
Y.on('synth', function (e) {
thisObj = this;
}, targetEl);
},
"test Y.on('synth', fn, el, thisObj)": function () {
Y.on('synth', function (e) {
thisObj = this;
},
"test Y.on('synth', fn, el, thisObj, arg)": function () {
Y.on('synth', function (e, x) {
thisObj = this;
arg = x;
},
"test Y.on('synth', fn, el, null, arg)": function () {
Y.on('synth', function (e, x) {
thisObj = this;
arg = x;
}, targetEl, null, 'arg!');
},
"test Y.on('synth', fn, selectorOne)": function () {
Y.on('synth', function (e) {
thisObj = this;
}, '#item3');
},
"test Y.on('synth', fn, selectorOne, thisObj)": function () {
Y.on('synth', function (e) {
thisObj = this;
}, '#item3', obj);
},
"test Y.on('synth', fn, selectorOne, thisObj, arg)": function () {
Y.on('synth', function (e, x) {
thisObj = this;
arg = x;
},
"test Y.on('synth', fn, selectorOne, null, arg)": function () {
Y.on('synth', function (e, x) {
thisObj = this;
arg = x;
}, '#item3', null, 'arg!');
},
"test Y.on('synth', fn, selectorMultiple)": function () {
type = [],
currentTarget = [],
thisObj = [];
Y.on('synth', function (e) {
}, '#outer li');
},
"test Y.on('synth', fn, selectorMultiple, thisObj)": function () {
type = [],
currentTarget = [],
thisObj = [],
foo = [];
Y.on('synth', function (e) {
}, '#outer li', obj);
},
"test Y.on('synth', fn, selectorMultiple, thisObj, arg)": function () {
type = [],
currentTarget = [],
thisObj = [],
foo = [],
arg = [];
Y.on('synth', function (e, x) {
},
"test Y.on('synth', fn, selectorMultiple, null, arg)": function () {
type = [],
currentTarget = [],
thisObj = [],
arg = [];
Y.on('synth', function (e, x) {
}, '#outer li', null, 'arg!');
},
"test Y.on('synth', fn, notYetAvailable)": function () {
test = this,
type = [],
currentTarget = [],
thisObj = [];
Y.on('synth', function (e) {
thisObj = this;
}, '#p4');
// This is a tainted test because it's using a different synthetic
// event to test that the synthetic event infrastructure is working
// properly. The other option is to use Y.later, but that opens a race
// condition. The test is left in place because something is better
// than nothing.
Y.on("available", function () {
if (p4) {
} else {
}
});
}, '#p4');
},
"test Y.on('synth', fn, notYetAvailable, thisObj)": function () {
test = this,
Y.on('synth', function (e) {
thisObj = this;
}, '#p4', obj);
// This is a tainted test because it's using a different synthetic
// event to test that the synthetic event infrastructure is working
// properly. The other option is to use Y.later, but that opens a race
// condition. The test is left in place because something is better
// than nothing.
Y.on("available", function () {
if (p4) {
} else {
}
});
}, '#p4');
},
"test Y.on('synth', fn, notYetAvailable, thisObj, arg)": function () {
test = this,
Y.on('synth', function (e, x) {
thisObj = this;
arg = x;
// This is a tainted test because it's using a different synthetic
// event to test that the synthetic event infrastructure is working
// properly. The other option is to use Y.later, but that opens a race
// condition. The test is left in place because something is better
// than nothing.
Y.on("available", function () {
if (p4) {
} else {
}
});
}, '#p4');
},
"test Y.on('synth', fn, notYetAvailable, null, arg)": function () {
test = this,
Y.on('synth', function (e, x) {
thisObj = this;
arg = x;
}, '#p4', null, 'arg!');
// This is a tainted test because it's using a different synthetic
// event to test that the synthetic event infrastructure is working
// properly. The other option is to use Y.later, but that opens a race
// condition. The test is left in place because something is better
// than nothing.
Y.on("available", function () {
if (p4) {
} else {
}
});
}, '#p4');
}
}));
name: 'node.on',
"test node.on(x, fn)": function () {
thisObj = this;
});
},
"test node.on(x, fn, thisObj)": function () {
thisObj = this;
}, obj);
},
"test node.on(x, fn, thisObj, arg)": function () {
thisObj = this;
arg = x;
}, obj, 'arg!');
},
"test node.on(x, fn, null, arg)": function () {
thisObj = this;
arg = x;
}, null, 'arg!');
}
}));
name: 'nodelist.on',
"test nodelist.on(x, fn)": function () {
type = [],
currentTarget = [],
thisObj = [];
});
},
"test nodelist.on(x, fn, thisObj)": function () {
type = [],
currentTarget = [],
thisObj = [],
foo = [];
}, obj);
},
"test nodelist.on(x, fn, thisObj, arg)": function () {
type = [],
currentTarget = [],
thisObj = [],
foo = [],
arg = [];
}, obj, 'arg!');
},
"test nodelist.on(x, fn, null, arg)": function () {
type = [],
currentTarget = [],
thisObj = [],
arg = [];
}, null, 'arg!');
}
}));
name: 'preventDups',
initUniqueSynth: function () {
preventDups: true,
},
}
}, true);
},
"node.on(x, fn) + node.on(x, fn) should allow dups": function () {
initSynth();
count = 0;
function increment() {
count++;
}
},
"Y.on(x, fn) + node.on(x, fn) should allow dups": function () {
initSynth();
var count = 0;
function increment() {
count++;
}
},
"nodelist.on(x, fn) + node.on(x, fn) should allow dups": function () {
initSynth();
var count = 0;
function increment() {
count++;
}
},
"preventDups:true node.on(x, fn) + node.on(x, fn) should prevent dups": function () {
this.initUniqueSynth();
count = 0;
function increment() {
count++;
}
},
"preventDups:true Y.on(x, fn) + node.on(x, fn) should prevent dups": function () {
this.initUniqueSynth();
var count = 0;
function increment() {
count++;
}
},
"preventDups:true nodelist.on(x, fn) + node.on(x, fn) should prevent dups": function () {
this.initUniqueSynth();
var count = 0;
function increment() {
count++;
}
}
}));
name: "node.delegate",
"test node.delegate(synth, fn, filter)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
container = [],
a = Y.one("#p1_no"),
b = Y.one("#inner_1_p1_no em");
count++;
}, 'p');
a.click();
b.click();
},
"test node.delegate(synth, fn, filter, thisObj)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
foo = [],
container = [],
a = Y.one("#p1_no"),
b = Y.one("#inner_1_p1_no em");
count++;
}, 'p', obj);
a.click();
b.click();
},
"test node.delegate(synth, fn, filter, thisObj, arg)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
foo = [],
arg = [],
container = [],
a = Y.one("#p1_no"),
b = Y.one("#inner_1_p1_no em");
count++;
a.click();
b.click();
},
"test node.delegate(synth, fn, filter, null, arg)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
arg = [],
container = [],
a = Y.one("#p1_no"),
b = Y.one("#inner_1_p1_no em");
count++;
}, 'p', null, "arg!");
a.click();
b.click();
}
}));
name: "Y.delegate",
"test Y.delegate(synth, fn, node, filter)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
container = [],
a = Y.one("#p1_no"),
b = Y.one("#inner_1_p1_no em");
Y.delegate('synth', function (e) {
count++;
}, inner, 'p');
a.click();
b.click();
},
"test Y.delegate(synth, fn, el, filter)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
container = [],
a = Y.one("#p1_no"),
b = Y.one("#inner_1_p1_no em");
Y.delegate('synth', function (e) {
count++;
a.click();
b.click();
},
"test Y.delegate(synth, fn, selectorOne, filter)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
container = [],
a = Y.one("#p1_no"),
b = Y.one("#inner_1_p1_no em");
Y.delegate('synth', function (e) {
count++;
}, "#inner", 'p');
a.click();
b.click();
},
"test Y.delegate(synth, fn, node, filter, thisObj)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
foo = [],
container = [],
a = Y.one("#p1_no"),
b = Y.one("#inner_1_p1_no em");
Y.delegate('synth', function (e) {
count++;
a.click();
b.click();
},
"test Y.delegate(synth, fn, node, filter, thisObj, arg)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
foo = [],
arg = [],
container = [],
a = Y.one("#p1_no"),
b = Y.one("#inner_1_p1_no em");
Y.delegate('synth', function (e, x) {
count++;
a.click();
b.click();
},
"test Y.delegate(synth, fn, node, filter, null, arg)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
arg = [],
container = [],
a = Y.one("#p1_no"),
b = Y.one("#inner_1_p1_no em");
Y.delegate('synth', function (e, x) {
count++;
a.click();
b.click();
},
"test Y.delegate(synth, fn, notAvailableYet, filter)": function () {
test = this,
count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
container = [];
Y.delegate('synth', function (e) {
count++;
}, '#inner_1', 'p');
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
// This is a tainted test because it's using a different synthetic
// event to test that the synthetic event infrastructure is working
// properly. The other option is to use Y.later, but that opens a race
// condition. The test is left in place because something is better
// than nothing.
Y.on("available", function () {
if (a && b && inner1) {
a.click();
b.click();
} else {
}
});
}, '#pass2-trigger');
},
"test Y.delegate(synth, fn, notAvailableYet, filter, thisObj)": function () {
test = this,
count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
foo = [],
container = [];
Y.delegate('synth', function (e) {
count++;
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
// This is a tainted test because it's using a different synthetic
// event to test that the synthetic event infrastructure is working
// properly. The other option is to use Y.later, but that opens a race
// condition. The test is left in place because something is better
// than nothing.
Y.on("available", function () {
if (a && b && inner1) {
a.click();
b.click();
} else {
}
});
}, '#pass2-trigger');
},
"test Y.delegate(synth, fn, notAvailableYet, filter, thisObj, arg)": function () {
test = this,
count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
foo = [],
arg = [],
container = [];
Y.delegate('synth', function (e, x) {
count++;
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
// This is a tainted test because it's using a different synthetic
// event to test that the synthetic event infrastructure is working
// properly. The other option is to use Y.later, but that opens a race
// condition. The test is left in place because something is better
// than nothing.
Y.on("available", function () {
if (a && b && inner1) {
a.click();
b.click();
} else {
}
});
}, '#pass2-trigger');
},
"test Y.delegate(synth, fn, notAvailableYet, filter, null, arg)": function () {
test = this,
count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
arg = [],
container = [];
Y.delegate('synth', function (e, x) {
count++;
}, '#inner_1', 'p', null, "arg!");
inner.setContent("<div id='inner_1'><p id='pass1'>Added</p><div><p id='pass2'><em id='pass2-trigger'>Trigger</em></p></div></div>");
// This is a tainted test because it's using a different synthetic
// event to test that the synthetic event infrastructure is working
// properly. The other option is to use Y.later, but that opens a race
// condition. The test is left in place because something is better
// than nothing.
Y.on("available", function () {
if (a && b && inner1) {
a.click();
b.click();
} else {
}
});
}, '#pass2-trigger');
},
"test Y.delegate(synth, fn, selectorMulti, filter)": function () {
var count = 0,
type = [],
target = [],
currentTarget = [],
thisObj = [],
container = [],
a = Y.one('#item3 p'),
b = Y.one("#inner_1_p1_no em");
Y.delegate('synth', function (e) {
count++;
}, ".nested, #inner", 'p');
a.click();
b.click();
}
}));
name: "Detach",
_should: {
fail: {
// TODO: Can this be made to work?
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___')": true,
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___', fn)": true,
"test nodelist.on('cat|__', fn) + node.detach('cat|*')": true,
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___')": true,
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___', fn)": true,
"test Y.on('cat|__', fn, multiSelector) + node.detach('cat|*')": true
}
},
"test node.on() + node.detach(synth, fn)": function () {
var count = 0,
function fn() {
count++;
}
},
"test node.on(synth, fn, thisObj) + node.detach(synth, fn)": function () {
var count = 0,
a = {},
b = {},
function fn() {
count++;
}
},
"test node.on() + node.detach(synth)": function () {
var count = 0,
function fn() {
count++;
}
},
"test node.on() + node.detach()": function () {
var count = 0,
function fn() {
count++;
}
},
"test node.on() + node.detachAll()": function () {
var count = 0,
function fn() {
count++;
}
},
"test node.on() + node.purge(true, synth)": function () {
var count = 0,
function fn() {
count++;
}
},
"test node.on() + parent.purge(true, synth)": function () {
var count = 0,
function fn() {
count++;
}
},
"test nodelist.on(synth, fn) + node.detach(synth, fn)": function () {
var count = 0,
function increment() {
count++;
}
},
"test nodelist.on(synth, fn) + node.detach(synth)": function () {
var count = 0,
function increment() {
count++;
}
},
"test node.on(synth, fn) + nodelist.detach(synth, fn)": function () {
var count = 0,
function increment() {
count++;
}
},
"test node.on(synth, fn) + nodelist.detach(synth)": function () {
var count = 0,
function increment() {
count++;
}
},
"test node.on() + handle.detach()": function () {
var count = 0,
sub;
function increment() {
count++;
}
},
"test nodelist.on() + handle.detach()": function () {
var count = 0,
sub;
function increment() {
count++;
}
},
"test nodelist.on() + nodelist.detach(synth, fn)": function () {
var count = 0,
function fn() {
count++;
}
count = 0;
count = 0;
count = 0;
},
"test nodelist.on(synth, fn, thisObj) + nodelist.detach(synth, fn)": function () {
var count = 0,
a = {},
b = {},
function fn() {
count++;
}
count = 0;
count = 0;
count = 0;
},
"test nodelist.on() + nodelist.detach(synth)": function () {
var count = 0,
function fn() {
count++;
}
count = 0;
count = 0;
count = 0;
},
"test nodelist.on() + nodelist.detach()": function () {
var count = 0,
function fn() {
count++;
}
count = 0;
count = 0;
count = 0;
},
"test nodelist.on() + nodelist.detachAll()": function () {
var count = 0,
function fn() {
count++;
}
count = 0;
count = 0;
count = 0;
},
"test nodelist.on() + parent.purge(true, synth)": function () {
var count = 0,
function fn() {
count++;
}
count = 0;
count = 0;
count = 0;
},
"test node.on('cat|__', fn) + node.detach('cat|___')": function () {
var count = 0,
function increment() {
count++;
}
},
"test node.on('cat|__', fn) + node.detach('cat|___', fn)": function () {
var count = 0,
function increment() {
count++;
}
},
"test node.on('cat|__', fn) + node.detach('cat|*')": function () {
var count = 0,
function increment() {
count++;
}
},
"test Y.on('cat|__', fn, sel) + node.detach('cat|___')": function () {
var count = 0,
function increment() {
count++;
}
},
"test Y.on('cat|__', fn, sel) + node.detach('cat|___', fn)": function () {
var count = 0,
function increment() {
count++;
}
},
"test Y.on('cat|__', fn) + node.detach('cat|*')": function () {
var count = 0,
function increment() {
count++;
}
},
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___')": function () {
var count = 0,
function increment() {
count++;
}
},
"test nodelist.on('cat|__', fn) + nodelist.detach('cat|___', fn)": function () {
var count = 0,
function increment() {
count++;
}
},
"test nodelist.on('cat|__', fn) + node.detach('cat|*')": function () {
var count = 0,
function increment() {
count++;
}
},
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___')": function () {
var count = 0,
function increment() {
count++;
}
},
"test Y.on('cat|__', fn, multiSelector) + nodelist.detach('cat|___', fn)": function () {
var count = 0,
function increment() {
count++;
}
},
"test Y.on('cat|__', fn, multiSelector) + node.detach('cat|*')": function () {
var count = 0,
function increment() {
count++;
}
}
// Y.on('cat|_', fn, multiSelector) + nodelist.detach('cat|_'[, fn]);
}));
name: "processArgs",
setUp: function () {
initTestbed();
var config = {
},
}, filter);
},
}
};
},
"test Y.on('synth', fn, selector, extra)": function () {
var test = this,
Y.on('synth', function (e) {
thisObj = this;
}, '#item3', 'EXTRA');
},
"Y.on('synth', fn, '#not-here-yet', extra) should resubscribe with original arguments": function () {
var test = this,
Y.on('synth', function (e) {
thisObj = this;
}, '#item4', 'EXTRA');
setTimeout(function () {
setTimeout(function () {
});
}, 300);
}, 100);
}
}));
name: "Notifier",
}));