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
32de3753
Commit
32de3753
authored
Jul 17, 2018
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disables toggle comments button for diff with no discussions
parent
ff060ad4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
8 deletions
+74
-8
app/assets/javascripts/diffs/components/diff_file_header.vue
app/assets/javascripts/diffs/components/diff_file_header.vue
+2
-1
app/assets/javascripts/diffs/store/getters.js
app/assets/javascripts/diffs/store/getters.js
+8
-0
changelogs/unreleased/49161-disable-toggle-comments.yml
changelogs/unreleased/49161-disable-toggle-comments.yml
+5
-0
spec/javascripts/diffs/components/diff_file_header_spec.js
spec/javascripts/diffs/components/diff_file_header_spec.js
+41
-7
spec/javascripts/diffs/store/getters_spec.js
spec/javascripts/diffs/store/getters_spec.js
+18
-0
No files found.
app/assets/javascripts/diffs/components/diff_file_header.vue
View file @
32de3753
...
@@ -50,7 +50,7 @@ export default {
...
@@ -50,7 +50,7 @@ export default {
};
};
},
},
computed
:
{
computed
:
{
...
mapGetters
(
'
diffs
'
,
[
'
diffHasExpandedDiscussions
'
]),
...
mapGetters
(
'
diffs
'
,
[
'
diffHasExpandedDiscussions
'
,
'
diffHasDiscussions
'
]),
hasExpandedDiscussions
()
{
hasExpandedDiscussions
()
{
return
this
.
diffHasExpandedDiscussions
(
this
.
diffFile
);
return
this
.
diffHasExpandedDiscussions
(
this
.
diffFile
);
},
},
...
@@ -221,6 +221,7 @@ export default {
...
@@ -221,6 +221,7 @@ export default {
v-if=
"diffFile.blob && diffFile.blob.readableText"
v-if=
"diffFile.blob && diffFile.blob.readableText"
>
>
<button
<button
:disabled=
"!diffHasDiscussions(diffFile)"
:class=
"
{ active: hasExpandedDiscussions }"
:class=
"
{ active: hasExpandedDiscussions }"
:title="s__('MergeRequests|Toggle comments for this file')"
:title="s__('MergeRequests|Toggle comments for this file')"
class="js-btn-vue-toggle-comments btn"
class="js-btn-vue-toggle-comments btn"
...
...
app/assets/javascripts/diffs/store/getters.js
View file @
32de3753
...
@@ -47,6 +47,14 @@ export const diffHasExpandedDiscussions = (state, getters) => diff => {
...
@@ -47,6 +47,14 @@ export const diffHasExpandedDiscussions = (state, getters) => diff => {
);
);
};
};
/**
* Checks if the diff has any discussion
* @param {Boolean} diff
* @returns {Boolean}
*/
export
const
diffHasDiscussions
=
(
state
,
getters
)
=>
diff
=>
getters
.
getDiffFileDiscussions
(
diff
).
length
>
0
;
/**
/**
* Returns an array with the discussions of the given diff
* Returns an array with the discussions of the given diff
* @param {Object} diff
* @param {Object} diff
...
...
changelogs/unreleased/49161-disable-toggle-comments.yml
0 → 100644
View file @
32de3753
---
title
:
Disables toggle comments button if diff has no discussions
merge_request
:
author
:
type
:
other
spec/javascripts/diffs/components/diff_file_header_spec.js
View file @
32de3753
...
@@ -11,7 +11,9 @@ const discussionFixture = 'merge_requests/diff_discussion.json';
...
@@ -11,7 +11,9 @@ const discussionFixture = 'merge_requests/diff_discussion.json';
describe
(
'
diff_file_header
'
,
()
=>
{
describe
(
'
diff_file_header
'
,
()
=>
{
let
vm
;
let
vm
;
let
props
;
let
props
;
const
diffDiscussionMock
=
getJSONFixture
(
discussionFixture
)[
0
];
const
Component
=
Vue
.
extend
(
DiffFileHeader
);
const
Component
=
Vue
.
extend
(
DiffFileHeader
);
const
store
=
new
Vuex
.
Store
({
const
store
=
new
Vuex
.
Store
({
modules
:
{
modules
:
{
diffs
:
diffsModule
,
diffs
:
diffsModule
,
...
@@ -20,7 +22,6 @@ describe('diff_file_header', () => {
...
@@ -20,7 +22,6 @@ describe('diff_file_header', () => {
});
});
beforeEach
(()
=>
{
beforeEach
(()
=>
{
const
diffDiscussionMock
=
getJSONFixture
(
discussionFixture
)[
0
];
const
diffFile
=
convertObjectPropsToCamelCase
(
diffDiscussionMock
.
diff_file
,
{
deep
:
true
});
const
diffFile
=
convertObjectPropsToCamelCase
(
diffDiscussionMock
.
diff_file
,
{
deep
:
true
});
props
=
{
props
=
{
diffFile
,
diffFile
,
...
@@ -409,7 +410,7 @@ describe('diff_file_header', () => {
...
@@ -409,7 +410,7 @@ describe('diff_file_header', () => {
});
});
describe
(
'
handles toggle discussions
'
,
()
=>
{
describe
(
'
handles toggle discussions
'
,
()
=>
{
it
(
'
dispatches toggleFileDiscussions when user clicks on toggle discussions button
'
,
()
=>
{
it
(
'
renders a disabled button when diff has no discussions
'
,
()
=>
{
const
propsCopy
=
Object
.
assign
({},
props
);
const
propsCopy
=
Object
.
assign
({},
props
);
propsCopy
.
diffFile
.
submodule
=
false
;
propsCopy
.
diffFile
.
submodule
=
false
;
propsCopy
.
diffFile
.
blob
=
{
propsCopy
.
diffFile
.
blob
=
{
...
@@ -428,11 +429,44 @@ describe('diff_file_header', () => {
...
@@ -428,11 +429,44 @@ describe('diff_file_header', () => {
store
,
store
,
});
});
spyOn
(
vm
,
'
toggleFileDiscussions
'
);
expect
(
vm
.
$el
.
querySelector
(
'
.js-btn-vue-toggle-comments
'
).
getAttribute
(
'
disabled
'
),
vm
.
$el
.
querySelector
(
'
.js-btn-vue-toggle-comments
'
).
click
();
).
toEqual
(
'
disabled
'
);
});
expect
(
vm
.
toggleFileDiscussions
).
toHaveBeenCalled
();
describe
(
'
with discussions
'
,
()
=>
{
it
(
'
dispatches toggleFileDiscussions when user clicks on toggle discussions button
'
,
()
=>
{
const
propsCopy
=
Object
.
assign
({},
props
);
propsCopy
.
diffFile
.
submodule
=
false
;
propsCopy
.
diffFile
.
blob
=
{
id
:
'
848ed9407c6730ff16edb3dd24485a0eea24292a
'
,
path
:
'
lib/base.js
'
,
name
:
'
base.js
'
,
mode
:
'
100644
'
,
readableText
:
true
,
icon
:
'
file-text-o
'
,
};
propsCopy
.
addMergeRequestButtons
=
true
;
propsCopy
.
diffFile
.
deletedFile
=
true
;
const
discussionGetter
=
()
=>
[
diffDiscussionMock
];
notesModule
.
getters
.
discussions
=
discussionGetter
;
vm
=
mountComponentWithStore
(
Component
,
{
props
:
propsCopy
,
store
:
new
Vuex
.
Store
({
modules
:
{
diffs
:
diffsModule
,
notes
:
notesModule
,
},
}),
});
spyOn
(
vm
,
'
toggleFileDiscussions
'
);
vm
.
$el
.
querySelector
(
'
.js-btn-vue-toggle-comments
'
).
click
();
expect
(
vm
.
toggleFileDiscussions
).
toHaveBeenCalled
();
});
});
});
});
});
});
});
...
...
spec/javascripts/diffs/store/getters_spec.js
View file @
32de3753
...
@@ -167,6 +167,24 @@ describe('Diffs Module Getters', () => {
...
@@ -167,6 +167,24 @@ describe('Diffs Module Getters', () => {
});
});
});
});
describe
(
'
diffHasDiscussions
'
,
()
=>
{
it
(
'
returns true when getDiffFileDiscussions returns discussions
'
,
()
=>
{
expect
(
getters
.
diffHasDiscussions
(
localState
,
{
getDiffFileDiscussions
:
()
=>
[
discussionMock
],
})(
diffFileMock
),
).
toEqual
(
true
);
});
it
(
'
returns false when getDiffFileDiscussions returns no discussions
'
,
()
=>
{
expect
(
getters
.
diffHasDiscussions
(
localState
,
{
getDiffFileDiscussions
:
()
=>
[],
})(
diffFileMock
),
).
toEqual
(
false
);
});
});
describe
(
'
getDiffFileDiscussions
'
,
()
=>
{
describe
(
'
getDiffFileDiscussions
'
,
()
=>
{
it
(
'
returns an array with discussions when fileHash matches and the discussion belongs to a diff
'
,
()
=>
{
it
(
'
returns an array with discussions when fileHash matches and the discussion belongs to a diff
'
,
()
=>
{
discussionMock
.
diff_file
.
file_hash
=
diffFileMock
.
fileHash
;
discussionMock
.
diff_file
.
file_hash
=
diffFileMock
.
fileHash
;
...
...
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