Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
39bef72c
提交
39bef72c
编辑于
4 years ago
作者:
Payton Burdette
提交者:
Natalia Tepluhina
4 years ago
浏览文件
操作
下载
补丁
差异文件
Migrate pipelines actions spec
Migrate pipelines actions spec from karma to jest. And use vue test utils now.
上级
718a986d
No related branches found
No related tags found
无相关合并请求
变更
1
隐藏空白变更内容
行内
左右并排
显示
1 个更改的文件
spec/frontend/pipelines/pipelines_actions_spec.js
+142
-0
142 个添加, 0 个删除
spec/frontend/pipelines/pipelines_actions_spec.js
有
142 个添加
和
0 个删除
spec/
javascripts
/pipelines/pipelines_actions_spec.js
→
spec/
frontend
/pipelines/pipelines_actions_spec.js
+
142
−
0
浏览文件 @
39bef72c
import
Vue
from
'
vue
'
;
import
{
shallowMount
}
from
'
@
vue
/test-utils
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
mountComponent
from
'
spec/helpers/vue_mount_component_helper
'
;
import
{
TEST_HOST
}
from
'
spec/test_constants
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
PipelinesActions
from
'
~/pipelines/components/pipelines_actions.vue
'
;
import
{
GlDeprecatedButton
}
from
'
@gitlab/ui
'
;
import
GlCountdown
from
'
~/vue_shared/components/gl_countdown.vue
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
describe
(
'
Pipelines Actions dropdown
'
,
()
=>
{
const
Component
=
Vue
.
extend
(
PipelinesActions
);
let
vm
;
let
wrapper
;
let
mock
;
afterEach
(()
=>
{
vm
.
$destroy
();
mock
.
restore
();
});
const
createComponent
=
(
actions
=
[])
=>
{
wrapper
=
shallowMount
(
PipelinesActions
,
{
propsData
:
{
actions
,
},
});
};
const
findAllDropdownItems
=
()
=>
wrapper
.
findAll
(
GlDeprecatedButton
);
const
findAllCountdowns
=
()
=>
wrapper
.
findAll
(
GlCountdown
);
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
});
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
=
null
;
mock
.
restore
();
});
describe
(
'
manual actions
'
,
()
=>
{
const
a
ctions
=
[
const
mockA
ctions
=
[
{
name
:
'
stop_review
'
,
path
:
`
${
TEST_HOST
}
/root/review-app/builds/1893/play`
,
...
...
@@ -33,33 +47,31 @@ describe('Pipelines Actions dropdown', () => {
];
beforeEach
(()
=>
{
vm
=
mountComponent
(
Component
,
{
a
ctions
}
);
createComponent
(
mockA
ctions
);
});
it
(
'
renders a dropdown with the provided actions
'
,
()
=>
{
const
dropdownItems
=
vm
.
$el
.
querySelectorAll
(
'
.dropdown-menu li
'
);
expect
(
dropdownItems
.
length
).
toEqual
(
actions
.
length
);
expect
(
findAllDropdownItems
()).
toHaveLength
(
mockActions
.
length
);
});
it
(
"
renders a disabled action when it's not playable
"
,
()
=>
{
const
dropdownItem
=
vm
.
$el
.
querySelector
(
'
.dropdown-menu li:last-child button
'
);
expect
(
dropdownItem
).
toBeDisabled
();
expect
(
findAllDropdownItems
()
.
at
(
1
)
.
attributes
(
'
disabled
'
),
).
toBe
(
'
true
'
);
});
describe
(
'
on click
'
,
()
=>
{
it
(
'
makes a request and toggles the loading state
'
,
done
=>
{
mock
.
onPost
(
actions
.
path
).
reply
(
200
);
vm
.
$el
.
querySelector
(
'
.dropdown-menu li button
'
).
click
();
it
(
'
makes a request and toggles the loading state
'
,
()
=>
{
mock
.
onPost
(
mockActions
.
path
).
reply
(
200
);
expect
(
vm
.
isLoading
).
toEqual
(
true
);
wrapper
.
find
(
GlDeprecatedButton
).
vm
.
$emit
(
'
click
'
);
setTimeout
(()
=>
{
expect
(
vm
.
isLoading
).
toEqual
(
false
);
expect
(
wrapper
.
vm
.
isLoading
).
toBe
(
true
);
done
();
return
waitForPromises
().
then
(()
=>
{
expect
(
wrapper
.
vm
.
isLoading
).
toBe
(
false
);
});
});
});
...
...
@@ -78,51 +90,53 @@ describe('Pipelines Actions dropdown', () => {
playable
:
true
,
scheduled_at
:
'
2018-10-05T08:23:00Z
'
,
};
const
findDropdownItem
=
action
=>
{
const
buttons
=
vm
.
$el
.
querySelectorAll
(
'
.dropdown-menu li button
'
);
return
Array
.
prototype
.
find
.
call
(
buttons
,
element
=>
element
.
innerText
.
trim
().
startsWith
(
action
.
name
),
);
};
beforeEach
(
done
=>
{
spyOn
(
Date
,
'
now
'
).
and
.
callFake
(()
=>
new
Date
(
'
2063-04-04T00:42:00Z
'
).
getTime
());
vm
=
mountComponent
(
Component
,
{
actions
:
[
scheduledJobAction
,
expiredJobAction
]
});
Vue
.
nextTick
()
.
then
(
done
)
.
catch
(
done
.
fail
);
beforeEach
(()
=>
{
jest
.
spyOn
(
Date
,
'
now
'
).
mockImplementation
(()
=>
new
Date
(
'
2063-04-04T00:42:00Z
'
).
getTime
());
createComponent
([
scheduledJobAction
,
expiredJobAction
]
);
});
it
(
'
makes post request after confirming
'
,
done
=>
{
it
(
'
makes post request after confirming
'
,
()
=>
{
mock
.
onPost
(
scheduledJobAction
.
path
).
reply
(
200
);
spyOn
(
window
,
'
confirm
'
).
and
.
callFake
(()
=>
true
);
jest
.
spyOn
(
window
,
'
confirm
'
).
mockReturnValue
(
true
);
findDropdownItem
(
scheduledJobAction
).
click
();
findAllDropdownItems
()
.
at
(
0
)
.
vm
.
$emit
(
'
click
'
);
expect
(
window
.
confirm
).
toHaveBeenCalled
();
setTimeout
(()
=>
{
return
waitForPromises
().
then
(()
=>
{
expect
(
mock
.
history
.
post
.
length
).
toBe
(
1
);
done
();
});
});
it
(
'
does not make post request if confirmation is cancelled
'
,
()
=>
{
mock
.
onPost
(
scheduledJobAction
.
path
).
reply
(
200
);
spyOn
(
window
,
'
confirm
'
).
and
.
callFake
(()
=>
false
);
jest
.
spyOn
(
window
,
'
confirm
'
).
mockReturnValue
(
false
);
findDropdownItem
(
scheduledJobAction
).
click
();
findAllDropdownItems
()
.
at
(
0
)
.
vm
.
$emit
(
'
click
'
);
expect
(
window
.
confirm
).
toHaveBeenCalled
();
expect
(
mock
.
history
.
post
.
length
).
toBe
(
0
);
});
it
(
'
displays the remaining time in the dropdown
'
,
()
=>
{
expect
(
findDropdownItem
(
scheduledJobAction
)).
toContainText
(
'
24:00:00
'
);
expect
(
findAllCountdowns
()
.
at
(
0
)
.
props
(
'
endDateString
'
),
).
toBe
(
scheduledJobAction
.
scheduled_at
);
});
it
(
'
displays 00:00:00 for expired jobs in the dropdown
'
,
()
=>
{
expect
(
findDropdownItem
(
expiredJobAction
)).
toContainText
(
'
00:00:00
'
);
expect
(
findAllCountdowns
()
.
at
(
1
)
.
props
(
'
endDateString
'
),
).
toBe
(
expiredJobAction
.
scheduled_at
);
});
});
});
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录