index.html revision 2fd0020b39d0935dd53b83d78bc7b3ca4007ed79
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass<script type="text/javascript" src="/build/yui/yui.js"></script>
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass<script type="text/javascript" src="/build/cache/cache.js"></script>
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass<script type="text/javascript" src="/build/dataschema/dataschema.js"></script>
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass<script type="text/javascript" src="/build/datasource/datasource.js" id="src_ds"></script>
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass(function() {
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass //filter: "debug",
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass //logInclude:{"datasource":true},
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass useConsole: true,
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass insertBefore: "src_ds"
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass }).use("dump", "test", "console", "io-base", "cache", "base", "plugin", "json", "dataschema", "datasource", function(Y) {
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass var ASSERT = Y.Assert,
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass ARRAYASSERT = Y.ArrayAssert,
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass OBJECTASSERT = Y.ObjectAssert,
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass BTNRUN = Y.get("#btnRun"),
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass WAITTIMEOUT = 5000; // On a slow connection set to 5000
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass // Set up the page
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass BTNRUN.set("disabled", false);
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass Y.on("click", function() {
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass var myConsole = new Y.Console().render();
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass var testClass = new Y.Test.Case({
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass name: "Class Tests",
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass testConstructor: function() {
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass var ds = new Y.DataSource.Local();
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass ASSERT.areSame((ds instanceof Y.Base), true, "Expected Base instance.");
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass ASSERT.areSame((ds instanceof Y.DataSource.Local), true, "Expected Local instance.");
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass testConstructorXHR: function() {
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass var ds = new Y.DataSource.XHR();
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass ASSERT.areSame((ds instanceof Y.Base), true, "Expected Base instance.");
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass ASSERT.areSame((ds instanceof Y.DataSource.Local), true, "Expected Local instance.");
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass ASSERT.areSame((ds instanceof Y.DataSource.XHR), true, "Expected XHR instance.");
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass var testLocal = new Y.Test.Case({
name: "DataSource.Local Tests",
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("XHR failure case.");
Y.Mock.verify(handler);
var ds = new Y.DataSource.Local({
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("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.ownsAll({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 testJSONSchema = new Y.Test.Case({
name: "DataSource.XHR JSONSchema Tests",
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 testXMLSchema = new Y.Test.Case({
name: "DataSource.XHR XMLSchema Tests",
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 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(testJSONSchema);
Y.Test.Runner.add(testCaching);
Y.Test.Runner.add(testPolling);
Y.Test.Runner.add(testXMLSchema);