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
504c358f
Commit
504c358f
authored
Apr 06, 2020
by
Thomas Randolph
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change the Diffs app in response to the state `commit` changing
parent
eca8d9af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
0 deletions
+82
-0
app/assets/javascripts/diffs/components/app.vue
app/assets/javascripts/diffs/components/app.vue
+15
-0
spec/frontend/diffs/components/app_spec.js
spec/frontend/diffs/components/app_spec.js
+67
-0
No files found.
app/assets/javascripts/diffs/components/app.vue
View file @
504c358f
...
...
@@ -7,6 +7,7 @@ import createFlash from '~/flash';
import
PanelResizer
from
'
~/vue_shared/components/panel_resizer.vue
'
;
import
glFeatureFlagsMixin
from
'
~/vue_shared/mixins/gl_feature_flags_mixin
'
;
import
{
isSingleViewStyle
}
from
'
~/helpers/diffs_helper
'
;
import
{
updateHistory
}
from
'
~/lib/utils/url_utility
'
;
import
eventHub
from
'
../../notes/event_hub
'
;
import
CompareVersions
from
'
./compare_versions.vue
'
;
import
DiffFile
from
'
./diff_file.vue
'
;
...
...
@@ -140,6 +141,20 @@ export default {
},
},
watch
:
{
commit
(
newCommit
,
oldCommit
)
{
const
commitChangedAfterRender
=
newCommit
&&
!
this
.
isLoading
;
const
commitIsDifferent
=
oldCommit
&&
newCommit
.
id
!==
oldCommit
.
id
;
const
url
=
window
?.
location
?
String
(
window
.
location
)
:
''
;
if
(
commitChangedAfterRender
&&
commitIsDifferent
)
{
updateHistory
({
title
:
document
.
title
,
url
:
url
.
replace
(
oldCommit
.
id
,
newCommit
.
id
),
});
this
.
refetchDiffData
();
this
.
adjustView
();
}
},
diffViewType
()
{
if
(
this
.
needsReload
()
||
this
.
needsFirstLoad
())
{
this
.
refetchDiffData
();
...
...
spec/frontend/diffs/components/app_spec.js
View file @
504c358f
...
...
@@ -14,10 +14,13 @@ import TreeList from '~/diffs/components/tree_list.vue';
import
{
INLINE_DIFF_VIEW_TYPE
,
PARALLEL_DIFF_VIEW_TYPE
}
from
'
~/diffs/constants
'
;
import
createDiffsStore
from
'
../create_diffs_store
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
*
as
urlUtils
from
'
~/lib/utils/url_utility
'
;
import
diffsMockData
from
'
../mock_data/merge_request_diffs
'
;
const
mergeRequestDiff
=
{
version_index
:
1
};
const
TEST_ENDPOINT
=
`
${
TEST_HOST
}
/diff/endpoint`
;
const
COMMIT_URL
=
'
[BASE URL]/OLD
'
;
const
UPDATED_COMMIT_URL
=
'
[BASE URL]/NEW
'
;
describe
(
'
diffs/components/app
'
,
()
=>
{
const
oldMrTabs
=
window
.
mrTabs
;
...
...
@@ -602,6 +605,70 @@ describe('diffs/components/app', () => {
});
});
describe
(
'
commit watcher
'
,
()
=>
{
const
spy
=
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
,
'
refetchDiffData
'
).
mockImplementation
(()
=>
{});
jest
.
spyOn
(
wrapper
.
vm
,
'
adjustView
'
).
mockImplementation
(()
=>
{});
};
let
location
;
beforeAll
(()
=>
{
location
=
window
.
location
;
delete
window
.
location
;
window
.
location
=
COMMIT_URL
;
document
.
title
=
'
My Title
'
;
});
beforeEach
(()
=>
{
jest
.
spyOn
(
urlUtils
,
'
updateHistory
'
);
});
afterAll
(()
=>
{
window
.
location
=
location
;
});
it
(
'
when the commit changes and the app is not loading it should update the history, refetch the diff data, and update the view
'
,
()
=>
{
createComponent
({},
({
state
})
=>
{
state
.
diffs
.
commit
=
{
...
state
.
diffs
.
commit
,
id
:
'
OLD
'
};
});
spy
();
store
.
state
.
diffs
.
commit
=
{
id
:
'
NEW
'
};
return
wrapper
.
vm
.
$nextTick
().
then
(()
=>
{
expect
(
urlUtils
.
updateHistory
).
toHaveBeenCalledWith
({
title
:
document
.
title
,
url
:
UPDATED_COMMIT_URL
,
});
expect
(
wrapper
.
vm
.
refetchDiffData
).
toHaveBeenCalled
();
expect
(
wrapper
.
vm
.
adjustView
).
toHaveBeenCalled
();
});
});
it
.
each
`
isLoading | oldSha | newSha
${
true
}
|
${
'
OLD
'
}
|
${
'
NEW
'
}
${
false
}
|
${
'
NEW
'
}
|
${
'
NEW
'
}
`
(
'
given `{ "isLoading": $isLoading, "oldSha": "$oldSha", "newSha": "$newSha" }`, nothing should happen
'
,
({
isLoading
,
oldSha
,
newSha
})
=>
{
createComponent
({},
({
state
})
=>
{
state
.
diffs
.
isLoading
=
isLoading
;
state
.
diffs
.
commit
=
{
...
state
.
diffs
.
commit
,
id
:
oldSha
};
});
spy
();
store
.
state
.
diffs
.
commit
=
{
id
:
newSha
};
return
wrapper
.
vm
.
$nextTick
().
then
(()
=>
{
expect
(
urlUtils
.
updateHistory
).
not
.
toHaveBeenCalled
();
expect
(
wrapper
.
vm
.
refetchDiffData
).
not
.
toHaveBeenCalled
();
expect
(
wrapper
.
vm
.
adjustView
).
not
.
toHaveBeenCalled
();
});
},
);
});
describe
(
'
diffs
'
,
()
=>
{
it
(
'
should render compare versions component
'
,
()
=>
{
createComponent
({},
({
state
})
=>
{
...
...
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