Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
b8ecb2c7
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,体验更适合开发者的 AI 搜索 >>
提交
b8ecb2c7
编写于
9月 07, 2018
作者:
T
Tim Zallmann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added new tests for newly added mutations, actions, utils
上级
89c796db
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
221 addition
and
12 deletion
+221
-12
app/assets/javascripts/diffs/components/app.vue
app/assets/javascripts/diffs/components/app.vue
+2
-7
app/assets/javascripts/diffs/store/utils.js
app/assets/javascripts/diffs/store/utils.js
+1
-1
app/assets/javascripts/notes/stores/utils.js
app/assets/javascripts/notes/stores/utils.js
+0
-1
spec/javascripts/diffs/store/actions_spec.js
spec/javascripts/diffs/store/actions_spec.js
+162
-3
spec/javascripts/diffs/store/mutations_spec.js
spec/javascripts/diffs/store/mutations_spec.js
+37
-0
spec/javascripts/diffs/store/utils_spec.js
spec/javascripts/diffs/store/utils_spec.js
+19
-0
未找到文件。
app/assets/javascripts/diffs/components/app.vue
浏览文件 @
b8ecb2c7
...
@@ -127,13 +127,8 @@ export default {
...
@@ -127,13 +127,8 @@ export default {
.
then
(()
=>
{
.
then
(()
=>
{
requestIdleCallback
(
requestIdleCallback
(
()
=>
{
()
=>
{
this
.
startRenderDiffsQueue
()
this
.
setDiscussions
();
.
then
(()
=>
{
this
.
startRenderDiffsQueue
();
this
.
setDiscussions
();
})
.
catch
(()
=>
{
createFlash
(
__
(
'
Something went wrong on our end. Please try again!
'
));
});
},
},
{
timeout
:
1000
},
{
timeout
:
1000
},
);
);
...
...
app/assets/javascripts/diffs/store/utils.js
浏览文件 @
b8ecb2c7
...
@@ -182,8 +182,8 @@ export function trimFirstCharOfLineContent(line = {}) {
...
@@ -182,8 +182,8 @@ export function trimFirstCharOfLineContent(line = {}) {
}
}
export
function
prepareDiffData
(
diffData
)
{
export
function
prepareDiffData
(
diffData
)
{
let
showingLines
=
0
;
const
filesLength
=
diffData
.
diffFiles
.
length
;
const
filesLength
=
diffData
.
diffFiles
.
length
;
let
showingLines
=
0
;
let
i
;
let
i
;
for
(
i
=
0
;
i
<
filesLength
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
filesLength
;
i
+=
1
)
{
const
file
=
diffData
.
diffFiles
[
i
];
const
file
=
diffData
.
diffFiles
[
i
];
...
...
app/assets/javascripts/notes/stores/utils.js
浏览文件 @
b8ecb2c7
...
@@ -32,7 +32,6 @@ export const reduceDiscussionsToLineCodes = selectedDiscussions =>
...
@@ -32,7 +32,6 @@ export const reduceDiscussionsToLineCodes = selectedDiscussions =>
const
items
=
acc
[
note
.
line_code
]
||
[];
const
items
=
acc
[
note
.
line_code
]
||
[];
if
(
note
.
diff_file
)
{
if
(
note
.
diff_file
)
{
Object
.
assign
(
note
,
{
fileHash
:
note
.
diff_file
.
file_hash
});
Object
.
assign
(
note
,
{
fileHash
:
note
.
diff_file
.
file_hash
});
// delete note.diff_file;
}
}
items
.
push
(
note
);
items
.
push
(
note
);
...
...
spec/javascripts/diffs/store/actions_spec.js
浏览文件 @
b8ecb2c7
...
@@ -7,8 +7,11 @@ import {
...
@@ -7,8 +7,11 @@ import {
}
from
'
~/diffs/constants
'
;
}
from
'
~/diffs/constants
'
;
import
*
as
actions
from
'
~/diffs/store/actions
'
;
import
*
as
actions
from
'
~/diffs/store/actions
'
;
import
*
as
types
from
'
~/diffs/store/mutation_types
'
;
import
*
as
types
from
'
~/diffs/store/mutation_types
'
;
import
{
reduceDiscussionsToLineCodes
}
from
'
~/notes/stores/utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
testAction
from
'
../../helpers/vuex_action_helper
'
;
import
testAction
from
'
../../helpers/vuex_action_helper
'
;
import
mockFile
from
'
../mock_data/diff_file
'
;
import
mockDiscussion
from
'
../mock_data/diff_discussions
'
;
describe
(
'
DiffsStoreActions
'
,
()
=>
{
describe
(
'
DiffsStoreActions
'
,
()
=>
{
describe
(
'
setBaseConfig
'
,
()
=>
{
describe
(
'
setBaseConfig
'
,
()
=>
{
...
@@ -53,6 +56,150 @@ describe('DiffsStoreActions', () => {
...
@@ -53,6 +56,150 @@ describe('DiffsStoreActions', () => {
});
});
});
});
describe
(
'
assignDiscussionsToDiff
'
,
()
=>
{
it
(
'
should merge discussions into diffs
'
,
done
=>
{
const
state
=
{
diffFiles
:
[
Object
.
assign
({},
mockFile
)]
};
const
singleDiscussion
=
Object
.
assign
({},
mockDiscussion
);
const
discussions
=
reduceDiscussionsToLineCodes
([
singleDiscussion
]);
testAction
(
actions
.
assignDiscussionsToDiff
,
discussions
,
state
,
[
{
type
:
types
.
SET_LINE_DISCUSSIONS
,
payload
:
{
line
:
{
lineCode
:
'
1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2
'
,
type
:
'
new
'
,
oldLine
:
null
,
newLine
:
2
,
discussions
:
[],
text
:
'
+<span id="LC2" class="line" lang="plaintext"></span>
\n
'
,
richText
:
'
<span id="LC2" class="line" lang="plaintext"></span>
\n
'
,
metaData
:
null
,
},
discussions
:
discussions
[
'
1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2
'
],
},
},
{
type
:
types
.
SET_LINE_DISCUSSIONS
,
payload
:
{
line
:
{
lineCode
:
'
1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2
'
,
type
:
'
new
'
,
oldLine
:
null
,
newLine
:
2
,
discussions
:
[],
text
:
'
+<span id="LC2" class="line" lang="plaintext"></span>
\n
'
,
richText
:
'
+<span id="LC2" class="line" lang="plaintext"></span>
\n
'
,
metaData
:
null
,
},
discussions
:
discussions
[
'
1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2
'
],
},
},
],
[],
()
=>
{
done
();
},
);
});
});
describe
(
'
removeDiscussionsFromDiff
'
,
()
=>
{
it
(
'
should remove discussions from diffs
'
,
done
=>
{
const
state
=
{
diffFiles
:
[
Object
.
assign
({},
mockFile
)]
};
const
singleDiscussion
=
Object
.
assign
({},
mockDiscussion
);
reduceDiscussionsToLineCodes
([
singleDiscussion
]);
testAction
(
actions
.
removeDiscussionsFromDiff
,
singleDiscussion
,
state
,
[
{
type
:
types
.
REMOVE_LINE_DISCUSSIONS
,
payload
:
{
lineCode
:
'
1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2
'
,
type
:
'
new
'
,
oldLine
:
null
,
newLine
:
2
,
discussions
:
[],
text
:
'
+<span id="LC2" class="line" lang="plaintext"></span>
\n
'
,
richText
:
'
<span id="LC2" class="line" lang="plaintext"></span>
\n
'
,
metaData
:
null
,
},
},
{
type
:
types
.
REMOVE_LINE_DISCUSSIONS
,
payload
:
{
lineCode
:
'
1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2
'
,
type
:
'
new
'
,
oldLine
:
null
,
newLine
:
2
,
discussions
:
[],
text
:
'
+<span id="LC2" class="line" lang="plaintext"></span>
\n
'
,
richText
:
'
+<span id="LC2" class="line" lang="plaintext"></span>
\n
'
,
metaData
:
null
,
},
},
],
[],
()
=>
{
done
();
},
);
});
});
describe
(
'
startRenderDiffsQueue
'
,
()
=>
{
it
(
'
should set all files to RENDER_FILE
'
,
done
=>
{
const
actualRAF
=
global
.
requestAnimationFrame
;
global
.
requestAnimationFrame
=
cb
=>
{
cb
();
};
const
state
=
{
diffFiles
:
[
{
id
:
1
,
renderIt
:
false
,
collapsed
:
false
,
},
{
id
:
2
,
renderIt
:
false
,
collapsed
:
false
,
},
],
};
const
pseudoCommit
=
(
commitType
,
file
)
=>
{
expect
(
commitType
).
toBe
(
types
.
RENDER_FILE
);
Object
.
assign
(
file
,
{
renderIt
:
true
,
});
};
actions
.
startRenderDiffsQueue
({
state
,
commit
:
pseudoCommit
})
.
then
(()
=>
{
global
.
requestAnimationFrame
=
actualRAF
;
expect
(
state
.
diffFiles
[
0
].
renderIt
).
toBeTruthy
();
expect
(
state
.
diffFiles
[
1
].
renderIt
).
toBeTruthy
();
done
();
})
.
catch
(()
=>
{
done
.
fail
();
});
});
});
describe
(
'
setInlineDiffViewType
'
,
()
=>
{
describe
(
'
setInlineDiffViewType
'
,
()
=>
{
it
(
'
should set diff view type to inline and also set the cookie properly
'
,
done
=>
{
it
(
'
should set diff view type to inline and also set the cookie properly
'
,
done
=>
{
testAction
(
testAction
(
...
@@ -204,7 +351,11 @@ describe('DiffsStoreActions', () => {
...
@@ -204,7 +351,11 @@ describe('DiffsStoreActions', () => {
actions
.
toggleFileDiscussions
({
getters
,
dispatch
});
actions
.
toggleFileDiscussions
({
getters
,
dispatch
});
expect
(
dispatch
).
toHaveBeenCalledWith
(
'
collapseDiscussion
'
,
{
discussionId
:
1
},
{
root
:
true
});
expect
(
dispatch
).
toHaveBeenCalledWith
(
'
collapseDiscussion
'
,
{
discussionId
:
1
},
{
root
:
true
},
);
});
});
it
(
'
should dispatch expandDiscussion when all discussions are collapsed
'
,
()
=>
{
it
(
'
should dispatch expandDiscussion when all discussions are collapsed
'
,
()
=>
{
...
@@ -218,7 +369,11 @@ describe('DiffsStoreActions', () => {
...
@@ -218,7 +369,11 @@ describe('DiffsStoreActions', () => {
actions
.
toggleFileDiscussions
({
getters
,
dispatch
});
actions
.
toggleFileDiscussions
({
getters
,
dispatch
});
expect
(
dispatch
).
toHaveBeenCalledWith
(
'
expandDiscussion
'
,
{
discussionId
:
1
},
{
root
:
true
});
expect
(
dispatch
).
toHaveBeenCalledWith
(
'
expandDiscussion
'
,
{
discussionId
:
1
},
{
root
:
true
},
);
});
});
it
(
'
should dispatch expandDiscussion when some discussions are collapsed and others are expanded for the collapsed discussion
'
,
()
=>
{
it
(
'
should dispatch expandDiscussion when some discussions are collapsed and others are expanded for the collapsed discussion
'
,
()
=>
{
...
@@ -232,7 +387,11 @@ describe('DiffsStoreActions', () => {
...
@@ -232,7 +387,11 @@ describe('DiffsStoreActions', () => {
actions
.
toggleFileDiscussions
({
getters
,
dispatch
});
actions
.
toggleFileDiscussions
({
getters
,
dispatch
});
expect
(
dispatch
).
toHaveBeenCalledWith
(
'
expandDiscussion
'
,
{
discussionId
:
1
},
{
root
:
true
});
expect
(
dispatch
).
toHaveBeenCalledWith
(
'
expandDiscussion
'
,
{
discussionId
:
1
},
{
root
:
true
},
);
});
});
});
});
});
});
spec/javascripts/diffs/store/mutations_spec.js
浏览文件 @
b8ecb2c7
...
@@ -148,4 +148,41 @@ describe('DiffsStoreMutations', () => {
...
@@ -148,4 +148,41 @@ describe('DiffsStoreMutations', () => {
expect
(
state
.
diffFiles
[
1
].
extraField
).
toEqual
(
1
);
expect
(
state
.
diffFiles
[
1
].
extraField
).
toEqual
(
1
);
});
});
});
});
describe
(
'
SET_LINE_DISCUSSIONS
'
,
()
=>
{
it
(
'
should add discussions to the given line
'
,
()
=>
{
const
line
=
{
fileHash
:
'
ABC
'
,
discussions
:
[]
};
const
discussions
=
[
{
id
:
1
,
},
{
id
:
2
,
},
];
mutations
[
types
.
SET_LINE_DISCUSSIONS
]({},
{
line
,
discussions
});
expect
(
line
.
discussions
.
length
).
toEqual
(
2
);
expect
(
line
.
discussions
[
1
].
id
).
toEqual
(
2
);
});
});
describe
(
'
REMOVE_LINE_DISCUSSIONS
'
,
()
=>
{
it
(
'
should remove the existing discussions on the given line
'
,
()
=>
{
const
line
=
{
fileHash
:
'
ABC
'
,
discussions
:
[
{
id
:
1
,
},
{
id
:
2
,
},
],
};
mutations
[
types
.
REMOVE_LINE_DISCUSSIONS
]({},
line
);
expect
(
line
.
discussions
.
length
).
toEqual
(
0
);
});
});
});
});
spec/javascripts/diffs/store/utils_spec.js
浏览文件 @
b8ecb2c7
...
@@ -220,4 +220,23 @@ describe('DiffsStoreUtils', () => {
...
@@ -220,4 +220,23 @@ describe('DiffsStoreUtils', () => {
expect
(
utils
.
trimFirstCharOfLineContent
()).
toEqual
({
discussions
:
[]
});
expect
(
utils
.
trimFirstCharOfLineContent
()).
toEqual
({
discussions
:
[]
});
});
});
});
});
describe
(
'
prepareDiffData
'
,
()
=>
{
it
(
'
sets the renderIt and collapsed attribute on files
'
,
()
=>
{
const
preparedDiff
=
{
diffFiles
:
[
getDiffFileMock
()]
};
utils
.
prepareDiffData
(
preparedDiff
);
const
firstParallelDiffLine
=
preparedDiff
.
diffFiles
[
0
].
parallelDiffLines
[
2
];
expect
(
firstParallelDiffLine
.
left
.
discussions
.
length
).
toBe
(
0
);
expect
(
firstParallelDiffLine
.
left
).
not
.
toHaveAttr
(
'
text
'
);
expect
(
firstParallelDiffLine
.
right
.
discussions
.
length
).
toBe
(
0
);
expect
(
firstParallelDiffLine
.
right
).
not
.
toHaveAttr
(
'
text
'
);
expect
(
preparedDiff
.
diffFiles
[
0
].
highlightedDiffLines
[
0
].
discussions
.
length
).
toBe
(
0
);
expect
(
preparedDiff
.
diffFiles
[
0
].
highlightedDiffLines
[
0
]).
not
.
toHaveAttr
(
'
text
'
);
expect
(
preparedDiff
.
diffFiles
[
0
].
renderIt
).
toBeTruthy
();
expect
(
preparedDiff
.
diffFiles
[
0
].
collapsed
).
toBeFalsy
();
});
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录