mirror of
https://github.com/thumbsup/thumbsup
synced 2024-11-03 15:40:14 +00:00
test(all): add unit tests for Album and Problem
This commit is contained in:
parent
cc7abdf0ac
commit
fb4c4fb89f
@ -28,3 +28,12 @@ debug.assertContains = function (expected) {
|
||||
throw new Error(`Expected log to contain: ${expected}`)
|
||||
}
|
||||
}
|
||||
|
||||
debug.assertNotContains = function (expected) {
|
||||
const matches = debug.recorded.filter(message => {
|
||||
return message.includes(expected)
|
||||
})
|
||||
if (matches.length > 0) {
|
||||
throw new Error(`Expected log not to contain: ${expected}`)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
var should = require('should/as-function')
|
||||
var Album = require('../../src/model/album')
|
||||
var fixtures = require('../fixtures')
|
||||
var path = require('path')
|
||||
const moment = require('moment')
|
||||
const path = require('path')
|
||||
const should = require('should/as-function')
|
||||
const Album = require('../../src/model/album')
|
||||
const fixtures = require('../fixtures')
|
||||
|
||||
describe('Album', function () {
|
||||
describe('options', function () {
|
||||
@ -180,6 +181,15 @@ describe('Album', function () {
|
||||
should(album.files).eql([c, b, a])
|
||||
})
|
||||
|
||||
it('can sort media by date', function () {
|
||||
const album = albumWithFileDates(['2010-10-15', '2010-01-01', '2010-03-24'])
|
||||
album.finalize({sortMediaBy: 'date'})
|
||||
const datesInAlbum = album.files.map(f => {
|
||||
return moment(f.meta.date).format('YYYY-MM-DD')
|
||||
})
|
||||
should(datesInAlbum).eql(['2010-01-01', '2010-03-24', '2010-10-15'])
|
||||
})
|
||||
|
||||
it('sorts nested albums too', function () {
|
||||
var nested = new Album({title: 'nested',
|
||||
files: [
|
||||
|
52
test/problems.spec.js
Normal file
52
test/problems.spec.js
Normal file
@ -0,0 +1,52 @@
|
||||
const should = require('should/as-function')
|
||||
const Problems = require('../src/problems.js')
|
||||
const debug = require('debug')
|
||||
const sinon = require('sinon')
|
||||
|
||||
describe('Problems', function () {
|
||||
beforeEach(() => {
|
||||
console.warnOld = console.log
|
||||
console.warn = sinon.spy()
|
||||
debug.reset()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
console.warn = console.warnOld
|
||||
})
|
||||
|
||||
it('prints a summary with the number of errors', () => {
|
||||
const problems = new Problems()
|
||||
problems.addFile('holidays/IMG_0001.jpg')
|
||||
problems.addFile('holidays/IMG_0002.jpg')
|
||||
problems.print()
|
||||
should(console.warn.args.length).above(0)
|
||||
const message = console.warn.args[0][0]
|
||||
should(message.indexOf('an issue with 2 files')).above(-1)
|
||||
console.warn = console.warnOld
|
||||
})
|
||||
|
||||
it('prints the list of files with errors', () => {
|
||||
const problems = new Problems()
|
||||
problems.addFile('holidays/IMG_0001.jpg')
|
||||
problems.addFile('holidays/IMG_0002.jpg')
|
||||
problems.print()
|
||||
debug.assertContains('were not processed')
|
||||
debug.assertContains('holidays/IMG_0001.jpg')
|
||||
debug.assertContains('holidays/IMG_0002.jpg')
|
||||
console.warn = console.warnOld
|
||||
})
|
||||
|
||||
it('does not print the summary if there are no errors', () => {
|
||||
const problems = new Problems()
|
||||
problems.print()
|
||||
should(console.warn.args).eql([])
|
||||
console.warn = console.warnOld
|
||||
})
|
||||
|
||||
it('does not print the detailed log if there are no errors', () => {
|
||||
const problems = new Problems()
|
||||
problems.print()
|
||||
debug.assertNotContains('were not processed')
|
||||
console.warn = console.warnOld
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user