Commit bb44a06f authored by techird's avatar techird

spec

parent 484331d1
......@@ -18,6 +18,7 @@
"MinderEvent",
"Command",
"KITYMINDER_CONFIG",
"keymap",
"Utils",
"utils"
]
......
{
"undef" : true,
"unused" : false,
"strict" : false,
"curly" : false,
"newcap" : true,
"trailing" : true,
"white": false,
"quotmark": false,
"predef" : [
"require",
"console",
"kity",
"KityMinder",
"KM",
"Minder",
"MinderNode",
"MinderEvent",
"Command",
"KITYMINDER_CONFIG",
"Utils",
"utils",
"describe",
"it",
"beforeEach",
"expect"
]
}
\ No newline at end of file
describe( "protocal/plain", function () {
var json, local, protocal;
beforeEach( function () {
protocal = KM.findProtocal( 'plain' );
} );
it( '协议存在', function () {
expect( protocal ).toBeDefined();
} );
it( '正确 encode', function () {
json = {
data: {
text: 'root',
anyway: 'omg'
},
children: [ {
data: {
text: 'l1c1'
}
}, {
data: {
text: 'l1c2'
},
children: [ {
data: {
text: 'l2c1'
}
}, {
data: {
text: 'l2c2'
}
} ]
}, {
data: {
text: 'l1c3'
}
} ]
};
local = protocal.encode( json );
expect( local ).toBe(
'root\n' +
'\tl1c1\n' +
'\tl1c2\n' +
'\t\tl2c1\n' +
'\t\tl2c2\n' +
'\tl1c3\n'
);
} );
} );
\ No newline at end of file
......@@ -47,7 +47,7 @@ KityMinder.registerModule( "KeyboardModule", function () {
}
function KBNavigate( km, direction ) {
function navigateTo( km, direction ) {
var nextNode = km.getSelectedNode()._nearestNodes[ direction ];
if ( nextNode ) {
km.select( nextNode );
......@@ -60,33 +60,36 @@ KityMinder.registerModule( "KeyboardModule", function () {
buildPositionNetwork( this.getRoot() );
},
keydown: function ( e ) {
var keys = KityMinder.keymap;
switch ( e.originEvent.keyCode ) {
case keymap.Enter:
case keys.Enter:
this.execCommand( 'appendSiblingNode', new MinderNode( 'Topic' ) );
e.preventDefault();
break;
case keymap.Tab:
case keys.Tab:
this.execCommand( 'appendChildNode', new MinderNode( 'Topic' ) );
e.preventDefault();
break;
case keymap.Backspace:
case keymap.Del:
case keys.Backspace:
case keys.Del:
this.execCommand( 'removenode' );
e.preventDefault();
break;
case keymap.Left:
case keymap.up:
case keymap.Right:
case keymap.Down:
if ( this.isSingleSelect() ) {
KBNavigate( this, {
37: 'left',
38: 'top',
39: 'right',
40: 'down'
}[ e.originEvent.keyCode ] );
}
case keys.Left:
navigateTo( this, 'left' );
e.preventDefault();
break;
case keys.Up:
navigateTo( this, 'top' );
e.preventDefault();
break;
case keys.Right:
navigateTo( this, 'right' );
e.preventDefault();
break;
case keys.Down:
navigateTo( this, 'down' );
e.preventDefault();
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment