mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(cloudfunc) add tests
This commit is contained in:
parent
1f4caf6bf2
commit
f41f3974a4
2 changed files with 111 additions and 0 deletions
25
test/lib/cloudfunc.html
Normal file
25
test/lib/cloudfunc.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<div class="fm-header">
|
||||
<span class="mini-icon "></span>
|
||||
<span class="name reduce-text">name</span>
|
||||
<span class="size reduce-text">size</span>
|
||||
<span class="owner reduce-text">owner</span>
|
||||
<span class="mode reduce-text">mode</span>
|
||||
</div><ul data-name="js-files" class="files"><li draggable="true" class="">
|
||||
<span class="mini-icon directory"></span>
|
||||
<span class="name reduce-text"><a href="/fs/etc" title=".." draggable="true">..</a></span>
|
||||
<span class="size reduce-text"><dir></span>
|
||||
<span class="owner reduce-text">.</span>
|
||||
<span class="mode reduce-text">--- --- ---</span>
|
||||
</li><li draggable="true" class="">
|
||||
<span class="mini-icon directory"></span>
|
||||
<span class="name reduce-text"><a href="/fs/etc/X11/applnk" title="applnk" draggable="true">applnk</a></span>
|
||||
<span class="size reduce-text"><dir></span>
|
||||
<span class="owner reduce-text">root</span>
|
||||
<span class="mode reduce-text">rwx r-x r-x</span>
|
||||
</li><li draggable="true" class="">
|
||||
<span class="mini-icon text-file"></span>
|
||||
<span class="name reduce-text"><a href="/fs/etc/X11/prefdm" title="prefdm" target="_blank" draggable="true">prefdm</a></span>
|
||||
<span class="size reduce-text">1.30kb</span>
|
||||
<span class="owner reduce-text">root</span>
|
||||
<span class="mode reduce-text">rwx r-x r-x</span>
|
||||
</li></ul>
|
||||
86
test/lib/cloudfunc.js
Normal file
86
test/lib/cloudfunc.js
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var DIR = __dirname + '/../../',
|
||||
LIBDIR = DIR + 'lib/',
|
||||
HTMLDIR = DIR + 'html/',
|
||||
|
||||
Util = require(LIBDIR + 'util'),
|
||||
CloudFunc = require(LIBDIR + 'cloudfunc'),
|
||||
files = require(LIBDIR + 'server/files'),
|
||||
|
||||
FS_DIR = HTMLDIR + 'fs/',
|
||||
TEMPLATEPATH = FS_DIR + 'file.html',
|
||||
LINK_TEMPLATE_PATH = FS_DIR + 'link.html',
|
||||
PATHTEMPLATE_PATH = FS_DIR + 'path.html',
|
||||
EXPECT_PATH = DIR + 'test/lib/cloudfunc.html',
|
||||
|
||||
Files = [TEMPLATEPATH, PATHTEMPLATE_PATH, LINK_TEMPLATE_PATH, EXPECT_PATH],
|
||||
|
||||
JSON_FILES = {
|
||||
path : '/etc/X11/',
|
||||
files : [{
|
||||
name: 'applnk',
|
||||
size: 'dir',
|
||||
uid : 0,
|
||||
mode: '40755'
|
||||
}, {
|
||||
name: 'prefdm',
|
||||
size: 1328,
|
||||
uid : 0,
|
||||
mode: '100755'
|
||||
}]
|
||||
},
|
||||
|
||||
|
||||
Expect =
|
||||
'<div data-name="js-path" class="reduce-text" title="/etc/X11/">' +
|
||||
'<span data-name="js-clear-storage" class="path-icon clear-storage" ' +
|
||||
'title="clear storage (Ctrl+D)">' +
|
||||
'</span>' +
|
||||
'<a data-name="js-refresh" href="/fs/etc/X11" ' +
|
||||
'class="path-icon refresh-icon" title="refresh (Ctrl+R)"></a>' +
|
||||
'<span data-name="js-links" class=links>' +
|
||||
'<a href="/fs" title="/">/</a>' +
|
||||
'<a href="/fs/etc" title="/etc">' +
|
||||
'etc' +
|
||||
'</a>/X11/' +
|
||||
'</span>' +
|
||||
'</div>';
|
||||
|
||||
|
||||
exports.check = function() {
|
||||
files.read(Files, 'utf-8', function(errors, files) {
|
||||
var i, n, template, pathTemplate, linkTemplate, expect, result;
|
||||
|
||||
if (errors)
|
||||
Util.log(errors);
|
||||
else {
|
||||
Util.time('CloudFunc.buildFromJSON');
|
||||
|
||||
template = files[TEMPLATEPATH];
|
||||
pathTemplate = files[PATHTEMPLATE_PATH];
|
||||
linkTemplate = files[LINK_TEMPLATE_PATH];
|
||||
expect = files[EXPECT_PATH];
|
||||
|
||||
result = CloudFunc.buildFromJSON(JSON_FILES, template, pathTemplate, linkTemplate);
|
||||
|
||||
Expect += expect;
|
||||
|
||||
n = Expect.length;
|
||||
for (i = 0; i < n; i++)
|
||||
if (result[i] !== Expect[i]) {
|
||||
Util.log('Error in char number: ' + i + '\n' +
|
||||
'Expect: ' + Expect.substr(i) + '\n' +
|
||||
'Result: ' + result.substr(i) );
|
||||
break;
|
||||
}
|
||||
|
||||
if (i === n)
|
||||
console.log('CloudFunc.buildFromJSON: OK');
|
||||
|
||||
Util.timeEnd('CloudFunc.buildFromJSON');
|
||||
}
|
||||
});
|
||||
};
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue