Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
b00939db
未验证
提交
b00939db
编辑于
1 year ago
作者:
Alexander Turinske
提交者:
GitLab
1 year ago
浏览文件
操作
下载
补丁
差异文件
Update tests for vue 3
- remove spy on vm methods - remove check of vm properties
上级
ce95836b
No related branches found
No related tags found
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
ee/app/assets/javascripts/related_items_tree/components/tree_root.vue
+1
-0
1 个添加, 0 个删除
...s/javascripts/related_items_tree/components/tree_root.vue
ee/spec/frontend/related_items_tree/components/tree_root_spec.js
+97
-102
97 个添加, 102 个删除
.../frontend/related_items_tree/components/tree_root_spec.js
有
98 个添加
和
102 个删除
ee/app/assets/javascripts/related_items_tree/components/tree_root.vue
+
1
−
0
浏览文件 @
b00939db
...
@@ -91,6 +91,7 @@ export default {
...
@@ -91,6 +91,7 @@ export default {
v-bind=
"treeRootOptions"
v-bind=
"treeRootOptions"
class=
"list-unstyled related-items-list tree-root gl-pb-0 gl-pt-0"
class=
"list-unstyled related-items-list tree-root gl-pb-0 gl-pt-0"
:move=
"onMove"
:move=
"onMove"
data-testid=
"tree-root"
@
start=
"handleDragOnStart"
@
start=
"handleDragOnStart"
@
end=
"handleDragOnEnd"
@
end=
"handleDragOnEnd"
>
>
...
...
此差异已折叠。
点击以展开。
ee/spec/frontend/related_items_tree/components/tree_root_spec.js
+
97
−
102
浏览文件 @
b00939db
import
{
GlButton
}
from
'
@gitlab/ui
'
;
import
{
GlButton
}
from
'
@gitlab/ui
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
Vue
,
{
nextTick
}
from
'
vue
'
;
import
Vue
,
{
nextTick
}
from
'
vue
'
;
import
Draggable
from
'
vuedraggable
'
;
import
Draggable
from
'
vuedraggable
'
;
// eslint-disable-next-line no-restricted-imports
// eslint-disable-next-line no-restricted-imports
import
Vuex
from
'
vuex
'
;
import
Vuex
from
'
vuex
'
;
import
{
shallowMountExtended
}
from
'
helpers/vue_test_utils_helper
'
;
import
{
ESC_KEY_CODE
}
from
'
~/lib/utils/keycodes
'
;
import
{
ESC_KEY_CODE
}
from
'
~/lib/utils/keycodes
'
;
import
{
DRAG_DELAY
}
from
'
~/sortable/constants
'
;
import
{
DRAG_DELAY
}
from
'
~/sortable/constants
'
;
import
TreeRoot
from
'
ee/related_items_tree/components/tree_root.vue
'
;
import
TreeRoot
from
'
ee/related_items_tree/components/tree_root.vue
'
;
import
{
treeItemChevronBtnClassName
}
from
'
ee/related_items_tree/constants
'
;
import
{
treeItemChevronBtnClassName
}
from
'
ee/related_items_tree/constants
'
;
import
createDefaultStore
from
'
ee/related_items_tree/store
'
;
import
createDefaultStore
from
'
ee/related_items_tree/store
'
;
import
*
as
epicUtils
from
'
ee/related_items_tree/utils/epic_utils
'
;
import
*
as
epicUtils
from
'
ee/related_items_tree/utils/epic_utils
'
;
import
{
gqClient
}
from
'
ee/related_items_tree/utils/epic_utils
'
;
import
{
import
{
mockQueryResponse
,
mockQueryResponse
,
mockInitialConfig
,
mockInitialConfig
,
...
@@ -21,51 +22,54 @@ import {
...
@@ -21,51 +22,54 @@ import {
const
{
epic
}
=
mockQueryResponse
.
data
.
group
;
const
{
epic
}
=
mockQueryResponse
.
data
.
group
;
Vue
.
use
(
Vuex
);
Vue
.
use
(
Vuex
);
let
store
;
const
createComponent
=
({
parentItem
=
mockParentItem
,
epicPageInfo
=
epic
.
children
.
pageInfo
,
issuesPageInfo
=
epic
.
issues
.
pageInfo
,
}
=
{})
=>
{
store
=
createDefaultStore
();
const
children
=
epicUtils
.
processQueryResponse
(
mockQueryResponse
.
data
.
group
);
store
.
dispatch
(
'
setInitialParentItem
'
,
mockParentItem
);
store
.
dispatch
(
'
setInitialConfig
'
,
mockInitialConfig
);
store
.
dispatch
(
'
setItemChildrenFlags
'
,
{
isSubItem
:
false
,
children
,
});
store
.
dispatch
(
'
setEpicPageInfo
'
,
{
describe
(
'
RelatedItemsTree
'
,
()
=>
{
parentItem
,
let
wrapper
;
pageInfo
:
epicPageInfo
,
let
store
;
});
const
createComponent
=
({
parentItem
=
mockParentItem
,
epicPageInfo
=
epic
.
children
.
pageInfo
,
issuesPageInfo
=
epic
.
issues
.
pageInfo
,
}
=
{})
=>
{
store
=
createDefaultStore
();
const
children
=
epicUtils
.
processQueryResponse
(
mockQueryResponse
.
data
.
group
);
store
.
dispatch
(
'
setInitialParentItem
'
,
mockParentItem
);
store
.
dispatch
(
'
setInitialConfig
'
,
mockInitialConfig
);
store
.
dispatch
(
'
setItemChildrenFlags
'
,
{
isSubItem
:
false
,
children
,
});
store
.
dispatch
(
'
set
Issue
PageInfo
'
,
{
store
.
dispatch
(
'
set
Epic
PageInfo
'
,
{
parentItem
,
parentItem
,
pageInfo
:
issues
PageInfo
,
pageInfo
:
epic
PageInfo
,
});
});
return
shallowMount
(
TreeRoot
,
{
store
.
dispatch
(
'
setIssuePageInfo
'
,
{
store
,
stubs
:
{
'
tree-item
'
:
true
,
},
propsData
:
{
parentItem
,
parentItem
,
children
,
pageInfo
:
issuesPageInfo
,
},
});
});
};
describe
(
'
RelatedItemsTree
'
,
()
=>
{
wrapper
=
shallowMountExtended
(
TreeRoot
,
{
describe
(
'
TreeRoot
'
,
()
=>
{
store
,
let
wrapper
;
stubs
:
{
'
tree-item
'
:
true
,
},
propsData
:
{
parentItem
,
children
,
},
});
};
const
findTreeRoot
=
()
=>
wrapper
.
findByTestId
(
'
tree-root
'
);
const
findMoreChildren
=
()
=>
findTreeRoot
().
find
(
'
li
'
);
describe
(
'
TreeRoot
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
wrapper
=
createComponent
();
createComponent
();
});
});
describe
(
'
mixins
'
,
()
=>
{
describe
(
'
mixins
'
,
()
=>
{
...
@@ -87,46 +91,48 @@ describe('RelatedItemsTree', () => {
...
@@ -87,46 +91,48 @@ describe('RelatedItemsTree', () => {
describe
(
'
computed
'
,
()
=>
{
describe
(
'
computed
'
,
()
=>
{
describe
(
'
treeRootWrapper
'
,
()
=>
{
describe
(
'
treeRootWrapper
'
,
()
=>
{
it
(
'
should return Draggable reference when userSignedIn prop is true
'
,
()
=>
{
it
(
'
should return Draggable reference when userSignedIn prop is true
'
,
()
=>
{
expect
(
wrapper
.
vm
.
treeRootWrapper
).
toBe
(
Draggable
);
expect
(
findTreeRoot
().
element
.
tagName
).
toBe
(
'
DRAGGABLE-STUB
'
);
});
});
it
(
'
should return string "ul" when userSignedIn prop is false
'
,
()
=>
{
it
(
'
should return string "ul" when userSignedIn prop is false
'
,
async
()
=>
{
store
.
dispatch
(
'
setInitialConfig
'
,
{
await
store
.
dispatch
(
'
setInitialConfig
'
,
{
...
mockInitialConfig
,
...
mockInitialConfig
,
userSignedIn
:
false
,
userSignedIn
:
false
,
});
});
expect
(
wrapper
.
vm
.
treeRootWrapper
).
toBe
(
'
ul
'
);
expect
(
findTreeRoot
().
element
.
tagName
).
toBe
(
'
UL
'
);
});
});
});
});
describe
(
'
treeRootOptions
'
,
()
=>
{
describe
(
'
treeRootOptions
'
,
()
=>
{
it
(
'
should return object containing Vue.Draggable config extended from `defaultSortableOptions` when userSignedIn prop is true
'
,
()
=>
{
it
(
'
should return object containing Vue.Draggable config extended from `defaultSortableOptions` when userSignedIn prop is true
'
,
()
=>
{
expect
(
wrapper
.
vm
.
treeRootOptions
).
toEqual
(
expect
(
findTreeRoot
().
attributes
()
).
toEqual
(
expect
.
objectContaining
({
expect
.
objectContaining
({
animation
:
200
,
animation
:
'
200
'
,
forceFallback
:
true
,
delay
:
'
100
'
,
fallback
Class
:
'
is-dragging
'
,
force
fallback
:
'
true
'
,
fallback
OnBody
:
false
,
fallback
class
:
'
is-dragging
'
,
ghost
C
lass
:
'
is-ghost
'
,
ghost
c
lass
:
'
is-ghost
'
,
group
:
'
gl-new-card-body
'
,
group
:
'
gl-new-card-body
'
,
tag
:
'
ul
'
,
tag
:
'
ul
'
,
'
ghost-class
'
:
'
tree-item-drag-active
'
,
'
data-parent-reference
'
:
mockParentItem
.
reference
,
'
data-parent-reference
'
:
mockParentItem
.
reference
,
'
data-parent-id
'
:
mockParentItem
.
id
,
'
data-parent-id
'
:
mockParentItem
.
id
,
value
:
wrapper
.
vm
.
children
,
filter
:
`.
${
treeItemChevronBtnClassName
}
`
,
filter
:
`.
${
treeItemChevronBtnClassName
}
`
,
}),
}),
);
);
});
});
it
(
'
should return an empty object when userSignedIn prop is false
'
,
()
=>
{
it
(
'
should return an empty object when userSignedIn prop is false
'
,
async
()
=>
{
store
.
dispatch
(
'
setInitialConfig
'
,
{
await
store
.
dispatch
(
'
setInitialConfig
'
,
{
...
mockInitialConfig
,
...
mockInitialConfig
,
userSignedIn
:
false
,
userSignedIn
:
false
,
});
});
expect
(
wrapper
.
vm
.
treeRootOptions
).
toEqual
(
expect
.
objectContaining
({}));
expect
(
Object
.
keys
(
findTreeRoot
().
attributes
())).
toEqual
([
'
move
'
,
'
data-testid
'
,
'
class
'
,
]);
});
});
});
});
});
});
...
@@ -374,49 +380,7 @@ describe('RelatedItemsTree', () => {
...
@@ -374,49 +380,7 @@ describe('RelatedItemsTree', () => {
});
});
});
});
describe
(
'
computed
'
,
()
=>
{
describe
(
'
hasMoreChildren
'
,
()
=>
{
it
(
'
returns `true` when either `hasMoreEpics` or `hasMoreIssues` is true
'
,
()
=>
{
expect
(
wrapper
.
vm
.
hasMoreChildren
).
toBe
(
true
);
});
it
(
'
returns `false` when both `hasMoreEpics` and `hasMoreIssues` is false
'
,
()
=>
{
const
wrapperNoMoreChild
=
createComponent
({
epicPageInfo
:
{
hasNextPage
:
false
,
endCursor
:
'
abc
'
,
},
issuesPageInfo
:
{
hasNextPage
:
false
,
endCursor
:
'
def
'
,
},
});
expect
(
wrapperNoMoreChild
.
vm
.
hasMoreChildren
).
toBe
(
false
);
wrapperNoMoreChild
.
destroy
();
});
});
});
describe
(
'
methods
'
,
()
=>
{
describe
(
'
methods
'
,
()
=>
{
describe
(
'
handleShowMoreClick
'
,
()
=>
{
it
(
'
sets `fetchInProgress` to true and calls `fetchNextPageItems` action with parentItem as param
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
,
'
fetchNextPageItems
'
)
.
mockImplementation
(()
=>
new
Promise
(()
=>
{}));
wrapper
.
vm
.
handleShowMoreClick
();
expect
(
wrapper
.
vm
.
fetchInProgress
).
toBe
(
true
);
expect
(
wrapper
.
vm
.
fetchNextPageItems
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
parentItem
:
mockParentItem
,
}),
);
});
});
describe
(
'
onMove
'
,
()
=>
{
describe
(
'
onMove
'
,
()
=>
{
let
mockEvt
;
let
mockEvt
;
let
mockOriginalEvt
;
let
mockOriginalEvt
;
...
@@ -482,6 +446,27 @@ describe('RelatedItemsTree', () => {
...
@@ -482,6 +446,27 @@ describe('RelatedItemsTree', () => {
});
});
describe
(
'
template
'
,
()
=>
{
describe
(
'
template
'
,
()
=>
{
describe
(
'
Children
'
,
()
=>
{
it
(
'
displays children when either when either `hasMoreEpics` or `hasMoreIssues` are true
'
,
()
=>
{
expect
(
findMoreChildren
().
exists
()).
toBe
(
true
);
});
it
(
'
does not display children when both `hasMoreEpics` and `hasMoreIssues` are false
'
,
()
=>
{
createComponent
({
epicPageInfo
:
{
hasNextPage
:
false
,
endCursor
:
'
abc
'
,
},
issuesPageInfo
:
{
hasNextPage
:
false
,
endCursor
:
'
def
'
,
},
});
expect
(
findMoreChildren
().
exists
()).
toBe
(
false
);
});
});
it
(
'
renders tree item component
'
,
()
=>
{
it
(
'
renders tree item component
'
,
()
=>
{
expect
(
wrapper
.
html
()).
toContain
(
'
tree-item-stub
'
);
expect
(
wrapper
.
html
()).
toContain
(
'
tree-item-stub
'
);
});
});
...
@@ -490,12 +475,22 @@ describe('RelatedItemsTree', () => {
...
@@ -490,12 +475,22 @@ describe('RelatedItemsTree', () => {
expect
(
wrapper
.
findComponent
(
GlButton
).
text
()).
toBe
(
'
Show more
'
);
expect
(
wrapper
.
findComponent
(
GlButton
).
text
()).
toBe
(
'
Show more
'
);
});
});
it
(
'
calls `handleShowMoreClick` when `Show more` link is clicked
'
,
()
=>
{
it
(
'
fetches more when `Show more` link is clicked and disables the button
'
,
async
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
,
'
handleShowMoreClick
'
).
mockImplementation
(()
=>
{});
jest
.
spyOn
(
gqClient
,
'
query
'
).
mockResolvedValue
({
data
:
{}
});
await
wrapper
.
findComponent
(
GlButton
).
vm
.
$emit
(
'
click
'
);
wrapper
.
findComponent
(
GlButton
).
vm
.
$emit
(
'
click
'
);
expect
(
gqClient
.
query
).
toHaveBeenCalled
();
expect
(
wrapper
.
findComponent
(
GlButton
).
exists
()).
toBe
(
false
);
expect
(
wrapper
.
vm
.
handleShowMoreClick
).
toHaveBeenCalled
();
const
{
fullPath
,
iid
}
=
mockParentItem
;
expect
(
gqClient
.
query
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
variables
:
{
epicEndCursor
:
'
abc
'
,
fullPath
,
iid
,
issueEndCursor
:
'
def
'
,
},
}),
);
});
});
});
});
});
});
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录