diff --git a/package.json b/package.json index 5d3e81078..45b417d83 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "start": "webpack --config plugins/webpack.js && node .", "test:all": "gulp --gulpfile plugins/gulpfile.js test", "test": "nyc --extension .jsx tape plugins/**/*.spec.js", - "test:react": "babel-tape-runner plugins/album/test/*.js | faucet", + "test:react": "babel-tape-runner plugins/album/test/*.js plugins/video/test/*.js | faucet", "ci-cover:coveralls": "nyc report --reporter=text-lcov | coveralls", "ci-cover:prep-codeclimate": "nyc report --reporter=text-lcov > coverage.lcov", "ci-cover:codeclimate": "codeclimate-test-reporter < coverage.lcov" diff --git a/plugins/album/test/react-thumb-enzyme.js b/plugins/album/test/react-thumb-enzyme.js index 9c3da79d3..5f5b15d4c 100644 --- a/plugins/album/test/react-thumb-enzyme.js +++ b/plugins/album/test/react-thumb-enzyme.js @@ -2,7 +2,7 @@ import test from 'tape'; import React from 'react'; import { shallow, mount } from 'enzyme'; -import './react-enzyme-setup'; +import '../../../test/react-enzyme-setup'; import Thumb from '../views/thumb'; test('React Component - Thumb', { skip: false }, (describe) => { diff --git a/plugins/utils/lib/index.js b/plugins/utils/lib/index.js index d027bc47f..f134bc4c4 100644 --- a/plugins/utils/lib/index.js +++ b/plugins/utils/lib/index.js @@ -24,7 +24,7 @@ function customMime(extension) { } } -const file = { +const fileMethods = { type: (filepath) => { if (!filepath) { return false; @@ -42,6 +42,18 @@ const file = { photoPath: filepath => filepath && filepath.replace('thumbs', 'photos'), }; +fileMethods.videoToThumbsPath = (filepath = null, gallery = null) => { + if (filepath === null || gallery === null) { + return undefined; + } + + const year = filepath.substr(0, 4); + const firstVideoSource = filepath.split(',')[0]; + const type = fileMethods.type(firstVideoSource); + const file = firstVideoSource.substr(0, firstVideoSource.indexOf(type) - 1); + return `/static/gallery-${gallery}/media/thumbs/${year}/${file}.jpg`; +}; + /** Find associated path and filename based on file without extension @@ -52,10 +64,10 @@ const file = { @param {bool} [options.ignoreExtension] Apply pattern without file extension @return {Promise} array of string associated filenames with absolute path **/ -file.glob = (sourceFolder, pattern, options = {}) => new Promise((resolve, reject) => { - let absolutePath = file.absolutePath(sourceFolder); +fileMethods.glob = (sourceFolder, pattern, options = {}) => new Promise((resolve, reject) => { + let absolutePath = fileMethods.absolutePath(sourceFolder); if (options.ignoreExtension === true) { - absolutePath = absolutePath.replace(`.${file.type(absolutePath)}`, ''); + absolutePath = absolutePath.replace(`.${fileMethods.type(absolutePath)}`, ''); } else { absolutePath = path.join(absolutePath, '/'); } @@ -70,4 +82,4 @@ file.glob = (sourceFolder, pattern, options = {}) => new Promise((resolve, rejec }); }); -module.exports.file = file; +module.exports.file = fileMethods; diff --git a/plugins/utils/test/index.spec.js b/plugins/utils/test/index.spec.js index 3dc5ffe1b..d30c2c6ce 100644 --- a/plugins/utils/test/index.spec.js +++ b/plugins/utils/test/index.spec.js @@ -105,6 +105,19 @@ tape('Utilities', { skip: false }, (describe) => { assert.end(); }); + describe.test('* File - Convert video filename to thumbs path', (assert) => { + const test = lib.file.videoToThumbsPath; + assert.equal(test(), undefined, 'Missing path arg'); + assert.equal(test('2001-video-description.mp4'), undefined, 'Missing gallery'); + assert.equal(test('2001-video-description.mp4', 'demo'), + '/static/gallery-demo/media/thumbs/2001/2001-video-description.jpg', 'Single Video'); + assert.equal(test('2002-03-21-01.mp4', 'demo'), + '/static/gallery-demo/media/thumbs/2002/2002-03-21-01.jpg', 'Single Video as Year'); + assert.equal(test('2003-video.avi,2004-video.mts', 'demo'), + '/static/gallery-demo/media/thumbs/2003/2003-video.jpg', 'Multiple videos'); + assert.end(); + }); + describe.test('* File - Glob', (assert) => { assert.plan(8); diff --git a/plugins/video/test/.eslintrc b/plugins/video/test/.eslintrc index 67384217d..a24ac9c6c 100644 --- a/plugins/video/test/.eslintrc +++ b/plugins/video/test/.eslintrc @@ -3,6 +3,7 @@ "rules": { "max-len": [2, 150, 4], "import/no-extraneous-dependencies": ["error", { "devDependencies": true }], - "global-require": 0 + "global-require": 0, + "react/jsx-filename-extension": 0 } } diff --git a/plugins/video/test/index.spec.js b/plugins/video/test/index.spec.js index ff152a0de..72dbf0819 100644 --- a/plugins/video/test/index.spec.js +++ b/plugins/video/test/index.spec.js @@ -46,7 +46,6 @@ tape('Verify /video route', { skip: false }, (describe) => { }); return server.inject(request, (response) => { - assert.ok(response.result.indexOf('); } Video.propTypes = { diff --git a/plugins/album/test/react-enzyme-setup.js b/test/react-enzyme-setup.js similarity index 100% rename from plugins/album/test/react-enzyme-setup.js rename to test/react-enzyme-setup.js