mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 06:25:50 +01:00
add tests for top topics
fix popular page displaying 18 topics per page
This commit is contained in:
@@ -57,7 +57,7 @@ module.exports = function (Categories) {
|
|||||||
function (results, next) {
|
function (results, next) {
|
||||||
var totalPinnedCount = results.pinnedTids.length;
|
var totalPinnedCount = results.pinnedTids.length;
|
||||||
|
|
||||||
pinnedTids = results.pinnedTids.slice(data.start, data.stop === -1 ? undefined : data.stop + 1);
|
pinnedTids = results.pinnedTids.slice(data.start, data.stop !== -1 ? data.stop + 1 : undefined);
|
||||||
|
|
||||||
var pinnedCount = pinnedTids.length;
|
var pinnedCount = pinnedTids.length;
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ module.exports = function (Topics) {
|
|||||||
function (topics, next) {
|
function (topics, next) {
|
||||||
tids = topics.filter(function (topic) {
|
tids = topics.filter(function (topic) {
|
||||||
return topic && parseInt(topic.deleted, 10) !== 1;
|
return topic && parseInt(topic.deleted, 10) !== 1;
|
||||||
}).sort(sortPopular).slice(start, stop !== -1 ? stop - 1 : undefined).map(function (topic) {
|
}).sort(sortPopular).slice(start, stop !== -1 ? stop + 1 : undefined).map(function (topic) {
|
||||||
return topic.tid;
|
return topic.tid;
|
||||||
});
|
});
|
||||||
privileges.topics.filterTids('read', tids, uid, next);
|
privileges.topics.filterTids('read', tids, uid, next);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
function (tids, next) {
|
function (tids, next) {
|
||||||
recentTopics.topicCount = tids.length;
|
recentTopics.topicCount = tids.length;
|
||||||
tids = tids.slice(start, stop + 1);
|
tids = tids.slice(start, stop !== -1 ? stop + 1 : undefined);
|
||||||
Topics.getTopicsByTids(tids, uid, next);
|
Topics.getTopicsByTids(tids, uid, next);
|
||||||
},
|
},
|
||||||
function (topicData, next) {
|
function (topicData, next) {
|
||||||
|
|||||||
@@ -35,13 +35,7 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
function (categoryTids, next) {
|
function (categoryTids, next) {
|
||||||
tids = _.uniq(tids.concat(categoryTids));
|
tids = _.uniq(tids.concat(categoryTids)).slice(start, stop !== -1 ? stop + 1 : undefined);
|
||||||
if (stop === -1) {
|
|
||||||
tids = tids.slice(start);
|
|
||||||
} else {
|
|
||||||
tids = tids.slice(start, stop + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Topics.getTopicsByTids(tids, uid, next);
|
Topics.getTopicsByTids(tids, uid, next);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
function (tids, next) {
|
function (tids, next) {
|
||||||
topTopics.topicCount = tids.length;
|
topTopics.topicCount = tids.length;
|
||||||
tids = tids.slice(start, stop + 1);
|
tids = tids.slice(start, stop !== -1 ? stop + 1 : undefined);
|
||||||
Topics.getTopicsByTids(tids, uid, next);
|
Topics.getTopicsByTids(tids, uid, next);
|
||||||
},
|
},
|
||||||
function (topicData, next) {
|
function (topicData, next) {
|
||||||
|
|||||||
@@ -42,11 +42,7 @@ module.exports = function (Topics) {
|
|||||||
return next(null, []);
|
return next(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.stop === -1) {
|
tids = tids.slice(params.start, params.stop !== -1 ? params.stop + 1 : undefined);
|
||||||
tids = tids.slice(params.start);
|
|
||||||
} else {
|
|
||||||
tids = tids.slice(params.start, params.stop + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Topics.getTopicsByTids(tids, params.uid, next);
|
Topics.getTopicsByTids(tids, params.uid, next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1823,4 +1823,20 @@ describe('Topic\'s', function () {
|
|||||||
], done);
|
], done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('top topics', function () {
|
||||||
|
it('should get top topics in category', function (done) {
|
||||||
|
var filters = ['', 'watched', 'unreplied', 'new'];
|
||||||
|
async.map(filters, function (filter, next) {
|
||||||
|
topics.getTopTopics(topic.categoryId, topic.userId, 0, -1, filter, next);
|
||||||
|
}, function (err, data) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert(data);
|
||||||
|
data.forEach(function (filterTopics) {
|
||||||
|
assert(Array.isArray(filterTopics.topics));
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user