mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test(current-file) add
This commit is contained in:
parent
f9075ce252
commit
10ed681608
5 changed files with 113 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
.*
|
||||
*.spec.js
|
||||
node_modules
|
||||
npm-debug.log*
|
||||
coverage
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
.*
|
||||
*.spec.js
|
||||
manifest.yml
|
||||
Dockerfile*
|
||||
docker-compose.yml
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
/* global DOM */
|
||||
/* global CloudCmd */
|
||||
|
||||
const btoa = require('../../common/btoa');
|
||||
|
||||
const {
|
||||
encode,
|
||||
decode,
|
||||
|
|
|
|||
107
client/dom/current-file.spec.js
Normal file
107
client/dom/current-file.spec.js
Normal file
|
|
@ -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: '/',
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue