refactor(test): replace var with const in tests files when appropriate

pull/134/head
Romain 6 years ago
parent e8a6d179f1
commit 73672ce4dd

@ -6,13 +6,13 @@ describe('Album', function () {
describe('stats', function () {
describe('single level stats', function () {
it('has no nested albums', function () {
var a = new Album({})
const a = new Album({})
a.finalize()
should(a.stats.albums).eql(0)
})
it('calculates counts for a single level', function () {
var a = new Album({
const a = new Album({
files: [
fixtures.photo(), fixtures.photo(),
fixtures.photo(), fixtures.photo(),
@ -25,7 +25,7 @@ describe('Album', function () {
})
it('calculates from/to dates', function () {
var a = new Album({
const a = new Album({
files: [
fixtures.photo({date: '2016-09-14'}),
fixtures.photo({date: '2016-09-02'}),
@ -40,7 +40,7 @@ describe('Album', function () {
describe('nested albums stats', function () {
it('counts all nested albums', function () {
var root = new Album({
const root = new Album({
albums: [new Album('a'), new Album('b')]
})
root.finalize()
@ -48,7 +48,7 @@ describe('Album', function () {
})
it('counts all nested photos', function () {
var root = new Album({
const root = new Album({
files: [fixtures.photo()],
albums: [
new Album({
@ -61,7 +61,7 @@ describe('Album', function () {
})
it('counts all nested photos', function () {
var root = new Album({
const root = new Album({
files: [fixtures.video()],
albums: [
new Album({
@ -74,7 +74,7 @@ describe('Album', function () {
})
it('calculates from/to dates across all albums', function () {
var a = new Album({
const a = new Album({
files: [fixtures.photo({date: '2016-09-14'})],
albums: [
new Album({
@ -94,7 +94,7 @@ describe('Album', function () {
describe('summary', function () {
it('creates a summary with a single photo', function () {
var a = new Album('single')
const a = new Album('single')
a.files = [
fixtures.photo()
]
@ -103,7 +103,7 @@ describe('Album', function () {
})
it('creates a summary with a single video', function () {
var a = new Album('single')
const a = new Album('single')
a.files = [
fixtures.video()
]
@ -112,14 +112,14 @@ describe('Album', function () {
})
it('creates a summary with a single album', function () {
var a = new Album('single')
const a = new Album('single')
a.albums = [new Album('nested')]
a.finalize()
should(a.summary).eql('1 album')
})
it('creates a summary with several photos', function () {
var a = new Album('single')
const a = new Album('single')
a.files = [
fixtures.photo(), fixtures.photo()
]
@ -128,7 +128,7 @@ describe('Album', function () {
})
it('creates a summary with several videos', function () {
var a = new Album('single')
const a = new Album('single')
a.files = [
fixtures.video(), fixtures.video()
]
@ -137,14 +137,14 @@ describe('Album', function () {
})
it('creates a summary with several albums', function () {
var a = new Album('single')
const a = new Album('single')
a.albums = [new Album('nested 1'), new Album('nested 2')]
a.finalize()
should(a.summary).eql('2 albums')
})
it('creates a summary with a mix of albums, photos and videos', function () {
var a = new Album('single')
const a = new Album('single')
a.albums = [new Album('nested')]
a.files = [
fixtures.photo(), fixtures.photo(),

@ -7,12 +7,12 @@ const fixtures = require('../fixtures')
describe('Album', function () {
describe('options', function () {
it('can pass the title as a single argument', function () {
var a = new Album('Holidays')
const a = new Album('Holidays')
should(a.title).eql('Holidays')
})
it('can pass a full hash of options', function () {
var a = new Album({id: 12, title: 'Holidays'})
const a = new Album({id: 12, title: 'Holidays'})
should(a.id).eql(12)
should(a.title).eql('Holidays')
})
@ -20,14 +20,14 @@ describe('Album', function () {
describe('output paths', function () {
it('sanitises album titles for the file name', function () {
var a = new Album('hello & world')
const a = new Album('hello & world')
should(a.basename).eql('helloworld')
})
it('concatenates nested filenames for uniqueness', function () {
// to avoid having two nested albums called "October" overwrite each other
// note: doesn't use the root title to avoid "home-" or "index-"
var root = new Album({
const root = new Album({
title: 'home',
albums: [
new Album({
@ -53,7 +53,7 @@ describe('Album', function () {
})
it('calculates the output file path', function () {
var root = new Album({
const root = new Album({
title: 'home',
albums: [new Album({title: '2010'})]
})
@ -63,7 +63,7 @@ describe('Album', function () {
})
it('calculates the URL for the browser', function () {
var root = new Album({
const root = new Album({
title: 'home',
albums: [new Album({title: '2010'})]
})
@ -73,7 +73,7 @@ describe('Album', function () {
})
it('calculates the output path with a target folder (slashes match the OS)', function () {
var root = new Album({
const root = new Album({
title: 'home',
albums: [new Album({title: '2010'})]
})
@ -83,7 +83,7 @@ describe('Album', function () {
})
it('calculates the URL with a target folder (always forward slashes)', function () {
var root = new Album({
const root = new Album({
title: 'home',
albums: [new Album({title: '2010'})]
})
@ -95,7 +95,7 @@ describe('Album', function () {
describe('previews', function () {
it('picks the first 10 files as previews', function () {
var a = new Album({files: [
const a = new Album({files: [
fixtures.photo(), fixtures.photo(), fixtures.photo(), fixtures.photo(),
fixtures.photo(), fixtures.photo(), fixtures.photo(), fixtures.photo(),
fixtures.photo(), fixtures.photo(), fixtures.photo(), fixtures.photo()
@ -105,7 +105,7 @@ describe('Album', function () {
})
it('adds <missing> thumbnails to fill', function () {
var a = new Album({files: [
const a = new Album({files: [
fixtures.photo(), fixtures.photo()
]})
a.finalize()
@ -114,7 +114,7 @@ describe('Album', function () {
})
it('uses files from nested albums too', function () {
var a = new Album({
const a = new Album({
title: 'a',
albums: [
new Album({
@ -137,46 +137,46 @@ describe('Album', function () {
describe('sorting', function () {
it('can sort albums by title', function () {
var a = new Album('A')
var b = new Album('B')
var c = new Album('C')
var root = new Album({albums: [c, a, b]})
const a = new Album('A')
const b = new Album('B')
const c = new Album('C')
const root = new Album({albums: [c, a, b]})
root.finalize({sortAlbumsBy: 'title'})
should(root.albums).eql([a, b, c])
})
it('can sort albums by start date', function () {
var startJan = albumWithFileDates(['2010-01-01', '2010-05-01'])
var startFeb = albumWithFileDates(['2010-02-01', '2010-04-01'])
var startMar = albumWithFileDates(['2010-03-01', '2010-03-01'])
var root = new Album({albums: [startFeb, startMar, startJan]})
const startJan = albumWithFileDates(['2010-01-01', '2010-05-01'])
const startFeb = albumWithFileDates(['2010-02-01', '2010-04-01'])
const startMar = albumWithFileDates(['2010-03-01', '2010-03-01'])
const root = new Album({albums: [startFeb, startMar, startJan]})
root.finalize({sortAlbumsBy: 'start-date'})
should(root.albums).eql([startJan, startFeb, startMar])
})
it('can sort albums by end date', function () {
var endMay = albumWithFileDates(['2010-01-01', '2010-05-01'])
var endApr = albumWithFileDates(['2010-02-01', '2010-04-01'])
var endMar = albumWithFileDates(['2010-03-01', '2010-03-01'])
var root = new Album({albums: [endMay, endMar, endApr]})
const endMay = albumWithFileDates(['2010-01-01', '2010-05-01'])
const endApr = albumWithFileDates(['2010-02-01', '2010-04-01'])
const endMar = albumWithFileDates(['2010-03-01', '2010-03-01'])
const root = new Album({albums: [endMay, endMar, endApr]})
root.finalize({sortAlbumsBy: 'end-date'})
should(root.albums).eql([endMar, endApr, endMay])
})
it('can sort media by filename', function () {
var a = fixtures.photo({path: 'a'})
var b = fixtures.photo({path: 'b'})
var c = fixtures.photo({path: 'c'})
var album = new Album({files: [c, a, b]})
const a = fixtures.photo({path: 'a'})
const b = fixtures.photo({path: 'b'})
const c = fixtures.photo({path: 'c'})
const album = new Album({files: [c, a, b]})
album.finalize({sortMediaBy: 'filename'})
should(album.files).eql([a, b, c])
})
it('can sort media by reverse filename', function () {
var a = fixtures.photo({path: 'a'})
var b = fixtures.photo({path: 'b'})
var c = fixtures.photo({path: 'c'})
var album = new Album({files: [c, a, b]})
const a = fixtures.photo({path: 'a'})
const b = fixtures.photo({path: 'b'})
const c = fixtures.photo({path: 'c'})
const album = new Album({files: [c, a, b]})
album.finalize({sortMediaBy: 'filename', sortMediaDirection: 'desc'})
should(album.files).eql([c, b, a])
})
@ -191,12 +191,12 @@ describe('Album', function () {
})
it('sorts nested albums too', function () {
var nested = new Album({title: 'nested',
const nested = new Album({title: 'nested',
files: [
fixtures.photo({path: 'b'}),
fixtures.photo({path: 'a'})
]})
var root = new Album({title: 'home', albums: [nested]})
const root = new Album({title: 'home', albums: [nested]})
root.finalize({sortMediaBy: 'filename'})
should(nested.files[0].path).eql('a')
should(nested.files[1].path).eql('b')
@ -205,10 +205,10 @@ describe('Album', function () {
describe('nested albums basic logic', function () {
it('calculates the depth of every album', function () {
var a = new Album('single')
var b = new Album('single')
var c = new Album('single')
var d = new Album('single')
const a = new Album('single')
const b = new Album('single')
const c = new Album('single')
const d = new Album('single')
a.albums = [b, c]
c.albums = [d]
a.finalize()
@ -219,10 +219,10 @@ describe('Album', function () {
})
it('sets the home flag on the top-level album', function () {
var a = new Album('single')
var b = new Album('single')
var c = new Album('single')
var d = new Album('single')
const a = new Album('single')
const b = new Album('single')
const c = new Album('single')
const d = new Album('single')
a.albums = [b, c]
c.albums = [d]
a.finalize()
@ -233,12 +233,12 @@ describe('Album', function () {
})
it('passes finalising options to all nested albums (e.g. sorting)', function () {
var nested = new Album({title: 'nested',
const nested = new Album({title: 'nested',
files: [
fixtures.photo({path: 'b'}),
fixtures.photo({path: 'a'})
]})
var root = new Album({title: 'home', albums: [nested]})
const root = new Album({title: 'home', albums: [nested]})
root.finalize({sortMediaBy: 'filename'})
should(nested.files[0].path).eql('a')
should(nested.files[1].path).eql('b')
@ -247,7 +247,7 @@ describe('Album', function () {
})
function albumWithFileDates (dates) {
var files = dates.map(function (d) {
const files = dates.map(function (d) {
return fixtures.photo({date: d})
})
return new Album({files: files})

@ -3,14 +3,14 @@ const File = require('../../src/model/file')
describe('File', function () {
it('reads the relative file path', function () {
var file = new File(dbFile({
const file = new File(dbFile({
SourceFile: 'holidays/beach.jpg'
}))
should(file.path).eql('holidays/beach.jpg')
})
it('parses the file modification date', function () {
var file = new File(dbFile({
const file = new File(dbFile({
File: {
FileModifyDate: '2017:01:27 14:38:29+05:00'
}
@ -19,7 +19,7 @@ describe('File', function () {
})
it('can guess the media type for photos', function () {
var file = new File(dbFile({
const file = new File(dbFile({
File: {
MIMEType: 'image/jpeg'
}
@ -28,7 +28,7 @@ describe('File', function () {
})
it('can guess the media type for videos', function () {
var file = new File(dbFile({
const file = new File(dbFile({
File: {
MIMEType: 'video/quicktime'
}
@ -37,7 +37,7 @@ describe('File', function () {
})
it('marks all other data types as unknown', function () {
var file = new File(dbFile({
const file = new File(dbFile({
File: {
MIMEType: 'text/html'
}
@ -46,9 +46,9 @@ describe('File', function () {
})
it('has a boolean flag for videos to simplify templates', function () {
var photo = new File(dbFile({File: {MIMEType: 'image/jpeg'}}))
const photo = new File(dbFile({File: {MIMEType: 'image/jpeg'}}))
should(photo.isVideo).eql(false)
var video = new File(dbFile({File: {MIMEType: 'video/quicktime'}}))
const video = new File(dbFile({File: {MIMEType: 'video/quicktime'}}))
should(video.isVideo).eql(true)
})
})

@ -4,7 +4,7 @@ const output = require('../../src/model/output')
describe('Output paths', function () {
describe('Images', function () {
it('generates a thumbnail', function () {
var o = output.paths('holidays/beach.jpg', 'image', {})
const o = output.paths('holidays/beach.jpg', 'image', {})
should(o.thumbnail).eql({
path: 'media/thumbs/holidays/beach.jpg',
rel: 'photo:thumbnail'
@ -12,7 +12,7 @@ describe('Output paths', function () {
})
it('generates a large "web" version', function () {
var o = output.paths('holidays/beach.jpg', 'image', {})
const o = output.paths('holidays/beach.jpg', 'image', {})
should(o.large).eql({
path: 'media/large/holidays/beach.jpg',
rel: 'photo:large'
@ -20,7 +20,7 @@ describe('Output paths', function () {
})
it('can point downloads to the large version', function () {
var o = output.paths('holidays/beach.jpg', 'image', {
const o = output.paths('holidays/beach.jpg', 'image', {
downloadPhotos: 'large'
})
should(o.download).eql({
@ -30,7 +30,7 @@ describe('Output paths', function () {
})
it('can point downloads to a copy in the output folder', function () {
var o = output.paths('holidays/beach.jpg', 'image', {
const o = output.paths('holidays/beach.jpg', 'image', {
downloadPhotos: 'copy'
})
should(o.download).eql({
@ -40,7 +40,7 @@ describe('Output paths', function () {
})
it('can point downloads to a symlink to the originals', function () {
var o = output.paths('holidays/beach.jpg', 'image', {
const o = output.paths('holidays/beach.jpg', 'image', {
downloadPhotos: 'symlink'
})
should(o.download).eql({
@ -50,7 +50,7 @@ describe('Output paths', function () {
})
it('can point downloads to an existing link', function () {
var o = output.paths('holidays/beach.jpg', 'image', {
const o = output.paths('holidays/beach.jpg', 'image', {
downloadPhotos: 'link',
downloadLinkPrefix: '../myphotos'
})
@ -62,7 +62,7 @@ describe('Output paths', function () {
it('keeps the original image format if the browser supports it', function () {
['jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG', 'gif', 'GIF'].forEach(ext => {
var o = output.paths(`holidays/beach.${ext}`, 'image', {})
const o = output.paths(`holidays/beach.${ext}`, 'image', {})
should(o.thumbnail.path).eql(`media/thumbs/holidays/beach.${ext}`)
})
})
@ -70,7 +70,7 @@ describe('Output paths', function () {
it('converts images to JPEG if not supported', function () {
// some of these formats are supported on certain browser, but we aim for maximum compatibility
['bmp', 'tiff', 'webp'].forEach(ext => {
var o = output.paths(`holidays/beach.${ext}`, 'image', {})
const o = output.paths(`holidays/beach.${ext}`, 'image', {})
should(o.thumbnail.path).eql(`media/thumbs/holidays/beach.jpg`)
})
})
@ -78,7 +78,7 @@ describe('Output paths', function () {
describe('Videos', function () {
it('generates a thumbnail', function () {
var o = output.paths('holidays/seagull.mp4', 'video', {})
const o = output.paths('holidays/seagull.mp4', 'video', {})
should(o.thumbnail).eql({
path: 'media/thumbs/holidays/seagull.jpg',
rel: 'video:thumbnail'
@ -86,7 +86,7 @@ describe('Output paths', function () {
})
it('generates a poster image', function () {
var o = output.paths('holidays/seagull.mp4', 'video', {})
const o = output.paths('holidays/seagull.mp4', 'video', {})
should(o.large).eql({
path: 'media/large/holidays/seagull.jpg',
rel: 'video:poster'
@ -94,7 +94,7 @@ describe('Output paths', function () {
})
it('generates a resized "web" video', function () {
var o = output.paths('holidays/seagull.mp4', 'video', {})
const o = output.paths('holidays/seagull.mp4', 'video', {})
should(o.video).eql({
path: 'media/large/holidays/seagull.mp4',
rel: 'video:resized'
@ -102,7 +102,7 @@ describe('Output paths', function () {
})
it('can point downloads to the large version', function () {
var o = output.paths('holidays/seagull.mp4', 'video', {
const o = output.paths('holidays/seagull.mp4', 'video', {
downloadVideos: 'large'
})
should(o.download).eql({
@ -112,7 +112,7 @@ describe('Output paths', function () {
})
it('can point downloads to a copy in the output folder', function () {
var o = output.paths('holidays/seagull.mp4', 'video', {
const o = output.paths('holidays/seagull.mp4', 'video', {
downloadVideos: 'copy'
})
should(o.download).eql({
@ -122,7 +122,7 @@ describe('Output paths', function () {
})
it('can point downloads to a symlink to the originals', function () {
var o = output.paths('holidays/seagull.mp4', 'video', {
const o = output.paths('holidays/seagull.mp4', 'video', {
downloadVideos: 'symlink'
})
should(o.download).eql({
@ -132,7 +132,7 @@ describe('Output paths', function () {
})
it('can point downloads to an existing link', function () {
var o = output.paths('holidays/seagull.mp4', 'video', {
const o = output.paths('holidays/seagull.mp4', 'video', {
downloadVideos: 'link',
downloadLinkPrefix: '../myphotos'
})
@ -145,7 +145,7 @@ describe('Output paths', function () {
describe('Download links', function () {
it('can use a relative link prefix', function () {
var o = output.paths('holidays/beach.jpg', 'image', {
const o = output.paths('holidays/beach.jpg', 'image', {
downloadPhotos: 'link',
downloadLinkPrefix: '../myphotos'
})
@ -156,7 +156,7 @@ describe('Output paths', function () {
})
it('can use a relative link prefix ending with a slash', function () {
var o = output.paths('holidays/beach.jpg', 'image', {
const o = output.paths('holidays/beach.jpg', 'image', {
downloadPhotos: 'link',
downloadLinkPrefix: '../myphotos/'
})
@ -167,7 +167,7 @@ describe('Output paths', function () {
})
it('can use an absolute link prefix', function () {
var o = output.paths('holidays/beach.jpg', 'image', {
const o = output.paths('holidays/beach.jpg', 'image', {
downloadPhotos: 'link',
downloadLinkPrefix: '/Photos'
})
@ -178,7 +178,7 @@ describe('Output paths', function () {
})
it('can use an absolute link prefix ending with a slash', function () {
var o = output.paths('holidays/beach.jpg', 'image', {
const o = output.paths('holidays/beach.jpg', 'image', {
downloadPhotos: 'link',
downloadLinkPrefix: '/Photos/'
})
@ -189,7 +189,7 @@ describe('Output paths', function () {
})
it('can use a URL prefix', function () {
var o = output.paths('holidays/beach.jpg', 'image', {
const o = output.paths('holidays/beach.jpg', 'image', {
downloadPhotos: 'link',
downloadLinkPrefix: 'http://mygallery.com/photos'
})
@ -200,7 +200,7 @@ describe('Output paths', function () {
})
it('can use a URL prefix ending with a slash', function () {
var o = output.paths('holidays/beach.jpg', 'image', {
const o = output.paths('holidays/beach.jpg', 'image', {
downloadPhotos: 'link',
downloadLinkPrefix: 'http://mygallery.com/photos/'
})

Loading…
Cancel
Save