2017-03-06 12:46:46 +00:00
|
|
|
var should = require('should/as-function')
|
|
|
|
var Album = require('../../src/model/album')
|
|
|
|
var fixtures = require('../fixtures')
|
|
|
|
|
|
|
|
describe('Album', function () {
|
|
|
|
describe('stats', function () {
|
|
|
|
describe('single level stats', function () {
|
|
|
|
it('has no nested albums', function () {
|
|
|
|
var a = new Album({})
|
|
|
|
a.finalize()
|
|
|
|
should(a.stats.albums).eql(0)
|
2017-02-05 07:38:44 +00:00
|
|
|
})
|
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('calculates counts for a single level', function () {
|
2017-02-05 07:38:44 +00:00
|
|
|
var a = new Album({
|
|
|
|
files: [
|
|
|
|
fixtures.photo(), fixtures.photo(),
|
|
|
|
fixtures.photo(), fixtures.photo(),
|
2017-03-06 12:46:46 +00:00
|
|
|
fixtures.video(), fixtures.video()
|
2017-02-05 07:38:44 +00:00
|
|
|
]
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
|
|
|
a.finalize()
|
|
|
|
should(a.stats.photos).eql(4)
|
|
|
|
should(a.stats.videos).eql(2)
|
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('calculates from/to dates', function () {
|
2017-02-05 07:38:44 +00:00
|
|
|
var a = new Album({
|
|
|
|
files: [
|
|
|
|
fixtures.photo({date: '2016-09-14'}),
|
|
|
|
fixtures.photo({date: '2016-09-02'}),
|
2017-03-06 12:46:46 +00:00
|
|
|
fixtures.photo({date: '2016-10-21'})
|
2017-02-05 07:38:44 +00:00
|
|
|
]
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
|
|
|
a.finalize()
|
|
|
|
should(a.stats.fromDate).eql(fixtures.date('2016-09-02').getTime())
|
|
|
|
should(a.stats.toDate).eql(fixtures.date('2016-10-21').getTime())
|
|
|
|
})
|
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
describe('nested albums stats', function () {
|
|
|
|
it('counts all nested albums', function () {
|
2017-02-05 07:38:44 +00:00
|
|
|
var root = new Album({
|
|
|
|
albums: [new Album('a'), new Album('b')]
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
|
|
|
root.finalize()
|
|
|
|
should(root.stats.albums).eql(2)
|
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('counts all nested photos', function () {
|
2017-02-05 07:38:44 +00:00
|
|
|
var root = new Album({
|
|
|
|
files: [fixtures.photo()],
|
|
|
|
albums: [
|
|
|
|
new Album({
|
|
|
|
files: [fixtures.photo(), fixtures.photo()]
|
|
|
|
})
|
|
|
|
]
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
|
|
|
root.finalize()
|
|
|
|
should(root.stats.photos).eql(3)
|
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('counts all nested photos', function () {
|
2017-02-05 07:38:44 +00:00
|
|
|
var root = new Album({
|
|
|
|
files: [fixtures.video()],
|
|
|
|
albums: [
|
|
|
|
new Album({
|
|
|
|
files: [fixtures.video(), fixtures.video()]
|
|
|
|
})
|
|
|
|
]
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
|
|
|
root.finalize()
|
|
|
|
should(root.stats.videos).eql(3)
|
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('calculates from/to dates across all albums', function () {
|
2017-02-05 07:38:44 +00:00
|
|
|
var a = new Album({
|
|
|
|
files: [fixtures.photo({date: '2016-09-14'})],
|
|
|
|
albums: [
|
|
|
|
new Album({
|
|
|
|
files: [fixtures.photo({date: '2016-09-02'})],
|
|
|
|
albums: [new Album({
|
|
|
|
files: [fixtures.photo({date: '2016-10-21'})]
|
|
|
|
})]
|
|
|
|
})
|
|
|
|
]
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
|
|
|
a.finalize()
|
|
|
|
should(a.stats.fromDate).eql(fixtures.date('2016-09-02').getTime())
|
|
|
|
should(a.stats.toDate).eql(fixtures.date('2016-10-21').getTime())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
describe('summary', function () {
|
|
|
|
it('creates a summary with a single photo', function () {
|
|
|
|
var a = new Album('single')
|
2017-02-05 07:38:44 +00:00
|
|
|
a.files = [
|
|
|
|
fixtures.photo()
|
2017-03-06 12:46:46 +00:00
|
|
|
]
|
|
|
|
a.finalize()
|
2017-02-05 07:38:44 +00:00
|
|
|
should(a.summary).eql('1 photo')
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('creates a summary with a single video', function () {
|
|
|
|
var a = new Album('single')
|
2017-02-05 07:38:44 +00:00
|
|
|
a.files = [
|
|
|
|
fixtures.video()
|
2017-03-06 12:46:46 +00:00
|
|
|
]
|
|
|
|
a.finalize()
|
2017-02-05 07:38:44 +00:00
|
|
|
should(a.summary).eql('1 video')
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('creates a summary with a single album', function () {
|
|
|
|
var a = new Album('single')
|
|
|
|
a.albums = [new Album('nested')]
|
|
|
|
a.finalize()
|
2017-02-05 07:38:44 +00:00
|
|
|
should(a.summary).eql('1 album')
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('creates a summary with several photos', function () {
|
|
|
|
var a = new Album('single')
|
2017-02-05 07:38:44 +00:00
|
|
|
a.files = [
|
2017-03-06 12:46:46 +00:00
|
|
|
fixtures.photo(), fixtures.photo()
|
|
|
|
]
|
|
|
|
a.finalize()
|
2017-02-05 07:38:44 +00:00
|
|
|
should(a.summary).eql('2 photos')
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('creates a summary with several videos', function () {
|
|
|
|
var a = new Album('single')
|
2017-02-05 07:38:44 +00:00
|
|
|
a.files = [
|
2017-03-06 12:46:46 +00:00
|
|
|
fixtures.video(), fixtures.video()
|
|
|
|
]
|
|
|
|
a.finalize()
|
2017-02-05 07:38:44 +00:00
|
|
|
should(a.summary).eql('2 videos')
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('creates a summary with several albums', function () {
|
|
|
|
var a = new Album('single')
|
|
|
|
a.albums = [new Album('nested 1'), new Album('nested 2')]
|
|
|
|
a.finalize()
|
2017-02-05 07:38:44 +00:00
|
|
|
should(a.summary).eql('2 albums')
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
2017-02-05 07:38:44 +00:00
|
|
|
|
2017-03-06 12:46:46 +00:00
|
|
|
it('creates a summary with a mix of albums, photos and videos', function () {
|
|
|
|
var a = new Album('single')
|
|
|
|
a.albums = [new Album('nested')]
|
2017-02-05 07:38:44 +00:00
|
|
|
a.files = [
|
|
|
|
fixtures.photo(), fixtures.photo(),
|
2017-03-06 12:46:46 +00:00
|
|
|
fixtures.video(), fixtures.video()
|
|
|
|
]
|
|
|
|
a.finalize()
|
2017-02-05 07:38:44 +00:00
|
|
|
should(a.summary).eql('1 album, 2 photos, 2 videos')
|
2017-03-06 12:46:46 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|