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