Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
63d3581e
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,发现更多精彩内容 >>
未验证
提交
63d3581e
编写于
3月 12, 2018
作者:
P
Phil Hughes
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed note polling not sending updated last fetched at date
added spec for polling
上级
98e31bf4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
71 addition
and
7 deletion
+71
-7
app/assets/javascripts/notes/services/notes_service.js
app/assets/javascripts/notes/services/notes_service.js
+3
-2
app/assets/javascripts/notes/stores/actions.js
app/assets/javascripts/notes/stores/actions.js
+2
-4
spec/javascripts/notes/mock_data.js
spec/javascripts/notes/mock_data.js
+1
-1
spec/javascripts/notes/stores/actions_spec.js
spec/javascripts/notes/stores/actions_spec.js
+65
-0
未找到文件。
app/assets/javascripts/notes/services/notes_service.js
浏览文件 @
63d3581e
...
@@ -27,10 +27,11 @@ export default {
...
@@ -27,10 +27,11 @@ export default {
return
Vue
.
http
[
method
](
endpoint
);
return
Vue
.
http
[
method
](
endpoint
);
},
},
poll
(
data
=
{})
{
poll
(
data
=
{})
{
const
{
endpoint
,
lastFetchedAt
}
=
data
;
const
endpoint
=
data
.
notesData
.
notesPath
;
const
lastFetchedAt
=
data
.
lastFetchedAt
;
const
options
=
{
const
options
=
{
headers
:
{
headers
:
{
'
X-Last-Fetched-At
'
:
`
${
lastFetchedAt
}
`
,
'
X-Last-Fetched-At
'
:
lastFetchedAt
?
`
${
lastFetchedAt
}
`
:
undefined
,
},
},
};
};
...
...
app/assets/javascripts/notes/stores/actions.js
浏览文件 @
63d3581e
...
@@ -203,12 +203,10 @@ const pollSuccessCallBack = (resp, commit, state, getters) => {
...
@@ -203,12 +203,10 @@ const pollSuccessCallBack = (resp, commit, state, getters) => {
};
};
export
const
poll
=
({
commit
,
state
,
getters
})
=>
{
export
const
poll
=
({
commit
,
state
,
getters
})
=>
{
const
requestData
=
{
endpoint
:
state
.
notesData
.
notesPath
,
lastFetchedAt
:
state
.
lastFetchedAt
};
eTagPoll
=
new
Poll
({
eTagPoll
=
new
Poll
({
resource
:
service
,
resource
:
service
,
method
:
'
poll
'
,
method
:
'
poll
'
,
data
:
requestData
,
data
:
state
,
successCallback
:
resp
=>
resp
.
json
()
successCallback
:
resp
=>
resp
.
json
()
.
then
(
data
=>
pollSuccessCallBack
(
data
,
commit
,
state
,
getters
)),
.
then
(
data
=>
pollSuccessCallBack
(
data
,
commit
,
state
,
getters
)),
errorCallback
:
()
=>
Flash
(
'
Something went wrong while fetching latest comments.
'
),
errorCallback
:
()
=>
Flash
(
'
Something went wrong while fetching latest comments.
'
),
...
@@ -217,7 +215,7 @@ export const poll = ({ commit, state, getters }) => {
...
@@ -217,7 +215,7 @@ export const poll = ({ commit, state, getters }) => {
if
(
!
Visibility
.
hidden
())
{
if
(
!
Visibility
.
hidden
())
{
eTagPoll
.
makeRequest
();
eTagPoll
.
makeRequest
();
}
else
{
}
else
{
service
.
poll
(
requestData
);
service
.
poll
(
state
);
}
}
Visibility
.
change
(()
=>
{
Visibility
.
change
(()
=>
{
...
...
spec/javascripts/notes/mock_data.js
浏览文件 @
63d3581e
/* eslint-disable */
/* eslint-disable */
export
const
notesDataMock
=
{
export
const
notesDataMock
=
{
discussionsPath
:
'
/gitlab-org/gitlab-ce/issues/26/discussions.json
'
,
discussionsPath
:
'
/gitlab-org/gitlab-ce/issues/26/discussions.json
'
,
lastFetchedAt
:
'
1501862675
'
,
lastFetchedAt
:
1501862675
,
markdownDocsPath
:
'
/help/user/markdown
'
,
markdownDocsPath
:
'
/help/user/markdown
'
,
newSessionPath
:
'
/users/sign_in?redirect_to_referer=yes
'
,
newSessionPath
:
'
/users/sign_in?redirect_to_referer=yes
'
,
notesPath
:
'
/gitlab-org/gitlab-ce/noteable/issue/98/notes
'
,
notesPath
:
'
/gitlab-org/gitlab-ce/noteable/issue/98/notes
'
,
...
...
spec/javascripts/notes/stores/actions_spec.js
浏览文件 @
63d3581e
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
_
from
'
underscore
'
;
import
_
from
'
underscore
'
;
import
{
headersInterceptor
}
from
'
spec/helpers/vue_resource_helper
'
;
import
*
as
actions
from
'
~/notes/stores/actions
'
;
import
*
as
actions
from
'
~/notes/stores/actions
'
;
import
store
from
'
~/notes/stores
'
;
import
store
from
'
~/notes/stores
'
;
import
testAction
from
'
../../helpers/vuex_action_helper
'
;
import
testAction
from
'
../../helpers/vuex_action_helper
'
;
...
@@ -129,4 +130,68 @@ describe('Actions Notes Store', () => {
...
@@ -129,4 +130,68 @@ describe('Actions Notes Store', () => {
],
done
);
],
done
);
});
});
});
});
describe
(
'
poll
'
,
()
=>
{
beforeEach
((
done
)
=>
{
jasmine
.
clock
().
install
();
spyOn
(
Vue
.
http
,
'
get
'
).
and
.
callThrough
();
store
.
dispatch
(
'
setNotesData
'
,
notesDataMock
)
.
then
(
done
)
.
catch
(
done
.
fail
);
});
afterEach
(()
=>
{
jasmine
.
clock
().
uninstall
();
});
it
(
'
calls service with last fetched state
'
,
(
done
)
=>
{
const
interceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
({
notes
:
[],
last_fetched_at
:
'
123456
'
,
}),
{
status
:
200
,
headers
:
{
'
poll-interval
'
:
'
1000
'
,
},
}));
};
Vue
.
http
.
interceptors
.
push
(
interceptor
);
Vue
.
http
.
interceptors
.
push
(
headersInterceptor
);
store
.
dispatch
(
'
poll
'
)
.
then
(()
=>
new
Promise
(
resolve
=>
requestAnimationFrame
(
resolve
)))
.
then
(()
=>
{
expect
(
Vue
.
http
.
get
).
toHaveBeenCalledWith
(
jasmine
.
anything
(),
{
url
:
jasmine
.
anything
(),
method
:
'
get
'
,
headers
:
{
'
X-Last-Fetched-At
'
:
undefined
,
},
});
expect
(
store
.
state
.
lastFetchedAt
).
toBe
(
'
123456
'
);
jasmine
.
clock
().
tick
(
1500
);
})
.
then
(()
=>
new
Promise
((
resolve
)
=>
{
requestAnimationFrame
(
resolve
);
}))
.
then
(()
=>
{
expect
(
Vue
.
http
.
get
.
calls
.
count
()).
toBe
(
2
);
expect
(
Vue
.
http
.
get
.
calls
.
mostRecent
().
args
[
1
].
headers
).
toEqual
({
'
X-Last-Fetched-At
'
:
'
123456
'
,
});
})
.
then
(()
=>
store
.
dispatch
(
'
stopPolling
'
))
.
then
(()
=>
{
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
interceptor
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
headersInterceptor
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录