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
Boxiang Sun
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
Show 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,14 +18,16 @@ export default {
...
@@ -18,14 +18,16 @@ export default {
},
},
created
()
{
created
()
{
this
.
addPopEventListener
();
window
.
addEventListener
(
'
popstate
'
,
this
.
checkHistory
);
},
destroyed
()
{
window
.
removeEventListener
(
'
popstate
'
,
this
.
checkHistory
);
},
},
data
:
()
=>
Store
,
data
:
()
=>
Store
,
methods
:
{
methods
:
{
addPopEventListener
()
{
checkHistory
()
{
window
.
addEventListener
(
'
popstate
'
,
()
=>
{
let
selectedFile
=
this
.
files
.
find
(
file
=>
location
.
pathname
.
indexOf
(
file
.
url
)
>
-
1
);
let
selectedFile
=
this
.
files
.
find
(
file
=>
location
.
pathname
.
indexOf
(
file
.
url
)
>
-
1
);
if
(
!
selectedFile
)
{
if
(
!
selectedFile
)
{
// Maybe it is not in the current tree but in the opened tabs
// Maybe it is not in the current tree but in the opened tabs
...
@@ -56,7 +58,6 @@ export default {
...
@@ -56,7 +58,6 @@ export default {
url
:
location
.
href
,
url
:
location
.
href
,
});
});
}
}
});
},
},
fileClicked
(
clickedFile
)
{
fileClicked
(
clickedFile
)
{
...
...
spec/javascripts/repo/components/repo_sidebar_spec.js
View file @
25186c7a
...
@@ -5,18 +5,26 @@ import RepoStore from '~/repo/stores/repo_store';
...
@@ -5,18 +5,26 @@ import RepoStore from '~/repo/stores/repo_store';
import
repoSidebar
from
'
~/repo/components/repo_sidebar.vue
'
;
import
repoSidebar
from
'
~/repo/components/repo_sidebar.vue
'
;
describe
(
'
RepoSidebar
'
,
()
=>
{
describe
(
'
RepoSidebar
'
,
()
=>
{
let
vm
;
function
createComponent
()
{
function
createComponent
()
{
const
RepoSidebar
=
Vue
.
extend
(
repoSidebar
);
const
RepoSidebar
=
Vue
.
extend
(
repoSidebar
);
return
new
RepoSidebar
().
$mount
();
return
new
RepoSidebar
().
$mount
();
}
}
afterEach
(()
=>
{
vm
.
$destroy
();
});
it
(
'
renders a sidebar
'
,
()
=>
{
it
(
'
renders a sidebar
'
,
()
=>
{
RepoStore
.
files
=
[{
RepoStore
.
files
=
[{
id
:
0
,
id
:
0
,
}];
}];
RepoStore
.
openedFiles
=
[];
RepoStore
.
openedFiles
=
[];
const
vm
=
createComponent
();
RepoStore
.
isRoot
=
false
;
vm
=
createComponent
();
const
thead
=
vm
.
$el
.
querySelector
(
'
thead
'
);
const
thead
=
vm
.
$el
.
querySelector
(
'
thead
'
);
const
tbody
=
vm
.
$el
.
querySelector
(
'
tbody
'
);
const
tbody
=
vm
.
$el
.
querySelector
(
'
tbody
'
);
...
@@ -35,7 +43,7 @@ describe('RepoSidebar', () => {
...
@@ -35,7 +43,7 @@ describe('RepoSidebar', () => {
RepoStore
.
openedFiles
=
[{
RepoStore
.
openedFiles
=
[{
id
:
0
,
id
:
0
,
}];
}];
const
vm
=
createComponent
();
vm
=
createComponent
();
expect
(
vm
.
$el
.
classList
.
contains
(
'
sidebar-mini
'
)).
toBeTruthy
();
expect
(
vm
.
$el
.
classList
.
contains
(
'
sidebar-mini
'
)).
toBeTruthy
();
expect
(
vm
.
$el
.
querySelector
(
'
thead
'
)).
toBeFalsy
();
expect
(
vm
.
$el
.
querySelector
(
'
thead
'
)).
toBeFalsy
();
...
@@ -47,7 +55,7 @@ describe('RepoSidebar', () => {
...
@@ -47,7 +55,7 @@ describe('RepoSidebar', () => {
tree
:
true
,
tree
:
true
,
};
};
RepoStore
.
files
=
[];
RepoStore
.
files
=
[];
const
vm
=
createComponent
();
vm
=
createComponent
();
expect
(
vm
.
$el
.
querySelectorAll
(
'
tbody .loading-file
'
).
length
).
toEqual
(
5
);
expect
(
vm
.
$el
.
querySelectorAll
(
'
tbody .loading-file
'
).
length
).
toEqual
(
5
);
});
});
...
@@ -57,7 +65,7 @@ describe('RepoSidebar', () => {
...
@@ -57,7 +65,7 @@ describe('RepoSidebar', () => {
id
:
0
,
id
:
0
,
}];
}];
RepoStore
.
isRoot
=
true
;
RepoStore
.
isRoot
=
true
;
const
vm
=
createComponent
();
vm
=
createComponent
();
expect
(
vm
.
$el
.
querySelector
(
'
tbody .prev-directory
'
)).
toBeTruthy
();
expect
(
vm
.
$el
.
querySelector
(
'
tbody .prev-directory
'
)).
toBeTruthy
();
});
});
...
@@ -103,7 +111,7 @@ describe('RepoSidebar', () => {
...
@@ -103,7 +111,7 @@ describe('RepoSidebar', () => {
};
};
RepoStore
.
files
=
[
file1
];
RepoStore
.
files
=
[
file1
];
RepoStore
.
isRoot
=
true
;
RepoStore
.
isRoot
=
true
;
const
vm
=
createComponent
();
vm
=
createComponent
();
vm
.
fileClicked
(
file1
);
vm
.
fileClicked
(
file1
);
...
@@ -114,7 +122,7 @@ describe('RepoSidebar', () => {
...
@@ -114,7 +122,7 @@ describe('RepoSidebar', () => {
describe
(
'
goToPreviousDirectoryClicked
'
,
()
=>
{
describe
(
'
goToPreviousDirectoryClicked
'
,
()
=>
{
it
(
'
should hide files in directory if already open
'
,
()
=>
{
it
(
'
should hide files in directory if already open
'
,
()
=>
{
const
prevUrl
=
'
foo/bar
'
;
const
prevUrl
=
'
foo/bar
'
;
const
vm
=
createComponent
();
vm
=
createComponent
();
vm
.
goToPreviousDirectoryClicked
(
prevUrl
);
vm
.
goToPreviousDirectoryClicked
(
prevUrl
);
...
@@ -135,13 +143,15 @@ describe('RepoSidebar', () => {
...
@@ -135,13 +143,15 @@ describe('RepoSidebar', () => {
RepoStore
.
openedFiles
=
[
file1
,
file2
];
RepoStore
.
openedFiles
=
[
file1
,
file2
];
RepoStore
.
isRoot
=
true
;
RepoStore
.
isRoot
=
true
;
const
vm
=
createComponent
();
vm
=
createComponent
();
vm
.
fileClicked
(
file1
);
vm
.
fileClicked
(
file1
);
it
(
'
render previous file when using back button
'
,
()
=>
{
it
(
'
render previous file when using back button
'
,
()
=>
{
spyOn
(
Helper
,
'
getContent
'
).
and
.
callThrough
();
spyOn
(
Helper
,
'
getContent
'
).
and
.
callThrough
();
vm
.
fileClicked
(
file2
);
vm
.
fileClicked
(
file2
);
expect
(
Helper
.
getContent
).
toHaveBeenCalledWith
(
file2
);
expect
(
Helper
.
getContent
).
toHaveBeenCalledWith
(
file2
);
Helper
.
getContent
.
calls
.
reset
();
history
.
pushState
({
history
.
pushState
({
key
:
Math
.
random
(),
key
:
Math
.
random
(),
...
@@ -150,7 +160,7 @@ describe('RepoSidebar', () => {
...
@@ -150,7 +160,7 @@ describe('RepoSidebar', () => {
popEvent
.
initEvent
(
'
popstate
'
,
true
,
true
);
popEvent
.
initEvent
(
'
popstate
'
,
true
,
true
);
window
.
dispatchEvent
(
popEvent
);
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