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
Jérome Perrin
gitlab-ce
Commits
25186c7a
Commit
25186c7a
authored
Oct 03, 2017
by
Tim Zallmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Repo Sidebar Tests
parent
1429e5b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
37 deletions
+48
-37
app/assets/javascripts/repo/components/repo_sidebar.vue
app/assets/javascripts/repo/components/repo_sidebar.vue
+30
-29
spec/javascripts/repo/components/repo_sidebar_spec.js
spec/javascripts/repo/components/repo_sidebar_spec.js
+18
-8
No files found.
app/assets/javascripts/repo/components/repo_sidebar.vue
View file @
25186c7a
...
...
@@ -18,45 +18,46 @@ export default {
},
created
()
{
this
.
addPopEventListener
();
window
.
addEventListener
(
'
popstate
'
,
this
.
checkHistory
);
},
destroyed
()
{
window
.
removeEventListener
(
'
popstate
'
,
this
.
checkHistory
);
},
data
:
()
=>
Store
,
methods
:
{
addPopEventListener
()
{
window
.
addEventListener
(
'
popstate
'
,
()
=>
{
let
selectedFile
=
this
.
files
.
find
(
file
=>
location
.
pathname
.
indexOf
(
file
.
url
)
>
-
1
);
if
(
!
selectedFile
)
{
// Maybe it is not in the current tree but in the opened tabs
selectedFile
=
Store
.
openedFiles
.
find
(
file
=>
location
.
pathname
.
indexOf
(
file
.
url
)
>
-
1
);
checkHistory
()
{
let
selectedFile
=
this
.
files
.
find
(
file
=>
location
.
pathname
.
indexOf
(
file
.
url
)
>
-
1
);
if
(
!
selectedFile
)
{
// Maybe it is not in the current tree but in the opened tabs
selectedFile
=
Store
.
openedFiles
.
find
(
file
=>
location
.
pathname
.
indexOf
(
file
.
url
)
>
-
1
);
}
if
(
selectedFile
)
{
if
(
selectedFile
.
url
!==
this
.
activeFile
.
url
)
{
this
.
fileClicked
(
selectedFile
);
}
if
(
selectedFile
)
{
if
(
selectedFile
.
url
!==
this
.
activeFile
.
url
)
{
this
.
fileClicked
(
selectedFile
);
}
if
(
location
.
hash
.
indexOf
(
'
#L
'
)
>
-
1
)
{
const
lineNumber
=
Number
(
location
.
hash
.
substr
(
2
));
if
(
!
isNaN
(
lineNumber
))
{
Store
.
setActiveLine
(
lineNumber
);
if
(
Store
.
isPreviewView
())
{
document
.
getElementById
(
`L
${
lineNumber
}
`
).
scrollIntoView
();
}
else
{
Helper
.
monacoInstance
.
setPosition
({
lineNumber
:
this
.
activeLine
,
column
:
1
,
});
}
if
(
location
.
hash
.
indexOf
(
'
#L
'
)
>
-
1
)
{
const
lineNumber
=
Number
(
location
.
hash
.
substr
(
2
));
if
(
!
isNaN
(
lineNumber
))
{
Store
.
setActiveLine
(
lineNumber
);
if
(
Store
.
isPreviewView
())
{
document
.
getElementById
(
`L
${
lineNumber
}
`
).
scrollIntoView
();
}
else
{
Helper
.
monacoInstance
.
setPosition
({
lineNumber
:
this
.
activeLine
,
column
:
1
,
});
}
}
}
else
{
// Not opened at all lets open new tab
this
.
fileClicked
({
url
:
location
.
href
,
});
}
});
}
else
{
// Not opened at all lets open new tab
this
.
fileClicked
({
url
:
location
.
href
,
});
}
},
fileClicked
(
clickedFile
)
{
...
...
spec/javascripts/repo/components/repo_sidebar_spec.js
View file @
25186c7a
...
...
@@ -5,18 +5,26 @@ import RepoStore from '~/repo/stores/repo_store';
import
repoSidebar
from
'
~/repo/components/repo_sidebar.vue
'
;
describe
(
'
RepoSidebar
'
,
()
=>
{
let
vm
;
function
createComponent
()
{
const
RepoSidebar
=
Vue
.
extend
(
repoSidebar
);
return
new
RepoSidebar
().
$mount
();
}
afterEach
(()
=>
{
vm
.
$destroy
();
});
it
(
'
renders a sidebar
'
,
()
=>
{
RepoStore
.
files
=
[{
id
:
0
,
}];
RepoStore
.
openedFiles
=
[];
const
vm
=
createComponent
();
RepoStore
.
isRoot
=
false
;
vm
=
createComponent
();
const
thead
=
vm
.
$el
.
querySelector
(
'
thead
'
);
const
tbody
=
vm
.
$el
.
querySelector
(
'
tbody
'
);
...
...
@@ -35,7 +43,7 @@ describe('RepoSidebar', () => {
RepoStore
.
openedFiles
=
[{
id
:
0
,
}];
const
vm
=
createComponent
();
vm
=
createComponent
();
expect
(
vm
.
$el
.
classList
.
contains
(
'
sidebar-mini
'
)).
toBeTruthy
();
expect
(
vm
.
$el
.
querySelector
(
'
thead
'
)).
toBeFalsy
();
...
...
@@ -47,7 +55,7 @@ describe('RepoSidebar', () => {
tree
:
true
,
};
RepoStore
.
files
=
[];
const
vm
=
createComponent
();
vm
=
createComponent
();
expect
(
vm
.
$el
.
querySelectorAll
(
'
tbody .loading-file
'
).
length
).
toEqual
(
5
);
});
...
...
@@ -57,7 +65,7 @@ describe('RepoSidebar', () => {
id
:
0
,
}];
RepoStore
.
isRoot
=
true
;
const
vm
=
createComponent
();
vm
=
createComponent
();
expect
(
vm
.
$el
.
querySelector
(
'
tbody .prev-directory
'
)).
toBeTruthy
();
});
...
...
@@ -103,7 +111,7 @@ describe('RepoSidebar', () => {
};
RepoStore
.
files
=
[
file1
];
RepoStore
.
isRoot
=
true
;
const
vm
=
createComponent
();
vm
=
createComponent
();
vm
.
fileClicked
(
file1
);
...
...
@@ -114,7 +122,7 @@ describe('RepoSidebar', () => {
describe
(
'
goToPreviousDirectoryClicked
'
,
()
=>
{
it
(
'
should hide files in directory if already open
'
,
()
=>
{
const
prevUrl
=
'
foo/bar
'
;
const
vm
=
createComponent
();
vm
=
createComponent
();
vm
.
goToPreviousDirectoryClicked
(
prevUrl
);
...
...
@@ -135,13 +143,15 @@ describe('RepoSidebar', () => {
RepoStore
.
openedFiles
=
[
file1
,
file2
];
RepoStore
.
isRoot
=
true
;
const
vm
=
createComponent
();
vm
=
createComponent
();
vm
.
fileClicked
(
file1
);
it
(
'
render previous file when using back button
'
,
()
=>
{
spyOn
(
Helper
,
'
getContent
'
).
and
.
callThrough
();
vm
.
fileClicked
(
file2
);
expect
(
Helper
.
getContent
).
toHaveBeenCalledWith
(
file2
);
Helper
.
getContent
.
calls
.
reset
();
history
.
pushState
({
key
:
Math
.
random
(),
...
...
@@ -150,7 +160,7 @@ describe('RepoSidebar', () => {
popEvent
.
initEvent
(
'
popstate
'
,
true
,
true
);
window
.
dispatchEvent
(
popEvent
);
expect
(
Helper
.
getContent
).
toHaveBeenCalledWith
(
file1
);
expect
(
Helper
.
getContent
.
calls
.
mostRecent
().
args
[
0
].
url
).
toContain
(
file1
.
url
);
});
});
});
...
...
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