diff --git a/.dockerignore b/.dockerignore index 3a966939..856e27c4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,5 @@ .* +*.spec.js node_modules npm-debug.log* coverage diff --git a/.npmignore b/.npmignore index 4abeb13b..b43d5ca0 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,5 @@ .* +*.spec.js manifest.yml Dockerfile* docker-compose.yml diff --git a/client/dom/current-file.js b/client/dom/current-file.js index 8ff1c425..d145ab71 100644 --- a/client/dom/current-file.js +++ b/client/dom/current-file.js @@ -3,6 +3,8 @@ /* global DOM */ /* global CloudCmd */ +const btoa = require('../../common/btoa'); + const { encode, decode, diff --git a/client/dom/current-file.spec.js b/client/dom/current-file.spec.js new file mode 100644 index 00000000..e9567950 --- /dev/null +++ b/client/dom/current-file.spec.js @@ -0,0 +1,107 @@ +'use strict'; + +const test = require('tape'); +const diff = require('sinon-called-with-diff'); +const sinon = diff(require('sinon')); + +const currentFile = require('./current-file'); + +test('current-file: setCurrentName: setAttribute', (t) => { + const { + DOM, + CloudCmd, + } = global; + + global.DOM = getDOM(); + global.CloudCmd = getCloudCmd(); + + const setAttribute = sinon.stub(); + const current = { + setAttribute + }; + + currentFile.setCurrentName('hello', current); + + t.ok(setAttribute.calledWith('data-name', 'js-file-aGVsbG8='), 'should call setAttribute'); + + global.DOM = DOM; + global.CloudCmd = CloudCmd; + + t.end(); +}); + +test('current-file: emit', (t) => { + const { + DOM, + CloudCmd, + } = global; + + const emit = sinon.stub(); + const setAttribute = sinon.stub(); + + global.DOM = getDOM(); + global.CloudCmd = getCloudCmd({ + emit, + }); + + const current = { + setAttribute, + }; + + currentFile.setCurrentName('hello', current); + + t.ok(emit.calledWith('current-file', current), 'should call emit'); + + global.DOM = DOM; + global.CloudCmd = CloudCmd; + + t.end(); +}); + +test('current-file: return', (t) => { + const { + DOM, + CloudCmd, + } = global; + + const setAttribute = sinon.stub(); + const link = {}; + + global.DOM = getDOM({ + link + }); + + global.CloudCmd = getCloudCmd(); + + const current = { + setAttribute, + }; + + const result = currentFile.setCurrentName('hello', current); + + t.equal(result, link, 'should return link'); + + global.DOM = DOM; + global.CloudCmd = CloudCmd; + + t.end(); +}); + +function getCloudCmd({emit} = {}) { + return { + PREFIX: '', + emit: emit || sinon.stub(), + }; +} + + +function getDOM({link} = {}) { + link = link || {}; + + return { + CurrentInfo: { + link, + dirPath: '/', + } + }; +} diff --git a/package.json b/package.json index 337d3244..47d37c70 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "fix:lint:client": "redrun lint:client -- --fix", "fix:lint:test": "redrun lint:test -- --fix", "fix:lint:server": "redrun lint:server -- --fix", - "test": "tape 'test/**/*.js'", + "test": "tape 'test/**/*.js' 'client/**/*.spec.js'", "test:client": "tape 'test/client/**/*.js'", "wisdom": "redrun build", "prewisdom": "redrun lint test", @@ -94,7 +94,7 @@ "watch:server": "nodemon bin/cloudcmd.js", "watch:lint": "nodemon -w client -w server -w webpack.config.js -x 'redrun lint:js'", "watch:lint:client": "nodemon -w client -w webpack.config.js -x 'redrun lint:js:eslint:client'", - "watch:test": "nodemon -w server -w test -w common -x \"npm test\"", + "watch:test": "nodemon -w client -w server -w test -w common -x \"npm test\"", "watch:test:client": "nodemon -w client -w test/client -x \"npm run test:client\"", "watch:coverage": "nodemon -w server -w test -w common -x \"npm run coverage\"", "w:c": "redrun watch:client",