Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b8ecb2c7
Commit
b8ecb2c7
authored
Sep 07, 2018
by
Tim Zallmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new tests for newly added mutations, actions, utils
parent
89c796db
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
221 additions
and
12 deletions
+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
No files found.
app/assets/javascripts/diffs/components/app.vue
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
View file @
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
();
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment