index.html revision 21a3d9293597d65e84324fe57b7158e3d67a46c1
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich<script type="text/javascript" src="/build/yui/yui.js"></script>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich<script type="text/javascript" src="/build/datasource/datasource-debug.js"></script>
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
ec749fdeacb8e11cb7a9dd6dcebd1538b953059eAllen Rabinovich //filter: "debug",
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich logInclude:{"TestRunner":true,"datasource":true},
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich useConsole: true
ec749fdeacb8e11cb7a9dd6dcebd1538b953059eAllen Rabinovich }).use("dump", "test", "console", "io-base", "cache", "base", "plugin", "json", "datatype", "dataschema", "datasource", function(Y) {
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich BTNRUN = Y.get("#btnRun"),
ec749fdeacb8e11cb7a9dd6dcebd1538b953059eAllen Rabinovich WAITTIMEOUT = 5000; // On a slow connection set to 5000
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich // Set up the page
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich BTNRUN.set("disabled", false);
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich Y.on("click", function() {
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich var myConsole = new Y.Console().render();
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich var testClass = new Y.Test.Case({
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich name: "Class Tests",
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich testConstructor: function() {
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich ASSERT.areSame((ds instanceof Y.Base), true, "Expected Base instance.");
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich ASSERT.areSame((ds instanceof Y.DataSource.Local), true, "Expected Local instance.");
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich testConstructorXHR: function() {
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich ASSERT.areSame((ds instanceof Y.Base), true, "Expected Base instance.");
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich ASSERT.areSame((ds instanceof Y.DataSource.Local), true, "Expected Local instance.");
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich ASSERT.areSame((ds instanceof Y.DataSource.XHR), true, "Expected XHR instance.");
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich var testLocal = new Y.Test.Case({
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich testLocalDefaults: function() {
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich source: ["a","b","c","d"]
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich var handler = Y.Mock();
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich method: "handleSuccess",
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich args: [Y.Mock.Value(function(e){
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich ARRAYASSERT.itemsAreSame(["a","b","c","d"], e.response.results, "Expected live array.");
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich failure: function(e) {
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich ASSERT.fail("XHR failure case.");
ec749fdeacb8e11cb7a9dd6dcebd1538b953059eAllen Rabinovich testLocalEvents: function() {
ec749fdeacb8e11cb7a9dd6dcebd1538b953059eAllen Rabinovich source: ["a","b","c","d"]
ec749fdeacb8e11cb7a9dd6dcebd1538b953059eAllen Rabinovich var handler = Y.Mock();
ec749fdeacb8e11cb7a9dd6dcebd1538b953059eAllen Rabinovich method: "handleRequest",
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich args: [Y.Mock.Value(function(e){
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich ASSERT.isNumber(e.tId, "request: Expected transaction ID.");
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich ASSERT.areSame("a", e.request, "request: Expected request.");
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich ASSERT.areSame("callback", e.callback, "request: Expected callback.");
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.sendRequest("a", "callback");
Y.Mock.verify(handler);
var ds = new Y.DataSource.Local({
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.set("source", undefined);
ds.sendRequest("a", "callback");
var testXHR = new Y.Test.Case({
name: "DataSource.XHR Tests",
var ds = new Y.DataSource.XHR({
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
OBJECTASSERT.ownsKeys({tId:null,request:null,data:null,response:null,callback:null}, e, "Expected all properties.");
ds.sendRequest(null, {
success: handler.handleSuccess,
ASSERT.fail("XHR failure case.");
var ds = new Y.DataSource.XHR({
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
OBJECTASSERT.ownsKeys({tId:null,request:null,data:null,response:null,callback:null}, e, "Expected all properties.");
ds.sendRequest(null, {
success: handler.handleSuccess,
ASSERT.fail("XHR failure case.");
var ds = new Y.DataSource.XHR({
resultListLocator: "ResultSet.Result",
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.sendRequest(null, "callback");
var ds = new Y.DataSource.XHR({
resultListLocator: "ResultSet.Result",
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.set("source", "foo");
ds.sendRequest("a", "callback");
var testScriptNode = new Y.Test.Case({
name: "DataSource.ScriptNode Tests",
var ds = new Y.DataSource.ScriptNode({
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ASSERT.areSame("q=select%20*%20from%20search.web%20where%20query%3D%22pizza%22", e.request, "Expected same request.");
OBJECTASSERT.ownsKeys({tId:null,request:null,data:null,response:null,callback:null}, e, "Expected all properties.");
success: handler.handleSuccess,
ASSERT.fail("ScriptNode failure case.");
var ds = new Y.DataSource.ScriptNode({
resultListLocator: "query.results.result",
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ASSERT.areSame("q=select%20*%20from%20search.web%20where%20query%3D%22pizza%22", e.request, "Expected same request.");
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ASSERT.areSame("q=select%20*%20from%20search.web%20where%20query%3D%22pizza%22", e.request, "Expected same request.");
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ASSERT.areSame("q=select%20*%20from%20search.web%20where%20query%3D%22pizza%22", e.request, "Expected same request.");
testScriptNodeError: (Y.UA.gecko) ? function() {
var ds = new Y.DataSource.ScriptNode({
resultListLocator: "query.results.result",
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.set("source", "foo");
ds.sendRequest("a", "callback");
var testFunction = new Y.Test.Case({
name: "DataSource.Function Tests",
var ds = new Y.DataSource.Function({
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
OBJECTASSERT.ownsKeys({tId:null,request:null,data:null,response:null,callback:null}, e, "Expected all properties.");
ds.sendRequest("foo", {
success: handler.handleSuccess,
ASSERT.fail("Function failure case.");
var ds = new Y.DataSource.Function({
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.sendRequest("foo", "callback");
var ds = new Y.DataSource.Function({
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.sendRequest("a", "callback");
var testDataSchemaPlugin = new Y.Test.Case({
var ds = new Y.DataSource.XHR({
resultListLocator: "ResultSet.Result",
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.sendRequest(null, {
success: handler.handleSuccess,
ASSERT.fail("XHR failure case.");
var ds = new Y.DataSource.XHR({
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.sendRequest(null, {
success: handler.handleSuccess,
ASSERT.fail("XHR failure case.");
var ds = new Y.DataSource.Local({
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.sendRequest(null, {
success: handler.handleSuccess,
ASSERT.fail("Local failure case.");
var ds = new Y.DataSource.Local({
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value(function(e){
ds.sendRequest(null, {
success: handler.handleSuccess,
ASSERT.fail("Local failure case.");
var testCaching = new Y.Test.Case({
var ds = new Y.DataSource.Local();
var ds = new Y.DataSource.Local();
var ds = new Y.DataSource.Local();
ds.cache.set("max", 5);
var ds = new Y.DataSource.Local({
ds.sendRequest("a");
ds.subscribe("data", function(e) {
ASSERT.fail("Entry should be cached -- 'data' event is unexpected");
ds.sendRequest("a");
var ds = new Y.DataSource.Local({
ds.sendRequest("a");
ds.cache.subscribe("retrieve", function(e) {
ASSERT.fail("Cache is unset -- 'retrieve' event is unexpected");
ds.unplug("cache");
ds.sendRequest("a");
var testPolling = new Y.Test.Case({
var ds = new Y.DataSource.Local();
ds = new Y.DataSource.XHR();
var ds = new Y.DataSource.Local();
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value.Any],
var id = ds.setInterval(500, null, {
success: handler.handleSuccess,
ASSERT.fail("XHR failure case.");
ASSERT.isNumber(id, "Expected interval id.");
this.wait(function(){
ds.clearInterval(id);
this.wait(function(){
Y.Mock.verify(handler);
var ds = new Y.DataSource.Local();
var handler = Y.Mock();
Y.Mock.expect(handler,{
args: [Y.Mock.Value.Any],
ds.setInterval(500, null, {
success: handler.handleSuccess,
ASSERT.fail("XHR failure case.");
ds.setInterval(500, null, {
success: handler.handleSuccess,
ASSERT.fail("XHR failure case.");
ds.setInterval(500, null, {
success: handler.handleSuccess,
ASSERT.fail("XHR failure case.");
this.wait(function(){
this.wait(function(){
Y.Mock.verify(handler);
Y.Test.Runner.add(testClass);
Y.Test.Runner.add(testLocal);
Y.Test.Runner.add(testXHR);
Y.Test.Runner.add(testScriptNode);
Y.Test.Runner.add(testFunction);
Y.Test.Runner.add(testDataSchemaPlugin);
Y.Test.Runner.add(testCaching);
Y.Test.Runner.add(testPolling);