Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ab7b01aa
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ab7b01aa
编写于
4月 24, 2018
作者:
C
Clement Ho
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'winh-mock-pager' into 'master'
Mock Pager in Karma tests See merge request gitlab-org/gitlab-ce!18556
上级
87cdd43b
92be3461
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
71 addition
and
51 deletion
+71
-51
spec/javascripts/activities_spec.js
spec/javascripts/activities_spec.js
+42
-33
spec/javascripts/commits_spec.js
spec/javascripts/commits_spec.js
+8
-4
spec/javascripts/pager_spec.js
spec/javascripts/pager_spec.js
+21
-14
未找到文件。
spec/javascripts/activities_spec.js
浏览文件 @
ab7b01aa
...
...
@@ -3,24 +3,30 @@
import
$
from
'
jquery
'
;
import
'
vendor/jquery.endless-scroll
'
;
import
Activities
from
'
~/activities
'
;
import
Pager
from
'
~/pager
'
;
(
()
=>
{
describe
(
'
Activities
'
,
()
=>
{
window
.
gon
||
(
window
.
gon
=
{});
const
fixtureTemplate
=
'
static/event_filter.html.raw
'
;
const
filters
=
[
{
id
:
'
all
'
,
},
{
},
{
id
:
'
push
'
,
name
:
'
push events
'
,
},
{
},
{
id
:
'
merged
'
,
name
:
'
merge events
'
,
},
{
},
{
id
:
'
comments
'
,
},
{
},
{
id
:
'
team
'
,
}];
},
];
function
getEventName
(
index
)
{
const
filter
=
filters
[
index
];
...
...
@@ -32,31 +38,34 @@ import Activities from '~/activities';
return
`#
${
filter
.
id
}
_event_filter`
;
}
describe
(
'
Activities
'
,
()
=>
{
beforeEach
(()
=>
{
loadFixtures
(
fixtureTemplate
);
spyOn
(
Pager
,
'
init
'
).
and
.
stub
();
new
Activities
();
});
for
(
let
i
=
0
;
i
<
filters
.
length
;
i
+=
1
)
{
((
i
)
=>
{
(
i
=>
{
describe
(
`when selecting
${
getEventName
(
i
)}
`
,
()
=>
{
beforeEach
(()
=>
{
$
(
getSelector
(
i
)).
click
();
});
for
(
let
x
=
0
;
x
<
filters
.
length
;
x
+=
1
)
{
((
x
)
=>
{
(
x
=>
{
const
shouldHighlight
=
i
===
x
;
const
testName
=
shouldHighlight
?
'
should highlight
'
:
'
should not highlight
'
;
it
(
`
${
testName
}
${
getEventName
(
x
)}
`
,
()
=>
{
expect
(
$
(
getSelector
(
x
)).
parent
().
hasClass
(
'
active
'
)).
toEqual
(
shouldHighlight
);
expect
(
$
(
getSelector
(
x
))
.
parent
()
.
hasClass
(
'
active
'
),
).
toEqual
(
shouldHighlight
);
});
})(
x
);
}
});
})(
i
);
}
});
})();
});
spec/javascripts/commits_spec.js
浏览文件 @
ab7b01aa
...
...
@@ -3,6 +3,7 @@ import 'vendor/jquery.endless-scroll';
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
CommitsList
from
'
~/commits
'
;
import
Pager
from
'
~/pager
'
;
describe
(
'
Commits List
'
,
()
=>
{
let
commitsList
;
...
...
@@ -14,6 +15,7 @@ describe('Commits List', () => {
</form>
<ol id="commits-list"></ol>
`
);
spyOn
(
Pager
,
'
init
'
).
and
.
stub
();
commitsList
=
new
CommitsList
(
25
);
});
...
...
@@ -68,9 +70,10 @@ describe('Commits List', () => {
mock
.
restore
();
});
it
(
'
should save the last search string
'
,
(
done
)
=>
{
it
(
'
should save the last search string
'
,
done
=>
{
commitsList
.
searchField
.
val
(
'
GitLab
'
);
commitsList
.
filterResults
()
commitsList
.
filterResults
()
.
then
(()
=>
{
expect
(
ajaxSpy
).
toHaveBeenCalled
();
expect
(
commitsList
.
lastSearch
).
toEqual
(
'
GitLab
'
);
...
...
@@ -80,8 +83,9 @@ describe('Commits List', () => {
.
catch
(
done
.
fail
);
});
it
(
'
should not make ajax call if the input does not change
'
,
(
done
)
=>
{
commitsList
.
filterResults
()
it
(
'
should not make ajax call if the input does not change
'
,
done
=>
{
commitsList
.
filterResults
()
.
then
(()
=>
{
expect
(
ajaxSpy
).
not
.
toHaveBeenCalled
();
expect
(
commitsList
.
lastSearch
).
toEqual
(
''
);
...
...
spec/javascripts/pager_spec.js
浏览文件 @
ab7b01aa
import
$
from
'
jquery
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
Pager
from
'
~/pager
'
;
describe
(
'
pager
'
,
()
=>
{
let
axiosMock
;
beforeEach
(()
=>
{
axiosMock
=
new
MockAdapter
(
axios
);
});
afterEach
(()
=>
{
axiosMock
.
restore
();
});
describe
(
'
init
'
,
()
=>
{
const
originalHref
=
window
.
location
.
href
;
beforeEach
(()
=>
{
setFixtures
(
'
<div class="content_list"></div><div class="loading"></div>
'
);
spyOn
(
$
.
fn
,
'
endlessScroll
'
).
and
.
stub
();
});
afterEach
(()
=>
{
...
...
@@ -46,33 +58,28 @@ describe('pager', () => {
describe
(
'
getOld
'
,
()
=>
{
const
urlRegex
=
/
(
.*
)
some_list
(
.*
)
$/
;
let
mock
;
function
mockSuccess
()
{
m
ock
.
onGet
(
urlRegex
).
reply
(
200
,
{
axiosM
ock
.
onGet
(
urlRegex
).
reply
(
200
,
{
count
:
0
,
html
:
''
,
});
}
function
mockError
()
{
m
ock
.
onGet
(
urlRegex
).
networkError
();
axiosM
ock
.
onGet
(
urlRegex
).
networkError
();
}
beforeEach
(()
=>
{
setFixtures
(
'
<div class="content_list" data-href="/some_list"></div><div class="loading"></div>
'
);
setFixtures
(
'
<div class="content_list" data-href="/some_list"></div><div class="loading"></div>
'
,
);
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
();
mock
=
new
MockAdapter
(
axios
);
Pager
.
init
();
});
afterEach
(()
=>
{
mock
.
restore
();
});
it
(
'
shows loader while loading next page
'
,
(
done
)
=>
{
it
(
'
shows loader while loading next page
'
,
done
=>
{
mockSuccess
();
spyOn
(
Pager
.
loading
,
'
show
'
);
...
...
@@ -85,7 +92,7 @@ describe('pager', () => {
});
});
it
(
'
hides loader on success
'
,
(
done
)
=>
{
it
(
'
hides loader on success
'
,
done
=>
{
mockSuccess
();
spyOn
(
Pager
.
loading
,
'
hide
'
);
...
...
@@ -98,7 +105,7 @@ describe('pager', () => {
});
});
it
(
'
hides loader on error
'
,
(
done
)
=>
{
it
(
'
hides loader on error
'
,
done
=>
{
mockError
();
spyOn
(
Pager
.
loading
,
'
hide
'
);
...
...
@@ -111,7 +118,7 @@ describe('pager', () => {
});
});
it
(
'
sends request to url with offset and limit params
'
,
(
done
)
=>
{
it
(
'
sends request to url with offset and limit params
'
,
done
=>
{
Pager
.
offset
=
100
;
Pager
.
limit
=
20
;
Pager
.
getOld
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录