model-list-test.js revision e555c9d01738735fa1493766e1c1a478e02abbc5
var ArrayAssert = Y.ArrayAssert,
ObjectAssert = Y.ObjectAssert,
// -- Global Suite -------------------------------------------------------------
// -- ModelList Suite ----------------------------------------------------------
// -- ModelList: Lifecycle -----------------------------------------------------
name: 'Lifecycle',
setUp: function () {
},
tearDown: function () {
delete this.list;
},
'ModelLists should have a `model` property': function () {
},
'destructor should detach all models from the list': function () {
}
}));
// -- ModelList: Methods -------------------------------------------------------
name: 'Methods',
setUp: function () {
ATTRS: {
}
});
this.createList = function (modelClass) {
};
this.createModel = function (config) {
};
},
tearDown: function () {
delete this.createList;
delete this.createModel;
delete this.TestList;
delete this.TestModel;
},
'add() should add a model to the list': function () {
var list = this.createList(),
model = this.createModel(),
},
'add() should add an array of models to the list': function () {
var list = this.createList(),
},
'add() should support models created in other windows': function () {
var list = this.createList(),
},
'comparator() should be undefined by default': function () {
},
'models should be added in the proper position based on the comparator': function () {
var list = this.createList();
};
},
'create() should create or update a model, then add it to the list': function () {
var list = this.createList(),
model = this.createModel();
},
'create() should call the callback if one is provided': function () {
var calls = 0,
list = this.createList();
calls += 1;
});
},
'create() should pass an error to the callback if one occurs': function () {
var calls = 0,
list = this.createList(),
model = this.createModel();
callback('Oh noes!');
};
calls += 1;
});
},
'create() should support models created in other windows': function () {
var list = this.createList(),
},
'filter() should filter the list and return an array': function () {
var list = this.createList(),
});
},
'filter() should accept a custom `this` object': function () {
var list = this.createList(),
obj = {};
}, obj);
},
'filter() should return an empty array if the callback never returns a truthy value': function () {
var list = this.createList();
},
'get() should return an array of attribute values from all models in the list': function () {
var list = this.createList();
},
'get() should return a list attribute if there is one': function () {
var list = this.createList();
},
'getAsHTML() should return an array of HTML-escaped attribute values': function () {
var list = this.createList();
},
'getAsHTML() should return a list attribute if there is one': function () {
var list = this.createList();
},
'getAsURL() should return an array of URL-encoded attribute values': function () {
var list = this.createList();
},
'getAsURL() should return a list attribute if there is one': function () {
var list = this.createList();
},
'getByClientId() should look up a model by its clientId': function () {
var list = this.createList(),
},
'getById() should look up a model by its id': function () {
var list = this.createList(),
},
'getById() should work with numeric ids': function () {
var list = this.createList(),
},
'getById() should work with custom ids': function () {
idAttribute: 'customId'
}, {
ATTRS: {
}
}),
},
'invoke() should call the named method on every model in the list': function () {
var list = this.createList(),
ArrayAssert.itemsAreSame(list.toArray(), results, 'invoke should return an array of return values');
},
'item() should return the model at the specified index': function () {
var list = this.createList();
},
'load() should delegate to sync()': function () {
var calls = 0,
list = this.createList(),
opts = {};
calls += 1;
callback();
};
},
'load() should be chainable and should call the callback if one was provided': function () {
var calls = 0,
list = this.createList();
calls += 1;
}));
calls += 1;
}));
},
'map() should execute a function on every model in the list and return an array of return values': function () {
var list = this.createList(),
obj = {},
}, obj);
},
'parse() should parse a JSON string and return an object': function () {
var list = this.createList(),
},
'parse() should not try to parse non-strings': function () {
var list = this.createList(),
},
'reset() should replace all models in the list': function () {
var list = this.createList(),
// Removed models should be cleanly detached.
// And we should be able to re-add them.
},
'reset() should sort the new models in the list': function () {
var list = this.createList();
};
]);
},
'reset() with no args should clear the list': function () {
var list = this.createList(),
},
'reset() should support models created in other windows': function () {
var list = this.createList(),
},
'remove() should remove a single model from the list': function () {
var list = this.createList();
},
'remove() should remove an array of models from the list': function () {
var list = this.createList(),
},
// 'set() should set a single attribute value on all models in the list': function () {
//
// },
//
// 'setAttrs() should set multiple attribute values on all models in the list': function () {
//
// },
'sort() should re-sort the list': function () {
var list = this.createList();
};
},
'sync() should just call the supplied callback by default': function () {
var calls = 0,
list = this.createList();
calls += 1;
});
},
'toArray() should return an array containing all the models in the list': function () {
var list = this.createList(),
},
'toJSON() should return an array of model hashes': function () {
var list = this.createList(),
}
}));
// -- ModelList: Events --------------------------------------------------------
name: 'Events',
setUp: function () {
ATTRS: {
}
});
this.createList = function (modelClass) {
};
this.createModel = function (config) {
};
},
tearDown: function () {
delete this.createList;
delete this.createModel;
delete this.TestList;
delete this.TestModel;
},
'`add` event should fire when a model is added': function () {
var calls = 0,
list = this.createList(),
model = this.createModel();
calls += 1;
});
calls += 1;
});
},
'`add` event should be preventable': function () {
var calls = 0,
list = this.createList();
calls += 1;
e.preventDefault();
});
});
},
'`add` event should not fire when a model is added silently': function () {
var list = this.createList();
});
},
'`change` event should bubble up from models': function () {
var calls = 0,
list = this.createList(),
calls += 1;
});
},
'`create` event should fire when a model is created': function () {
var calls = 0,
list = this.createList(),
model = this.createModel();
calls += 1;
});
});
},
'`create` event should receive options passed to the create() method': function () {
var calls = 0,
list = this.createList(),
model = this.createModel();
calls += 1;
});
},
'`error` event should bubble up from models': function () {
var calls = 0,
list = this.createList(),
callback('fail!');
}
};
calls += 1;
});
},
'`error` event should fire when a duplicate model is added': function () {
var calls = 0,
list = this.createList(),
model = this.createModel();
calls += 1;
});
},
"`error` event should fire when a model that isn't in the list is removed": function () {
var calls = 0,
list = this.createList(),
model = this.createModel();
calls += 1;
});
},
"`error` event should fire when a sync layer response can't be parsed": function () {
var calls = 0,
list = this.createList(),
response = 'foo bar baz';
calls += 1;
});
},
'`reset` event should fire when the list is reset or sorted': function () {
var calls = 0,
list = this.createList(),
calls += 1;
});
calls += 1;
});
};
},
'`reset` event facade should contain sorted models': function () {
var calls = 0,
list = this.createList();
};
var values = [];
calls += 1;
});
});
]);
},
'`reset` event should be preventable': function () {
var calls = 0,
list = this.createList();
calls += 1;
e.preventDefault();
});
});
},
'`reset` event should not fire when the list is reset silently': function () {
var list = this.createList();
});
},
'`remove` event should fire when a model is removed': function () {
var calls = 0,
list = this.createList(),
calls += 1;
});
calls += 1;
});
},
'`remove` event should be preventable': function () {
var calls = 0,
list = this.createList();
calls += 1;
e.preventDefault();
});
});
},
'`remove` event should not fire when a model is removed silently': function () {
var list = this.createList();
});
}
}));
}, '@VERSION@', {
});