Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ee1c471b
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,发现更多精彩内容 >>
未验证
提交
ee1c471b
编写于
2月 01, 2018
作者:
P
Phil Hughes
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Converted pager.js to axios
上级
ab8e3a55
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
32 deletion
+77
-32
app/assets/javascripts/pager.js
app/assets/javascripts/pager.js
+16
-17
spec/javascripts/pager_spec.js
spec/javascripts/pager_spec.js
+61
-15
未找到文件。
app/assets/javascripts/pager.js
浏览文件 @
ee1c471b
import
{
getParameterByName
}
from
'
~/lib/utils/common_utils
'
;
import
axios
from
'
./lib/utils/axios_utils
'
;
import
{
removeParams
}
from
'
./lib/utils/url_utility
'
;
const
ENDLESS_SCROLL_BOTTOM_PX
=
400
;
...
...
@@ -22,24 +23,22 @@ export default {
getOld
()
{
this
.
loading
.
show
();
$
.
ajax
({
type
:
'
GET
'
,
url
:
this
.
url
,
data
:
`limit=
${
this
.
limit
}
&offset=
${
this
.
offset
}
`
,
dataType
:
'
json
'
,
error
:
()
=>
this
.
loading
.
hide
(),
success
:
(
data
)
=>
{
this
.
append
(
data
.
count
,
this
.
prepareData
(
data
.
html
));
this
.
callback
();
// keep loading until we've filled the viewport height
if
(
!
this
.
disable
&&
!
this
.
isScrollable
())
{
this
.
getOld
();
}
else
{
this
.
loading
.
hide
();
}
axios
.
get
(
this
.
url
,
{
params
:
{
limit
:
this
.
limit
,
offset
:
this
.
offset
,
},
});
}).
then
(({
data
})
=>
{
this
.
append
(
data
.
count
,
this
.
prepareData
(
data
.
html
));
this
.
callback
();
// keep loading until we've filled the viewport height
if
(
!
this
.
disable
&&
!
this
.
isScrollable
())
{
this
.
getOld
();
}
else
{
this
.
loading
.
hide
();
}
}).
catch
(()
=>
this
.
loading
.
hide
());
},
append
(
count
,
html
)
{
...
...
spec/javascripts/pager_spec.js
浏览文件 @
ee1c471b
/* global fixture */
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
*
as
utils
from
'
~/lib/utils/url_utility
'
;
import
Pager
from
'
~/pager
'
;
...
...
@@ -9,7 +10,6 @@ describe('pager', () => {
beforeEach
(()
=>
{
setFixtures
(
'
<div class="content_list"></div><div class="loading"></div>
'
);
spyOn
(
$
,
'
ajax
'
);
});
afterEach
(()
=>
{
...
...
@@ -47,39 +47,85 @@ describe('pager', () => {
});
describe
(
'
getOld
'
,
()
=>
{
const
urlRegex
=
/
\/
some_list
(
.*
)
$/
;
let
mock
;
function
mockSuccess
()
{
mock
.
onGet
(
urlRegex
).
reply
(
200
,
{
count
:
20
,
html
:
''
,
});
}
function
mockError
()
{
mock
.
onGet
(
urlRegex
).
networkError
();
}
beforeEach
(()
=>
{
setFixtures
(
'
<div class="content_list" data-href="/some_list"></div><div class="loading"></div>
'
);
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
();
Pager
.
init
();
mock
=
new
MockAdapter
(
axios
);
});
it
(
'
shows loader while loading next page
'
,
()
=>
{
afterEach
(()
=>
{
mock
.
restore
();
});
it
(
'
shows loader while loading next page
'
,
(
done
)
=>
{
mockSuccess
();
spyOn
(
Pager
.
loading
,
'
show
'
);
Pager
.
getOld
();
expect
(
Pager
.
loading
.
show
).
toHaveBeenCalled
();
setTimeout
(()
=>
{
expect
(
Pager
.
loading
.
show
).
toHaveBeenCalled
();
done
();
});
});
it
(
'
hides loader on success
'
,
()
=>
{
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(
options
=>
options
.
success
({}));
it
(
'
hides loader on success
'
,
(
done
)
=>
{
mockSuccess
();
spyOn
(
Pager
.
loading
,
'
hide
'
);
Pager
.
getOld
();
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
setTimeout
(()
=>
{
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
done
();
});
});
it
(
'
hides loader on error
'
,
()
=>
{
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(
options
=>
options
.
error
());
it
(
'
hides loader on error
'
,
(
done
)
=>
{
mockError
();
spyOn
(
Pager
.
loading
,
'
hide
'
);
Pager
.
getOld
();
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
setTimeout
(()
=>
{
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
done
();
});
});
it
(
'
sends request to url with offset and limit params
'
,
()
=>
{
spyOn
(
$
,
'
ajax
'
);
it
(
'
sends request to url with offset and limit params
'
,
(
done
)
=>
{
Pager
.
offset
=
100
;
Pager
.
limit
=
20
;
Pager
.
getOld
();
const
[{
data
,
url
}]
=
$
.
ajax
.
calls
.
argsFor
(
0
);
expect
(
data
).
toBe
(
'
limit=20&offset=100
'
);
expect
(
url
).
toBe
(
'
/some_list
'
);
setTimeout
(()
=>
{
const
[
url
,
params
]
=
$
.
ajax
.
calls
.
argsFor
(
0
);
console
.
log
(
url
,
params
);
// expect(data).toBe('limit=20&offset=100');
// expect(url).toBe('/some_list');
done
();
});
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录