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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
982da16b
Commit
982da16b
authored
Sep 07, 2018
by
Tim Zallmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the discussion tests artificial to have them stable, mocked RAF + RIC
parent
b8ecb2c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
46 deletions
+98
-46
app/assets/javascripts/diffs/store/actions.js
app/assets/javascripts/diffs/store/actions.js
+1
-0
spec/javascripts/diffs/store/actions_spec.js
spec/javascripts/diffs/store/actions_spec.js
+97
-46
No files found.
app/assets/javascripts/diffs/store/actions.js
View file @
982da16b
...
@@ -65,6 +65,7 @@ export const assignDiscussionsToDiff = ({ state, commit }, allLineDiscussions) =
...
@@ -65,6 +65,7 @@ export const assignDiscussionsToDiff = ({ state, commit }, allLineDiscussions) =
export
const
removeDiscussionsFromDiff
=
({
state
,
commit
},
removeDiscussion
)
=>
{
export
const
removeDiscussionsFromDiff
=
({
state
,
commit
},
removeDiscussion
)
=>
{
const
{
fileHash
}
=
removeDiscussion
;
const
{
fileHash
}
=
removeDiscussion
;
const
selectedFile
=
state
.
diffFiles
.
find
(
file
=>
file
.
fileHash
===
fileHash
);
const
selectedFile
=
state
.
diffFiles
.
find
(
file
=>
file
.
fileHash
===
fileHash
);
if
(
selectedFile
)
{
if
(
selectedFile
)
{
const
targetLine
=
selectedFile
.
parallelDiffLines
.
find
(
const
targetLine
=
selectedFile
.
parallelDiffLines
.
find
(
line
=>
line
=>
...
...
spec/javascripts/diffs/store/actions_spec.js
View file @
982da16b
...
@@ -10,10 +10,27 @@ import * as types from '~/diffs/store/mutation_types';
...
@@ -10,10 +10,27 @@ import * as types from '~/diffs/store/mutation_types';
import
{
reduceDiscussionsToLineCodes
}
from
'
~/notes/stores/utils
'
;
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
'
,
()
=>
{
const
originalMethods
=
{
requestAnimationFrame
:
global
.
requestAnimationFrame
,
requestIdleCallback
:
global
.
requestIdleCallback
,
};
beforeEach
(()
=>
{
[
'
requestAnimationFrame
'
,
'
requestIdleCallback
'
].
forEach
(
method
=>
{
global
[
method
]
=
cb
=>
{
cb
();
};
});
});
afterEach
(()
=>
{
[
'
requestAnimationFrame
'
,
'
requestIdleCallback
'
].
forEach
(
method
=>
{
global
[
method
]
=
originalMethods
[
method
];
});
});
describe
(
'
setBaseConfig
'
,
()
=>
{
describe
(
'
setBaseConfig
'
,
()
=>
{
it
(
'
should set given endpoint and project path
'
,
done
=>
{
it
(
'
should set given endpoint and project path
'
,
done
=>
{
const
endpoint
=
'
/diffs/set/endpoint
'
;
const
endpoint
=
'
/diffs/set/endpoint
'
;
...
@@ -58,8 +75,40 @@ describe('DiffsStoreActions', () => {
...
@@ -58,8 +75,40 @@ describe('DiffsStoreActions', () => {
describe
(
'
assignDiscussionsToDiff
'
,
()
=>
{
describe
(
'
assignDiscussionsToDiff
'
,
()
=>
{
it
(
'
should merge discussions into diffs
'
,
done
=>
{
it
(
'
should merge discussions into diffs
'
,
done
=>
{
const
state
=
{
diffFiles
:
[
Object
.
assign
({},
mockFile
)]
};
const
state
=
{
const
singleDiscussion
=
Object
.
assign
({},
mockDiscussion
);
diffFiles
:
[
{
fileHash
:
'
ABC
'
,
parallelDiffLines
:
[
{
left
:
{
lineCode
:
'
ABC_1_1
'
,
discussions
:
[],
},
right
:
{
lineCode
:
'
ABC_1_1
'
,
discussions
:
[],
},
},
],
highlightedDiffLines
:
[
{
lineCode
:
'
ABC_1_1
'
,
discussions
:
[],
},
],
},
],
};
const
singleDiscussion
=
{
line_code
:
'
ABC_1_1
'
,
diff_discussion
:
{},
diff_file
:
{
file_hash
:
'
ABC
'
,
},
resolvable
:
true
,
};
const
discussions
=
reduceDiscussionsToLineCodes
([
singleDiscussion
]);
const
discussions
=
reduceDiscussionsToLineCodes
([
singleDiscussion
]);
testAction
(
testAction
(
...
@@ -71,32 +120,20 @@ describe('DiffsStoreActions', () => {
...
@@ -71,32 +120,20 @@ describe('DiffsStoreActions', () => {
type
:
types
.
SET_LINE_DISCUSSIONS
,
type
:
types
.
SET_LINE_DISCUSSIONS
,
payload
:
{
payload
:
{
line
:
{
line
:
{
lineCode
:
'
1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2
'
,
lineCode
:
'
ABC_1_1
'
,
type
:
'
new
'
,
oldLine
:
null
,
newLine
:
2
,
discussions
:
[],
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
'
],
discussions
:
[
singleDiscussion
],
},
},
},
},
{
{
type
:
types
.
SET_LINE_DISCUSSIONS
,
type
:
types
.
SET_LINE_DISCUSSIONS
,
payload
:
{
payload
:
{
line
:
{
line
:
{
lineCode
:
'
1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2
'
,
lineCode
:
'
ABC_1_1
'
,
type
:
'
new
'
,
oldLine
:
null
,
newLine
:
2
,
discussions
:
[],
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
'
],
discussions
:
[
singleDiscussion
],
},
},
},
},
],
],
...
@@ -110,10 +147,39 @@ describe('DiffsStoreActions', () => {
...
@@ -110,10 +147,39 @@ describe('DiffsStoreActions', () => {
describe
(
'
removeDiscussionsFromDiff
'
,
()
=>
{
describe
(
'
removeDiscussionsFromDiff
'
,
()
=>
{
it
(
'
should remove discussions from diffs
'
,
done
=>
{
it
(
'
should remove discussions from diffs
'
,
done
=>
{
const
state
=
{
diffFiles
:
[
Object
.
assign
({},
mockFile
)]
};
const
state
=
{
const
singleDiscussion
=
Object
.
assign
({},
mockDiscussion
);
diffFiles
:
[
{
reduceDiscussionsToLineCodes
([
singleDiscussion
]);
fileHash
:
'
ABC
'
,
parallelDiffLines
:
[
{
left
:
{
lineCode
:
'
ABC_1_1
'
,
discussions
:
[
{
id
:
1
,
},
],
},
right
:
{
lineCode
:
'
ABC_1_1
'
,
discussions
:
[],
},
},
],
highlightedDiffLines
:
[
{
lineCode
:
'
ABC_1_1
'
,
discussions
:
[],
},
],
},
],
};
const
singleDiscussion
=
{
fileHash
:
'
ABC
'
,
line_code
:
'
ABC_1_1
'
,
};
testAction
(
testAction
(
actions
.
removeDiscussionsFromDiff
,
actions
.
removeDiscussionsFromDiff
,
...
@@ -123,27 +189,19 @@ describe('DiffsStoreActions', () => {
...
@@ -123,27 +189,19 @@ describe('DiffsStoreActions', () => {
{
{
type
:
types
.
REMOVE_LINE_DISCUSSIONS
,
type
:
types
.
REMOVE_LINE_DISCUSSIONS
,
payload
:
{
payload
:
{
lineCode
:
'
1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2
'
,
lineCode
:
'
ABC_1_1
'
,
type
:
'
new
'
,
discussions
:
[
oldLine
:
null
,
{
newLine
:
2
,
id
:
1
,
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
,
type
:
types
.
REMOVE_LINE_DISCUSSIONS
,
payload
:
{
payload
:
{
lineCode
:
'
1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2
'
,
lineCode
:
'
ABC_1_1
'
,
type
:
'
new
'
,
oldLine
:
null
,
newLine
:
2
,
discussions
:
[],
discussions
:
[],
text
:
'
+<span id="LC2" class="line" lang="plaintext"></span>
\n
'
,
richText
:
'
+<span id="LC2" class="line" lang="plaintext"></span>
\n
'
,
metaData
:
null
,
},
},
},
},
],
],
...
@@ -157,11 +215,6 @@ describe('DiffsStoreActions', () => {
...
@@ -157,11 +215,6 @@ describe('DiffsStoreActions', () => {
describe
(
'
startRenderDiffsQueue
'
,
()
=>
{
describe
(
'
startRenderDiffsQueue
'
,
()
=>
{
it
(
'
should set all files to RENDER_FILE
'
,
done
=>
{
it
(
'
should set all files to RENDER_FILE
'
,
done
=>
{
const
actualRAF
=
global
.
requestAnimationFrame
;
global
.
requestAnimationFrame
=
cb
=>
{
cb
();
};
const
state
=
{
const
state
=
{
diffFiles
:
[
diffFiles
:
[
{
{
...
@@ -187,8 +240,6 @@ describe('DiffsStoreActions', () => {
...
@@ -187,8 +240,6 @@ describe('DiffsStoreActions', () => {
actions
actions
.
startRenderDiffsQueue
({
state
,
commit
:
pseudoCommit
})
.
startRenderDiffsQueue
({
state
,
commit
:
pseudoCommit
})
.
then
(()
=>
{
.
then
(()
=>
{
global
.
requestAnimationFrame
=
actualRAF
;
expect
(
state
.
diffFiles
[
0
].
renderIt
).
toBeTruthy
();
expect
(
state
.
diffFiles
[
0
].
renderIt
).
toBeTruthy
();
expect
(
state
.
diffFiles
[
1
].
renderIt
).
toBeTruthy
();
expect
(
state
.
diffFiles
[
1
].
renderIt
).
toBeTruthy
();
...
...
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