mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	admin navigation test
This commit is contained in:
		| @@ -1,14 +1,14 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var navigationController = {}; | ||||
| var async = require('async'); | ||||
|  | ||||
| var navigationAdmin = require('../../navigation/admin'); | ||||
| var navigationController = module.exports; | ||||
|  | ||||
| navigationController.get = function (req, res, next) { | ||||
| 	require('../../navigation/admin').getAdmin(function (err, data) { | ||||
| 		if (err) { | ||||
| 			return next(err); | ||||
| 		} | ||||
|  | ||||
|  | ||||
| 	async.waterfall([ | ||||
| 		navigationAdmin.getAdmin, | ||||
| 		function (data) { | ||||
| 			data.enabled.forEach(function (enabled, index) { | ||||
| 				enabled.index = index; | ||||
| 				enabled.selected = index === 0; | ||||
| @@ -17,7 +17,6 @@ navigationController.get = function (req, res, next) { | ||||
| 			data.navigation = data.enabled.slice(); | ||||
|  | ||||
| 			res.render('admin/general/navigation', data); | ||||
| 	}); | ||||
| 		}, | ||||
| 	], next); | ||||
| }; | ||||
|  | ||||
| module.exports = navigationController; | ||||
|   | ||||
| @@ -48,17 +48,18 @@ admin.getAdmin = function (callback) { | ||||
| }; | ||||
|  | ||||
| admin.get = function (callback) { | ||||
| 	db.getSortedSetRange('navigation:enabled', 0, -1, function (err, data) { | ||||
| 		if (err) { | ||||
| 			return callback(err); | ||||
| 		} | ||||
|  | ||||
| 	async.waterfall([ | ||||
| 		function (next) { | ||||
| 			db.getSortedSetRange('navigation:enabled', 0, -1, next); | ||||
| 		}, | ||||
| 		function (data, next) { | ||||
| 			data = data.map(function (item, idx) { | ||||
| 				return JSON.parse(item)[idx]; | ||||
| 			}); | ||||
|  | ||||
| 		callback(null, data); | ||||
| 	}); | ||||
| 			next(null, data); | ||||
| 		}, | ||||
| 	], callback); | ||||
| }; | ||||
|  | ||||
| function getAvailable(callback) { | ||||
|   | ||||
| @@ -1,21 +1,21 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var async = require('async'); | ||||
| var nconf = require('nconf'); | ||||
|  | ||||
| var admin = require('./admin'); | ||||
| var translator = require('../translator'); | ||||
|  | ||||
| var navigation = {}; | ||||
| var navigation = module.exports; | ||||
|  | ||||
| navigation.get = function (callback) { | ||||
| 	if (admin.cache) { | ||||
| 		return callback(null, admin.cache); | ||||
| 	} | ||||
|  | ||||
| 	admin.get(function (err, data) { | ||||
| 		if (err) { | ||||
| 			return callback(err); | ||||
| 		} | ||||
|  | ||||
| 	async.waterfall([ | ||||
| 		admin.get, | ||||
| 		function (data, next) { | ||||
| 			data = data.filter(function (item) { | ||||
| 				return item && item.enabled; | ||||
| 			}).map(function (item) { | ||||
| @@ -33,8 +33,9 @@ navigation.get = function (callback) { | ||||
|  | ||||
| 			admin.cache = data; | ||||
|  | ||||
| 		callback(null, data); | ||||
| 	}); | ||||
| 			next(null, data); | ||||
| 		}, | ||||
| 	], callback); | ||||
| }; | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -303,12 +303,20 @@ describe('Admin Controllers', function () { | ||||
| 	}); | ||||
|  | ||||
| 	it('should load /admin/general/navigation', function (done) { | ||||
| 		var navigation = require('../src/navigation/admin'); | ||||
| 		var data = require('../install/data/navigation.json'); | ||||
|  | ||||
| 		navigation.save(data, function (err) { | ||||
| 			assert.ifError(err); | ||||
| 			request(nconf.get('url') + '/api/admin/general/navigation', { jar: jar, json: true }, function (err, res, body) { | ||||
| 				assert.ifError(err); | ||||
| 				assert(body); | ||||
| 				assert(body.available); | ||||
| 				assert(body.enabled); | ||||
| 				done(); | ||||
| 			}); | ||||
| 		}); | ||||
| 	}); | ||||
|  | ||||
| 	it('should load /admin/development/info', function (done) { | ||||
| 		request(nconf.get('url') + '/api/admin/development/info', { jar: jar, json: true }, function (err, res, body) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user