Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
498f2905
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
498f2905
编写于
4月 06, 2017
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Debt: Test for keybindings editor model (cont..)
上级
19b127a6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
178 addition
and
4 deletion
+178
-4
src/vs/workbench/parts/preferences/test/common/keybindingsEditorModel.test.ts
...ts/preferences/test/common/keybindingsEditorModel.test.ts
+178
-4
未找到文件。
src/vs/workbench/parts/preferences/test/common/keybindingsEditorModel.test.ts
浏览文件 @
498f2905
...
...
@@ -7,7 +7,12 @@ import * as assert from 'assert';
import
*
as
uuid
from
'
vs/base/common/uuid
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
OS
}
from
'
vs/base/common/platform
'
;
import
{
Registry
}
from
'
vs/platform/platform
'
;
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
{
KeyCode
,
SimpleKeybinding
,
ChordKeybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
SyncActionDescriptor
}
from
'
vs/platform/actions/common/actions
'
;
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
IWorkbenchActionRegistry
,
Extensions
as
ActionExtensions
}
from
'
vs/workbench/common/actionRegistry
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
IExtensionService
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
...
...
@@ -24,6 +29,12 @@ interface Modifiers {
shiftKey
?:
boolean
;
}
class
AnAction
extends
Action
{
constructor
(
id
:
string
)
{
super
(
id
);
}
}
suite
(
'
Keybindings Editor Model test
'
,
()
=>
{
let
instantiationService
:
TestInstantiationService
;
...
...
@@ -36,15 +47,95 @@ suite('Keybindings Editor Model test', () => {
instantiationService
.
stub
(
IExtensionService
,
{},
'
onReady
'
,
()
=>
TPromise
.
as
(
null
));
testObject
=
instantiationService
.
createInstance
(
KeybindingsEditorModel
,
OS
);
CommandsRegistry
.
registerCommand
(
'
command_without_keybinding
'
,
()
=>
{
});
});
test
(
'
fetch returns default keybindings
'
,
()
=>
{
const
expected
=
[
const
expected
=
prepareKeybindingService
(
aResolvedKeybindingItem
({
command
:
'
a
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
'
b
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
chordPart
:
{
keyCode
:
KeyCode
.
Escape
}
})
];
instantiationService
.
stub
(
IKeybindingService
,
'
getKeybindings
'
,
()
=>
expected
);
instantiationService
.
stub
(
IKeybindingService
,
'
getDefaultKeybindings
'
,
()
=>
expected
);
);
return
testObject
.
resolve
().
then
(()
=>
{
const
actuals
=
asResolvedKeybindingItems
(
testObject
.
fetch
(
''
));
assertKeybindingItems
(
actuals
,
expected
);
});
});
test
(
'
fetch returns default keybindings at the top
'
,
()
=>
{
const
expected
=
prepareKeybindingService
(
aResolvedKeybindingItem
({
command
:
'
a
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
'
b
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
chordPart
:
{
keyCode
:
KeyCode
.
Escape
}
})
);
return
testObject
.
resolve
().
then
(()
=>
{
const
actuals
=
asResolvedKeybindingItems
(
testObject
.
fetch
(
''
).
slice
(
0
,
2
),
true
);
assertKeybindingItems
(
actuals
,
expected
);
});
});
test
(
'
fetch returns default keybindings sorted by command id
'
,
()
=>
{
const
keybindings
=
prepareKeybindingService
(
aResolvedKeybindingItem
({
command
:
'
b
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
'
c
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
chordPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
'
a
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Backspace
}
})
);
const
expected
=
[
keybindings
[
2
],
keybindings
[
0
],
keybindings
[
1
]];
return
testObject
.
resolve
().
then
(()
=>
{
const
actuals
=
asResolvedKeybindingItems
(
testObject
.
fetch
(
''
));
assertKeybindingItems
(
actuals
,
expected
);
});
});
test
(
'
fetch returns user keybinding first if default and user has same id
'
,
()
=>
{
const
sameId
=
'
b
'
+
uuid
.
generateUuid
();
const
keybindings
=
prepareKeybindingService
(
aResolvedKeybindingItem
({
command
:
sameId
,
firstPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
sameId
,
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
chordPart
:
{
keyCode
:
KeyCode
.
Escape
},
isDefault
:
false
})
);
const
expected
=
[
keybindings
[
1
],
keybindings
[
0
]];
return
testObject
.
resolve
().
then
(()
=>
{
const
actuals
=
asResolvedKeybindingItems
(
testObject
.
fetch
(
''
));
assertKeybindingItems
(
actuals
,
expected
);
});
});
test
(
'
fetch returns keybinding with titles first
'
,
()
=>
{
const
keybindings
=
prepareKeybindingService
(
aResolvedKeybindingItem
({
command
:
'
a
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
'
b
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
chordPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
'
c
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
chordPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
'
d
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
chordPart
:
{
keyCode
:
KeyCode
.
Escape
}
})
);
registerCommandWithTitle
(
keybindings
[
1
].
command
,
'
B Title
'
);
registerCommandWithTitle
(
keybindings
[
3
].
command
,
'
A Title
'
);
const
expected
=
[
keybindings
[
3
],
keybindings
[
1
],
keybindings
[
0
],
keybindings
[
2
]];
instantiationService
.
stub
(
IKeybindingService
,
'
getKeybindings
'
,
()
=>
keybindings
);
instantiationService
.
stub
(
IKeybindingService
,
'
getDefaultKeybindings
'
,
()
=>
keybindings
);
return
testObject
.
resolve
().
then
(()
=>
{
const
actuals
=
asResolvedKeybindingItems
(
testObject
.
fetch
(
''
));
assertKeybindingItems
(
actuals
,
expected
);
});
});
test
(
'
fetch returns keybinding with user first if title and id matches
'
,
()
=>
{
const
sameId
=
'
b
'
+
uuid
.
generateUuid
();
const
keybindings
=
prepareKeybindingService
(
aResolvedKeybindingItem
({
command
:
'
a
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
sameId
,
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
chordPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
'
c
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
chordPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
sameId
,
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
isDefault
:
false
})
);
registerCommandWithTitle
(
keybindings
[
1
].
command
,
'
Same Title
'
);
registerCommandWithTitle
(
keybindings
[
3
].
command
,
'
Same Title
'
);
const
expected
=
[
keybindings
[
3
],
keybindings
[
1
],
keybindings
[
0
],
keybindings
[
2
]];
return
testObject
.
resolve
().
then
(()
=>
{
const
actuals
=
asResolvedKeybindingItems
(
testObject
.
fetch
(
''
));
...
...
@@ -52,6 +143,89 @@ suite('Keybindings Editor Model test', () => {
});
});
test
(
'
fetch returns default keybindings sorted by precedence
'
,
()
=>
{
const
expected
=
prepareKeybindingService
(
aResolvedKeybindingItem
({
command
:
'
b
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
'
c
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
chordPart
:
{
keyCode
:
KeyCode
.
Escape
}
}),
aResolvedKeybindingItem
({
command
:
'
a
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Backspace
}
})
);
return
testObject
.
resolve
().
then
(()
=>
{
const
actuals
=
asResolvedKeybindingItems
(
testObject
.
fetch
(
''
,
true
));
assertKeybindingItems
(
actuals
,
expected
);
});
});
test
(
'
convert keybinding without title to entry
'
,
()
=>
{
const
expected
=
aResolvedKeybindingItem
({
command
:
'
a
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
when
:
'
context1 && context2
'
});
prepareKeybindingService
(
expected
);
return
testObject
.
resolve
().
then
(()
=>
{
const
actual
=
testObject
.
fetch
(
''
)[
0
];
assert
.
equal
(
actual
.
keybindingItem
.
command
,
expected
.
command
);
assert
.
equal
(
actual
.
keybindingItem
.
commandLabel
,
''
);
assert
.
equal
(
actual
.
keybindingItem
.
commandDefaultLabel
,
null
);
assert
.
equal
(
actual
.
keybindingItem
.
keybinding
.
getAriaLabel
(),
expected
.
resolvedKeybinding
.
getAriaLabel
());
assert
.
equal
(
actual
.
keybindingItem
.
when
,
expected
.
when
.
serialize
());
});
});
test
(
'
convert keybinding with title to entry
'
,
()
=>
{
const
expected
=
aResolvedKeybindingItem
({
command
:
'
a
'
+
uuid
.
generateUuid
(),
firstPart
:
{
keyCode
:
KeyCode
.
Escape
},
when
:
'
context1 && context2
'
});
prepareKeybindingService
(
expected
);
registerCommandWithTitle
(
expected
.
command
,
'
Some Title
'
);
return
testObject
.
resolve
().
then
(()
=>
{
const
actual
=
testObject
.
fetch
(
''
)[
0
];
assert
.
equal
(
actual
.
keybindingItem
.
command
,
expected
.
command
);
assert
.
equal
(
actual
.
keybindingItem
.
commandLabel
,
'
Some Title
'
);
assert
.
equal
(
actual
.
keybindingItem
.
commandDefaultLabel
,
null
);
assert
.
equal
(
actual
.
keybindingItem
.
keybinding
.
getAriaLabel
(),
expected
.
resolvedKeybinding
.
getAriaLabel
());
assert
.
equal
(
actual
.
keybindingItem
.
when
,
expected
.
when
.
serialize
());
});
});
test
(
'
convert without title and binding to entry
'
,
()
=>
{
CommandsRegistry
.
registerCommand
(
'
command_without_keybinding
'
,
()
=>
{
});
prepareKeybindingService
();
return
testObject
.
resolve
().
then
(()
=>
{
const
actual
=
testObject
.
fetch
(
''
).
filter
(
element
=>
element
.
keybindingItem
.
command
===
'
command_without_keybinding
'
)[
0
];
assert
.
equal
(
actual
.
keybindingItem
.
command
,
'
command_without_keybinding
'
);
assert
.
equal
(
actual
.
keybindingItem
.
commandLabel
,
''
);
assert
.
equal
(
actual
.
keybindingItem
.
commandDefaultLabel
,
null
);
assert
.
equal
(
actual
.
keybindingItem
.
keybinding
,
null
);
assert
.
equal
(
actual
.
keybindingItem
.
when
,
''
);
});
});
test
(
'
convert with title and wihtout binding to entry
'
,
()
=>
{
const
id
=
'
a
'
+
uuid
.
generateUuid
();
registerCommandWithTitle
(
id
,
'
some title
'
);
prepareKeybindingService
();
return
testObject
.
resolve
().
then
(()
=>
{
const
actual
=
testObject
.
fetch
(
''
).
filter
(
element
=>
element
.
keybindingItem
.
command
===
id
)[
0
];
assert
.
equal
(
actual
.
keybindingItem
.
command
,
id
);
assert
.
equal
(
actual
.
keybindingItem
.
commandLabel
,
'
some title
'
);
assert
.
equal
(
actual
.
keybindingItem
.
commandDefaultLabel
,
null
);
assert
.
equal
(
actual
.
keybindingItem
.
keybinding
,
null
);
assert
.
equal
(
actual
.
keybindingItem
.
when
,
''
);
});
});
function
prepareKeybindingService
(...
keybindingItems
:
ResolvedKeybindingItem
[]):
ResolvedKeybindingItem
[]
{
instantiationService
.
stub
(
IKeybindingService
,
'
getKeybindings
'
,
()
=>
keybindingItems
);
instantiationService
.
stub
(
IKeybindingService
,
'
getDefaultKeybindings
'
,
()
=>
keybindingItems
);
return
keybindingItems
;
}
function
registerCommandWithTitle
(
command
:
string
,
title
:
string
):
void
{
const
registry
=
Registry
.
as
<
IWorkbenchActionRegistry
>
(
ActionExtensions
.
WorkbenchActions
);
registry
.
registerWorkbenchAction
(
new
SyncActionDescriptor
(
AnAction
,
command
,
title
,
{
primary
:
null
}),
''
);
}
function
assertKeybindingItems
(
actual
:
ResolvedKeybindingItem
[],
expected
:
ResolvedKeybindingItem
[])
{
assert
.
equal
(
actual
.
length
,
expected
.
length
);
for
(
let
i
=
0
;
i
<
actual
.
length
;
i
++
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录