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
1935282f
Commit
1935282f
authored
Feb 22, 2021
by
Thomas Randolph
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update whitespace toggle to use GlFormCheckbox
parent
cf14e853
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
109 deletions
+84
-109
app/assets/javascripts/diffs/components/settings_dropdown.vue
...assets/javascripts/diffs/components/settings_dropdown.vue
+19
-21
spec/features/merge_request/user_toggles_whitespace_changes_spec.rb
...res/merge_request/user_toggles_whitespace_changes_spec.rb
+2
-2
spec/frontend/diffs/components/settings_dropdown_spec.js
spec/frontend/diffs/components/settings_dropdown_spec.js
+63
-86
No files found.
app/assets/javascripts/diffs/components/settings_dropdown.vue
View file @
1935282f
...
@@ -26,6 +26,9 @@ export default {
...
@@ -26,6 +26,9 @@ export default {
toggleFileByFile
()
{
toggleFileByFile
()
{
this
.
setFileByFile
({
fileByFile
:
!
this
.
viewDiffsFileByFile
});
this
.
setFileByFile
({
fileByFile
:
!
this
.
viewDiffsFileByFile
});
},
},
toggleWhitespace
(
updatedSetting
)
{
this
.
setShowWhitespace
({
showWhitespace
:
updatedSetting
,
pushState
:
true
});
},
},
},
};
};
</
script
>
</
script
>
...
@@ -80,26 +83,21 @@ export default {
...
@@ -80,26 +83,21 @@ export default {
</gl-button>
</gl-button>
</gl-button-group>
</gl-button-group>
</div>
</div>
<div
class=
"gl-mt-3 gl-px-3"
>
<gl-form-checkbox
<label
class=
"gl-mb-0"
>
data-testid=
"show-whitespace"
<input
class=
"gl-mt-3 gl-pl-3"
id=
"show-whitespace"
type=
"checkbox"
:checked=
"showWhitespace"
:checked=
"showWhitespace"
@
change=
"setShowWhitespace(
{ showWhitespace: $event.target.checked, pushState: true })
"
@
input=
"toggleWhitespace
"
/
>
>
{{
$options
.
i18n
.
whitespace
}}
{{
$options
.
i18n
.
whitespace
}}
</label>
</gl-form-checkbox>
</div>
<div
class=
"gl-mt-3 gl-px-3"
>
<gl-form-checkbox
<gl-form-checkbox
data-testid=
"file-by-file"
data-testid=
"file-by-file"
class=
"
gl-mb-0"
class=
"gl-pl-3
gl-mb-0"
:checked=
"viewDiffsFileByFile"
:checked=
"viewDiffsFileByFile"
@
input=
"toggleFileByFile"
@
input=
"toggleFileByFile"
>
>
{{
$options
.
i18n
.
fileByFile
}}
{{
$options
.
i18n
.
fileByFile
}}
</gl-form-checkbox>
</gl-form-checkbox>
</div>
</gl-dropdown>
</gl-dropdown>
</
template
>
</
template
>
spec/features/merge_request/user_toggles_whitespace_changes_spec.rb
View file @
1935282f
...
@@ -21,13 +21,13 @@ RSpec.describe 'Merge request > User toggles whitespace changes', :js do
...
@@ -21,13 +21,13 @@ RSpec.describe 'Merge request > User toggles whitespace changes', :js do
describe
'clicking "Hide whitespace changes" button'
do
describe
'clicking "Hide whitespace changes" button'
do
it
'toggles the "Hide whitespace changes" button'
do
it
'toggles the "Hide whitespace changes" button'
do
find
(
'
#show-whitespace
'
).
click
find
(
'
[data-testid="show-whitespace"]
'
).
click
visit
diffs_project_merge_request_path
(
project
,
merge_request
)
visit
diffs_project_merge_request_path
(
project
,
merge_request
)
find
(
'.js-show-diff-settings'
).
click
find
(
'.js-show-diff-settings'
).
click
expect
(
find
(
'
#show-whitespace
'
)).
not_to
be_checked
expect
(
find
(
'
[data-testid="show-whitespace"]
'
)).
not_to
be_checked
end
end
end
end
end
end
spec/frontend/diffs/components/settings_dropdown_spec.js
View file @
1935282f
import
{
mount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
{
mount
}
from
'
@vue/test-utils
'
;
import
Vue
from
'
vue
'
;
import
Vuex
from
'
vuex
'
;
import
Vuex
from
'
vuex
'
;
import
SettingsDropdown
from
'
~/diffs/components/settings_dropdown.vue
'
;
import
SettingsDropdown
from
'
~/diffs/components/settings_dropdown.vue
'
;
import
{
PARALLEL_DIFF_VIEW_TYPE
,
INLINE_DIFF_VIEW_TYPE
}
from
'
~/diffs/constants
'
;
import
{
PARALLEL_DIFF_VIEW_TYPE
,
INLINE_DIFF_VIEW_TYPE
}
from
'
~/diffs/constants
'
;
import
eventHub
from
'
~/diffs/event_hub
'
;
import
eventHub
from
'
~/diffs/event_hub
'
;
import
diffModule
from
'
~/diffs/store/modules
'
;
const
localVue
=
createLocalVue
();
import
{
extendedWrapper
}
from
'
../../__helpers__/vue_test_utils_helper
'
;
localVue
.
use
(
Vuex
);
import
createDiffsStore
from
'
../create_diffs_store
'
;
describe
(
'
Diff settings dropdown component
'
,
()
=>
{
describe
(
'
Diff settings dropdown component
'
,
()
=>
{
let
wrapper
;
let
wrapper
;
let
vm
;
let
vm
;
let
actions
;
let
store
;
Vue
.
use
(
Vuex
);
function
createComponent
(
extendStore
=
()
=>
{})
{
function
createComponent
(
extendStore
=
()
=>
{})
{
const
store
=
new
Vuex
.
Store
({
store
=
createDiffsStore
();
modules
:
{
diffs
:
{
namespaced
:
true
,
actions
,
state
:
diffModule
().
state
,
getters
:
diffModule
().
getters
,
},
},
});
extendStore
(
store
);
extendStore
(
store
);
wrapper
=
mount
(
SettingsDropdown
,
{
wrapper
=
extendedWrapper
(
localVue
,
mount
(
SettingsDropdown
,
{
store
,
store
,
});
}),
);
vm
=
wrapper
.
vm
;
vm
=
wrapper
.
vm
;
}
}
function
getFileByFileCheckbox
(
vueWrapper
)
{
function
getFileByFileCheckbox
(
vueWrapper
)
{
return
vueWrapper
.
find
(
'
[data-testid="file-by-file"]
'
);
return
vueWrapper
.
findByTestId
(
'
file-by-file
'
);
}
function
setup
({
storeUpdater
}
=
{})
{
createComponent
(
storeUpdater
);
jest
.
spyOn
(
store
,
'
dispatch
'
).
mockImplementation
(()
=>
{});
}
}
beforeEach
(()
=>
{
beforeEach
(()
=>
{
actions
=
{
setup
();
setInlineDiffViewType
:
jest
.
fn
(),
setParallelDiffViewType
:
jest
.
fn
(),
setRenderTreeList
:
jest
.
fn
(),
setShowWhitespace
:
jest
.
fn
(),
setFileByFile
:
jest
.
fn
(),
};
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
store
.
dispatch
.
mockRestore
();
wrapper
.
destroy
();
wrapper
.
destroy
();
});
});
describe
(
'
tree view buttons
'
,
()
=>
{
describe
(
'
tree view buttons
'
,
()
=>
{
it
(
'
list view button dispatches setRenderTreeList with false
'
,
()
=>
{
it
(
'
list view button dispatches setRenderTreeList with false
'
,
()
=>
{
createComponent
();
wrapper
.
find
(
'
.js-list-view
'
).
trigger
(
'
click
'
);
wrapper
.
find
(
'
.js-list-view
'
).
trigger
(
'
click
'
);
expect
(
actions
.
setRenderTreeList
).
toHaveBeenCalledWith
(
expect
.
anything
()
,
false
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
diffs/setRenderTreeList
'
,
false
);
});
});
it
(
'
tree view button dispatches setRenderTreeList with true
'
,
()
=>
{
it
(
'
tree view button dispatches setRenderTreeList with true
'
,
()
=>
{
createComponent
();
wrapper
.
find
(
'
.js-tree-view
'
).
trigger
(
'
click
'
);
wrapper
.
find
(
'
.js-tree-view
'
).
trigger
(
'
click
'
);
expect
(
actions
.
setRenderTreeList
).
toHaveBeenCalledWith
(
expect
.
anything
()
,
true
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
diffs/setRenderTreeList
'
,
true
);
});
});
it
(
'
sets list button as selected when renderTreeList is false
'
,
()
=>
{
it
(
'
sets list button as selected when renderTreeList is false
'
,
()
=>
{
createComponent
((
store
)
=>
{
setup
({
Object
.
assign
(
store
.
state
.
diffs
,
{
storeUpdater
:
(
origStore
)
=>
renderTreeList
:
false
,
Object
.
assign
(
origStore
.
state
.
diffs
,
{
renderTreeList
:
false
}),
});
});
});
expect
(
wrapper
.
find
(
'
.js-list-view
'
).
classes
(
'
selected
'
)).
toBe
(
true
);
expect
(
wrapper
.
find
(
'
.js-list-view
'
).
classes
(
'
selected
'
)).
toBe
(
true
);
...
@@ -81,10 +72,8 @@ describe('Diff settings dropdown component', () => {
...
@@ -81,10 +72,8 @@ describe('Diff settings dropdown component', () => {
});
});
it
(
'
sets tree button as selected when renderTreeList is true
'
,
()
=>
{
it
(
'
sets tree button as selected when renderTreeList is true
'
,
()
=>
{
createComponent
((
store
)
=>
{
setup
({
Object
.
assign
(
store
.
state
.
diffs
,
{
storeUpdater
:
(
origStore
)
=>
Object
.
assign
(
origStore
.
state
.
diffs
,
{
renderTreeList
:
true
}),
renderTreeList
:
true
,
});
});
});
expect
(
wrapper
.
find
(
'
.js-list-view
'
).
classes
(
'
selected
'
)).
toBe
(
false
);
expect
(
wrapper
.
find
(
'
.js-list-view
'
).
classes
(
'
selected
'
)).
toBe
(
false
);
...
@@ -94,10 +83,9 @@ describe('Diff settings dropdown component', () => {
...
@@ -94,10 +83,9 @@ describe('Diff settings dropdown component', () => {
describe
(
'
compare changes
'
,
()
=>
{
describe
(
'
compare changes
'
,
()
=>
{
it
(
'
sets inline button as selected
'
,
()
=>
{
it
(
'
sets inline button as selected
'
,
()
=>
{
createComponent
((
store
)
=>
{
setup
({
Object
.
assign
(
store
.
state
.
diffs
,
{
storeUpdater
:
(
origStore
)
=>
diffViewType
:
INLINE_DIFF_VIEW_TYPE
,
Object
.
assign
(
origStore
.
state
.
diffs
,
{
diffViewType
:
INLINE_DIFF_VIEW_TYPE
}),
});
});
});
expect
(
wrapper
.
find
(
'
.js-inline-diff-button
'
).
classes
(
'
selected
'
)).
toBe
(
true
);
expect
(
wrapper
.
find
(
'
.js-inline-diff-button
'
).
classes
(
'
selected
'
)).
toBe
(
true
);
...
@@ -105,10 +93,9 @@ describe('Diff settings dropdown component', () => {
...
@@ -105,10 +93,9 @@ describe('Diff settings dropdown component', () => {
});
});
it
(
'
sets parallel button as selected
'
,
()
=>
{
it
(
'
sets parallel button as selected
'
,
()
=>
{
createComponent
((
store
)
=>
{
setup
({
Object
.
assign
(
store
.
state
.
diffs
,
{
storeUpdater
:
(
origStore
)
=>
diffViewType
:
PARALLEL_DIFF_VIEW_TYPE
,
Object
.
assign
(
origStore
.
state
.
diffs
,
{
diffViewType
:
PARALLEL_DIFF_VIEW_TYPE
}),
});
});
});
expect
(
wrapper
.
find
(
'
.js-inline-diff-button
'
).
classes
(
'
selected
'
)).
toBe
(
false
);
expect
(
wrapper
.
find
(
'
.js-inline-diff-button
'
).
classes
(
'
selected
'
)).
toBe
(
false
);
...
@@ -116,53 +103,49 @@ describe('Diff settings dropdown component', () => {
...
@@ -116,53 +103,49 @@ describe('Diff settings dropdown component', () => {
});
});
it
(
'
calls setInlineDiffViewType when clicking inline button
'
,
()
=>
{
it
(
'
calls setInlineDiffViewType when clicking inline button
'
,
()
=>
{
createComponent
();
wrapper
.
find
(
'
.js-inline-diff-button
'
).
trigger
(
'
click
'
);
wrapper
.
find
(
'
.js-inline-diff-button
'
).
trigger
(
'
click
'
);
expect
(
actions
.
setInlineDiffViewType
).
toHaveBeenCalled
(
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
diffs/setInlineDiffViewType
'
,
expect
.
anything
()
);
});
});
it
(
'
calls setParallelDiffViewType when clicking parallel button
'
,
()
=>
{
it
(
'
calls setParallelDiffViewType when clicking parallel button
'
,
()
=>
{
createComponent
();
wrapper
.
find
(
'
.js-parallel-diff-button
'
).
trigger
(
'
click
'
);
wrapper
.
find
(
'
.js-parallel-diff-button
'
).
trigger
(
'
click
'
);
expect
(
actions
.
setParallelDiffViewType
).
toHaveBeenCalled
();
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
diffs/setParallelDiffViewType
'
,
expect
.
anything
(),
);
});
});
});
});
describe
(
'
whitespace toggle
'
,
()
=>
{
describe
(
'
whitespace toggle
'
,
()
=>
{
it
(
'
does not set as checked when showWhitespace is false
'
,
()
=>
{
it
(
'
does not set as checked when showWhitespace is false
'
,
()
=>
{
createComponent
((
store
)
=>
{
setup
({
Object
.
assign
(
store
.
state
.
diffs
,
{
storeUpdater
:
(
origStore
)
=>
showWhitespace
:
false
,
Object
.
assign
(
origStore
.
state
.
diffs
,
{
showWhitespace
:
false
}),
});
});
});
expect
(
wrapper
.
find
(
'
#
show-whitespace
'
).
element
.
checked
).
toBe
(
false
);
expect
(
wrapper
.
find
ByTestId
(
'
show-whitespace
'
).
element
.
checked
).
toBe
(
false
);
});
});
it
(
'
sets as checked when showWhitespace is true
'
,
()
=>
{
it
(
'
sets as checked when showWhitespace is true
'
,
()
=>
{
createComponent
((
store
)
=>
{
setup
({
Object
.
assign
(
store
.
state
.
diffs
,
{
storeUpdater
:
(
origStore
)
=>
Object
.
assign
(
origStore
.
state
.
diffs
,
{
showWhitespace
:
true
}),
showWhitespace
:
true
,
});
});
});
expect
(
wrapper
.
find
(
'
#
show-whitespace
'
).
element
.
checked
).
toBe
(
true
);
expect
(
wrapper
.
find
ByTestId
(
'
show-whitespace
'
).
element
.
checked
).
toBe
(
true
);
});
});
it
(
'
calls setShowWhitespace on change
'
,
()
=>
{
it
(
'
calls setShowWhitespace on change
'
,
async
()
=>
{
createComponent
();
const
checkbox
=
wrapper
.
findByTestId
(
'
show-whitespace
'
);
const
{
checked
}
=
checkbox
.
element
;
c
onst
checkbox
=
wrapper
.
find
(
'
#show-whitespace
'
);
c
heckbox
.
trigger
(
'
click
'
);
checkbox
.
element
.
checked
=
true
;
await
vm
.
$nextTick
();
checkbox
.
trigger
(
'
change
'
);
expect
(
actions
.
setShowWhitespace
).
toHaveBeenCalledWith
(
expect
.
anything
()
,
{
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
diffs/setShowWhitespace
'
,
{
showWhitespace
:
true
,
showWhitespace
:
!
checked
,
pushState
:
true
,
pushState
:
true
,
});
});
});
});
...
@@ -179,15 +162,12 @@ describe('Diff settings dropdown component', () => {
...
@@ -179,15 +162,12 @@ describe('Diff settings dropdown component', () => {
${
false
}
|
${
false
}
${
false
}
|
${
false
}
`
(
`
(
'
sets the checkbox to { checked: $checked } if the fileByFile setting is $fileByFile
'
,
'
sets the checkbox to { checked: $checked } if the fileByFile setting is $fileByFile
'
,
async
({
fileByFile
,
checked
})
=>
{
({
fileByFile
,
checked
})
=>
{
createComponent
((
store
)
=>
{
setup
({
Object
.
assign
(
store
.
state
.
diffs
,
{
storeUpdater
:
(
origStore
)
=>
viewDiffsFileByFile
:
fileByFile
,
Object
.
assign
(
origStore
.
state
.
diffs
,
{
viewDiffsFileByFile
:
fileByFile
}),
});
});
});
await
vm
.
$nextTick
();
expect
(
getFileByFileCheckbox
(
wrapper
).
element
.
checked
).
toBe
(
checked
);
expect
(
getFileByFileCheckbox
(
wrapper
).
element
.
checked
).
toBe
(
checked
);
},
},
);
);
...
@@ -199,19 +179,16 @@ describe('Diff settings dropdown component', () => {
...
@@ -199,19 +179,16 @@ describe('Diff settings dropdown component', () => {
`
(
`
(
'
when the file by file setting starts as $start, toggling the checkbox should call setFileByFile with $setting
'
,
'
when the file by file setting starts as $start, toggling the checkbox should call setFileByFile with $setting
'
,
async
({
start
,
setting
})
=>
{
async
({
start
,
setting
})
=>
{
createComponent
((
store
)
=>
{
setup
(
{
Object
.
assign
(
store
.
state
.
diffs
,
{
storeUpdater
:
(
origStore
)
=>
viewDiffsFileByFile
:
start
,
Object
.
assign
(
origStore
.
state
.
diffs
,
{
viewDiffsFileByFile
:
start
})
,
});
});
});
await
vm
.
$nextTick
();
getFileByFileCheckbox
(
wrapper
).
trigger
(
'
click
'
);
getFileByFileCheckbox
(
wrapper
).
trigger
(
'
click
'
);
await
vm
.
$nextTick
();
await
vm
.
$nextTick
();
expect
(
actions
.
setFileByFile
).
toHaveBeenLastCalledWith
(
expect
.
anything
()
,
{
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
diffs/setFileByFile
'
,
{
fileByFile
:
setting
,
fileByFile
:
setting
,
});
});
},
},
...
...
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