|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var sinon = require('sinon'); |
| 4 | +var expect = require('chai').expect; |
| 5 | + |
| 6 | +describe('Console list', function() { |
| 7 | + var Hexo = require('../../../lib/hexo'); |
| 8 | + var hexo = new Hexo(__dirname); |
| 9 | + var Post = hexo.model('Post'); |
| 10 | + |
| 11 | + var listPosts = require('../../../lib/plugins/console/list/post').bind(hexo); |
| 12 | + |
| 13 | + before(function() { |
| 14 | + var log = console.log; |
| 15 | + sinon.stub(console, 'log', function() { |
| 16 | + return log.apply(log, arguments); |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + after(function() { |
| 21 | + console.log.restore(); |
| 22 | + }); |
| 23 | + |
| 24 | + it('no post', function() { |
| 25 | + listPosts(); |
| 26 | + expect(console.log.calledWith(sinon.match('Date'))).to.be.true; |
| 27 | + expect(console.log.calledWith(sinon.match('Title'))).to.be.true; |
| 28 | + expect(console.log.calledWith(sinon.match('Path'))).to.be.true; |
| 29 | + expect(console.log.calledWith(sinon.match('Category'))).to.be.true; |
| 30 | + expect(console.log.calledWith(sinon.match('Tags'))).to.be.true; |
| 31 | + expect(console.log.calledWith(sinon.match('No posts.'))).to.be.true; |
| 32 | + }); |
| 33 | + |
| 34 | + it('post', function() { |
| 35 | + var posts = [ |
| 36 | + {source: 'foo', slug: 'foo', title: 'Its', date: 1e8}, |
| 37 | + {source: 'bar', slug: 'bar', title: 'Math', date: 1e8 + 1}, |
| 38 | + {source: 'baz', slug: 'baz', title: 'Dude', date: 1e8 - 1} |
| 39 | + ]; |
| 40 | + return hexo.init() |
| 41 | + .then(function() { |
| 42 | + return Post.insert(posts); |
| 43 | + }).then(function() { |
| 44 | + hexo.locals.invalidate(); |
| 45 | + }) |
| 46 | + .then(function() { |
| 47 | + listPosts(); |
| 48 | + expect(console.log.calledWith(sinon.match('Date'))).to.be.true; |
| 49 | + expect(console.log.calledWith(sinon.match('Title'))).to.be.true; |
| 50 | + expect(console.log.calledWith(sinon.match('Path'))).to.be.true; |
| 51 | + expect(console.log.calledWith(sinon.match('Category'))).to.be.true; |
| 52 | + expect(console.log.calledWith(sinon.match('Tags'))).to.be.true; |
| 53 | + for (var i = 0; i < posts.length; i++) { |
| 54 | + expect(console.log.calledWith(sinon.match(posts[i].source))).to.be.true; |
| 55 | + expect(console.log.calledWith(sinon.match(posts[i].slug))).to.be.true; |
| 56 | + expect(console.log.calledWith(sinon.match(posts[i].title))).to.be.true; |
| 57 | + } |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
0 commit comments