Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
e3aa941f
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e3aa941f
编写于
2月 16, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
notifications - add tests
上级
34466c16
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
185 addition
and
5 deletion
+185
-5
src/vs/workbench/common/notifications.ts
src/vs/workbench/common/notifications.ts
+58
-5
src/vs/workbench/test/common/notifications.test.ts
src/vs/workbench/test/common/notifications.test.ts
+127
-0
未找到文件。
src/vs/workbench/common/notifications.ts
浏览文件 @
e3aa941f
...
...
@@ -35,7 +35,7 @@ export interface INotificationChangeEvent {
}
class
NoOpNotification
implements
INotificationHandle
{
dispose
()
{
}
public
dispose
():
void
{
}
}
export
class
NotificationsModel
implements
INotificationsModel
{
...
...
@@ -69,13 +69,42 @@ export class NotificationsModel implements INotificationsModel {
return
item
;
// return early if this is a no-op
}
// Add to list as first entry (TODO@notification dedupe!)
// Deduplicate
const
duplicate
=
this
.
findNotification
(
item
);
if
(
duplicate
)
{
duplicate
.
dispose
();
}
// Add to list as first entry
this
.
_notifications
.
splice
(
0
,
0
,
item
);
// Events
this
.
_onDidNotificationChange
.
fire
({
item
,
index
:
0
,
kind
:
NotificationChangeType
.
ADD
});
return
item
;
// Wrap into handles
return
{
dispose
:
()
=>
this
.
disposeItem
(
item
)
};
}
private
disposeItem
(
item
:
INotificationViewItem
):
void
{
const
liveItem
=
this
.
findNotification
(
item
);
if
(
liveItem
&&
liveItem
!==
item
)
{
liveItem
.
dispose
();
// item could have been replaced with another one, make sure to dispose the live item
}
else
{
item
.
dispose
();
// otherwise just dispose the item that was passed in
}
}
private
findNotification
(
item
:
INotificationViewItem
):
INotificationViewItem
{
for
(
let
i
=
0
;
i
<
this
.
_notifications
.
length
;
i
++
)
{
const
notification
=
this
.
_notifications
[
i
];
if
(
notification
.
equals
(
item
))
{
return
notification
;
}
}
return
void
0
;
}
private
createViewItem
(
notification
:
INotification
):
INotificationViewItem
|
NoOpNotification
{
...
...
@@ -126,6 +155,8 @@ export interface INotificationViewItem {
collapse
():
void
;
dispose
():
void
;
equals
(
item
:
INotificationViewItem
);
}
export
function
isNotificationViewItem
(
obj
:
any
):
obj
is
INotificationViewItem
{
...
...
@@ -171,10 +202,10 @@ export class NotificationViewItem implements INotificationViewItem {
message
.
value
=
`
${
message
.
value
.
substr
(
0
,
NotificationViewItem
.
MAX_MESSAGE_LENGTH
)}
...`
;
}
return
new
NotificationViewItem
(
severity
,
message
,
notification
.
source
,
notification
.
actions
||
[]
);
return
new
NotificationViewItem
(
severity
,
message
,
notification
.
source
,
notification
.
actions
);
}
private
constructor
(
private
_severity
:
Severity
,
private
_message
:
IMarkdownString
,
private
_source
:
string
,
private
_actions
:
IAction
[])
{
private
constructor
(
private
_severity
:
Severity
,
private
_message
:
IMarkdownString
,
private
_source
:
string
,
private
_actions
:
IAction
[]
=
[]
)
{
this
.
toDispose
=
[];
this
.
_expanded
=
_actions
.
length
>
0
;
...
...
@@ -242,4 +273,26 @@ export class NotificationViewItem implements INotificationViewItem {
this
.
toDispose
=
dispose
(
this
.
toDispose
);
}
public
equals
(
other
:
INotificationViewItem
):
boolean
{
if
(
this
.
_source
!==
other
.
source
)
{
return
false
;
}
if
(
this
.
_actions
.
length
!==
other
.
actions
.
length
)
{
return
false
;
}
if
(
this
.
_message
.
value
!==
other
.
message
.
value
)
{
return
false
;
}
for
(
let
i
=
0
;
i
<
this
.
_actions
.
length
;
i
++
)
{
if
(
this
.
_actions
[
i
].
id
!==
other
.
actions
[
i
].
id
)
{
return
false
;
}
}
return
true
;
}
}
\ No newline at end of file
src/vs/workbench/test/common/notifications.test.ts
0 → 100644
浏览文件 @
e3aa941f
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
NotificationsModel
,
NotificationViewItem
,
INotificationChangeEvent
,
NotificationChangeType
}
from
'
vs/workbench/common/notifications
'
;
import
{
Severity
}
from
'
vs/platform/message/common/message
'
;
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
{
INotification
}
from
'
vs/platform/notification/common/notification
'
;
suite
(
'
Notifications
'
,
()
=>
{
test
(
'
Items
'
,
()
=>
{
// Invalid
assert
.
ok
(
!
NotificationViewItem
.
create
({
severity
:
Severity
.
Error
,
message
:
''
}));
assert
.
ok
(
!
NotificationViewItem
.
create
({
severity
:
Severity
.
Error
,
message
:
null
}));
assert
.
ok
(
!
NotificationViewItem
.
create
({
severity
:
Severity
.
Error
,
message
:
{
value
:
''
,
isTrusted
:
true
}
}));
// Duplicates
let
item1
=
NotificationViewItem
.
create
({
severity
:
Severity
.
Error
,
message
:
'
Error Message
'
});
let
item2
=
NotificationViewItem
.
create
({
severity
:
Severity
.
Error
,
message
:
'
Error Message
'
});
let
item3
=
NotificationViewItem
.
create
({
severity
:
Severity
.
Info
,
message
:
'
Info Message
'
});
let
item4
=
NotificationViewItem
.
create
({
severity
:
Severity
.
Error
,
message
:
'
Error Message
'
,
source
:
'
Source
'
});
let
item5
=
NotificationViewItem
.
create
({
severity
:
Severity
.
Error
,
message
:
'
Error Message
'
,
actions
:
[
new
Action
(
'
id
'
,
'
label
'
)]
});
assert
.
equal
(
item1
.
equals
(
item1
),
true
);
assert
.
equal
(
item2
.
equals
(
item2
),
true
);
assert
.
equal
(
item3
.
equals
(
item3
),
true
);
assert
.
equal
(
item4
.
equals
(
item4
),
true
);
assert
.
equal
(
item5
.
equals
(
item5
),
true
);
assert
.
equal
(
item1
.
equals
(
item2
),
true
);
assert
.
equal
(
item1
.
equals
(
item3
),
false
);
assert
.
equal
(
item1
.
equals
(
item4
),
false
);
assert
.
equal
(
item1
.
equals
(
item5
),
false
);
// Message Box
assert
.
equal
(
item5
.
canCollapse
,
false
);
assert
.
equal
(
item5
.
expanded
,
true
);
// Events
let
called
=
0
;
item1
.
onDidChange
(()
=>
{
called
++
;
});
item1
.
expand
();
item1
.
expand
();
item1
.
collapse
();
item1
.
collapse
();
assert
.
equal
(
called
,
2
);
called
=
0
;
item1
.
onDidDispose
(()
=>
{
called
++
;
});
item1
.
dispose
();
assert
.
equal
(
called
,
1
);
});
test
(
'
Model
'
,
()
=>
{
const
model
=
new
NotificationsModel
();
let
lastEvent
:
INotificationChangeEvent
;
model
.
onDidNotificationChange
(
e
=>
{
lastEvent
=
e
;
});
let
item1
:
INotification
=
{
severity
:
Severity
.
Error
,
message
:
'
Error Message
'
,
actions
:
[
new
Action
(
'
id
'
,
'
label
'
)]
};
let
item2
:
INotification
=
{
severity
:
Severity
.
Warning
,
message
:
'
Warning Message
'
,
source
:
'
Some Source
'
};
let
item2Duplicate
:
INotification
=
{
severity
:
Severity
.
Warning
,
message
:
'
Warning Message
'
,
source
:
'
Some Source
'
};
let
item3
:
INotification
=
{
severity
:
Severity
.
Info
,
message
:
'
Info Message
'
};
let
item1Handle
=
model
.
notify
(
item1
);
assert
.
equal
(
lastEvent
.
item
.
severity
,
item1
.
severity
);
assert
.
equal
(
lastEvent
.
item
.
message
.
value
,
item1
.
message
);
assert
.
equal
(
lastEvent
.
index
,
0
);
assert
.
equal
(
lastEvent
.
kind
,
NotificationChangeType
.
ADD
);
let
item2Handle
=
model
.
notify
(
item2
);
assert
.
equal
(
lastEvent
.
item
.
severity
,
item2
.
severity
);
assert
.
equal
(
lastEvent
.
item
.
message
.
value
,
item2
.
message
);
assert
.
equal
(
lastEvent
.
index
,
0
);
assert
.
equal
(
lastEvent
.
kind
,
NotificationChangeType
.
ADD
);
model
.
notify
(
item3
);
assert
.
equal
(
lastEvent
.
item
.
severity
,
item3
.
severity
);
assert
.
equal
(
lastEvent
.
item
.
message
.
value
,
item3
.
message
);
assert
.
equal
(
lastEvent
.
index
,
0
);
assert
.
equal
(
lastEvent
.
kind
,
NotificationChangeType
.
ADD
);
assert
.
equal
(
model
.
notifications
.
length
,
3
);
item1Handle
.
dispose
();
assert
.
equal
(
model
.
notifications
.
length
,
2
);
assert
.
equal
(
lastEvent
.
item
.
severity
,
item1
.
severity
);
assert
.
equal
(
lastEvent
.
item
.
message
.
value
,
item1
.
message
);
assert
.
equal
(
lastEvent
.
index
,
2
);
assert
.
equal
(
lastEvent
.
kind
,
NotificationChangeType
.
REMOVE
);
model
.
notify
(
item2Duplicate
);
assert
.
equal
(
model
.
notifications
.
length
,
2
);
assert
.
equal
(
lastEvent
.
item
.
severity
,
item2Duplicate
.
severity
);
assert
.
equal
(
lastEvent
.
item
.
message
.
value
,
item2Duplicate
.
message
);
assert
.
equal
(
lastEvent
.
index
,
0
);
assert
.
equal
(
lastEvent
.
kind
,
NotificationChangeType
.
ADD
);
item2Handle
.
dispose
();
assert
.
equal
(
model
.
notifications
.
length
,
1
);
assert
.
equal
(
lastEvent
.
item
.
severity
,
item2Duplicate
.
severity
);
assert
.
equal
(
lastEvent
.
item
.
message
.
value
,
item2Duplicate
.
message
);
assert
.
equal
(
lastEvent
.
index
,
0
);
assert
.
equal
(
lastEvent
.
kind
,
NotificationChangeType
.
REMOVE
);
model
.
notifications
[
0
].
expand
();
assert
.
equal
(
lastEvent
.
item
.
severity
,
item3
.
severity
);
assert
.
equal
(
lastEvent
.
item
.
message
.
value
,
item3
.
message
);
assert
.
equal
(
lastEvent
.
index
,
0
);
assert
.
equal
(
lastEvent
.
kind
,
NotificationChangeType
.
CHANGE
);
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录