mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 20:44:53 -04:00
Add tests.
This commit is contained in:
parent
7311cc8e4b
commit
022f715b98
5 changed files with 45 additions and 11 deletions
|
@ -43,7 +43,7 @@ modulejs.define('ext/filter', ['_', '$', 'core/event', 'core/location', 'core/re
|
|||
|
||||
$filter.removeClass('pending');
|
||||
view.setHint('noMatch');
|
||||
view.setItems('filter', matchedItems);
|
||||
view.setItems(matchedItems);
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
|
|
@ -41,7 +41,7 @@ modulejs.define('ext/search', ['_', '$', 'core/event', 'core/location', 'core/re
|
|||
|
||||
$search.removeClass('pending');
|
||||
view.setHint('noMatch');
|
||||
view.setItems('search', _.map(response.search, function (item) {
|
||||
view.setItems(_.map(response.search, function (item) {
|
||||
|
||||
return Item.get(item);
|
||||
}));
|
||||
|
|
|
@ -84,7 +84,7 @@ modulejs.define('view/view', ['_', '$', 'core/event', 'core/format', 'core/locat
|
|||
event.pub('item.mouseleave', item);
|
||||
}
|
||||
|
||||
function setItems(context, items) {
|
||||
function setItems(items) {
|
||||
|
||||
var removed = _.map($items.find('.item'), function (item) {
|
||||
|
||||
|
@ -103,7 +103,7 @@ modulejs.define('view/view', ['_', '$', 'core/event', 'core/format', 'core/locat
|
|||
event.pub('view.changed', items, removed);
|
||||
}
|
||||
|
||||
function changeItems(context, add, remove) {
|
||||
function changeItems(add, remove) {
|
||||
|
||||
_.each(add, function (item) {
|
||||
|
||||
|
@ -158,7 +158,7 @@ modulejs.define('view/view', ['_', '$', 'core/event', 'core/format', 'core/locat
|
|||
});
|
||||
|
||||
setHint('empty');
|
||||
setItems('location.changed', items);
|
||||
setItems(items);
|
||||
}
|
||||
|
||||
function onLocationRefreshed(item, added, removed) {
|
||||
|
@ -173,7 +173,7 @@ modulejs.define('view/view', ['_', '$', 'core/event', 'core/format', 'core/locat
|
|||
});
|
||||
|
||||
setHint('empty');
|
||||
changeItems('location.refreshed', add, removed);
|
||||
changeItems(add, removed);
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
|
|
@ -96,7 +96,7 @@ describe('module \'' + ID + '\'', function () {
|
|||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.ok(_.isFunction(instance.set));
|
||||
assert.isTrue(_.isFunction(instance.set));
|
||||
});
|
||||
|
||||
it('works', function () {
|
||||
|
|
|
@ -26,6 +26,9 @@ describe('module \'' + ID + '\'', function () {
|
|||
icon: sinon.stub().returns(util.uniqId())
|
||||
};
|
||||
this.xSettings = {view: {
|
||||
binaryPrefix: false,
|
||||
hideFolders: false,
|
||||
hideParentFolder: false,
|
||||
setParentFolderLabels: false
|
||||
}};
|
||||
this.xContent = {$el: null};
|
||||
|
@ -109,6 +112,12 @@ describe('module \'' + ID + '\'', function () {
|
|||
assert.lengthOf($('#view > #items'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #view-hint to #view', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#view > #view-hint'), 1);
|
||||
});
|
||||
|
||||
it('sets default metric', function () {
|
||||
|
||||
this.applyFn();
|
||||
|
@ -165,7 +174,15 @@ describe('module \'' + ID + '\'', function () {
|
|||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.ok(_.isFunction(instance.setItems));
|
||||
assert.isTrue(_.isFunction(instance.setItems));
|
||||
});
|
||||
|
||||
it('publishes view.changed', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
instance.setItems();
|
||||
assert.isTrue(this.xEvent.pub.calledOnce);
|
||||
assert.strictEqual(this.xEvent.pub.lastCall.args[0], 'view.changed');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -174,7 +191,7 @@ describe('module \'' + ID + '\'', function () {
|
|||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.ok(_.isFunction(instance.changeItems));
|
||||
assert.isTrue(_.isFunction(instance.changeItems));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -183,7 +200,7 @@ describe('module \'' + ID + '\'', function () {
|
|||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.ok(_.isFunction(instance.setLocation));
|
||||
assert.isTrue(_.isFunction(instance.setLocation));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -192,7 +209,24 @@ describe('module \'' + ID + '\'', function () {
|
|||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.ok(_.isFunction(instance.setHint));
|
||||
assert.isTrue(_.isFunction(instance.setHint));
|
||||
});
|
||||
|
||||
it('sets correct class to #view-hint', function () {
|
||||
|
||||
var key = util.uniqId();
|
||||
var instance = this.applyFn();
|
||||
instance.setHint(key);
|
||||
assert.strictEqual($('#view-hint').attr('class'), 'l10n-' + key);
|
||||
});
|
||||
|
||||
it('removes all other classes from #view-hint', function () {
|
||||
|
||||
var key = util.uniqId();
|
||||
var instance = this.applyFn();
|
||||
$('#view-hint').addClass('a');
|
||||
instance.setHint(key);
|
||||
assert.strictEqual($('#view-hint').attr('class'), 'l10n-' + key);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue