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
Tatuya Kamada
gitlab-ce
Commits
72e0ed0a
Commit
72e0ed0a
authored
Jan 07, 2017
by
Sam Rose
Committed by
samrose3
Jan 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only search commits on input change since last search
parent
b60de9c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
1 deletion
+57
-1
app/assets/javascripts/commits.js
app/assets/javascripts/commits.js
+7
-1
spec/javascripts/commits_spec.js.es6
spec/javascripts/commits_spec.js.es6
+50
-0
No files found.
app/assets/javascripts/commits.js
View file @
72e0ed0a
...
...
@@ -3,7 +3,7 @@
(
function
()
{
this
.
CommitsList
=
(
function
()
{
function
CommitsList
()
{}
var
CommitsList
=
{};
CommitsList
.
timer
=
null
;
...
...
@@ -20,6 +20,7 @@
});
this
.
content
=
$
(
"
#commits-list
"
);
this
.
searchField
=
$
(
"
#commits-search
"
);
this
.
lastSearch
=
this
.
searchField
.
val
();
return
this
.
initSearch
();
};
...
...
@@ -37,6 +38,7 @@
var
commitsUrl
,
form
,
search
;
form
=
$
(
"
.commits-search-form
"
);
search
=
CommitsList
.
searchField
.
val
();
if
(
search
===
CommitsList
.
lastSearch
)
return
;
commitsUrl
=
form
.
attr
(
"
action
"
)
+
'
?
'
+
form
.
serialize
();
CommitsList
.
content
.
fadeTo
(
'
fast
'
,
0.5
);
return
$
.
ajax
({
...
...
@@ -47,12 +49,16 @@
return
CommitsList
.
content
.
fadeTo
(
'
fast
'
,
1.0
);
},
success
:
function
(
data
)
{
CommitsList
.
lastSearch
=
search
;
CommitsList
.
content
.
html
(
data
.
html
);
return
history
.
replaceState
({
page
:
commitsUrl
// Change url so if user reload a page - search results are saved
},
document
.
title
,
commitsUrl
);
},
error
:
function
()
{
CommitsList
.
lastSearch
=
null
;
},
dataType
:
"
json
"
});
};
...
...
spec/javascripts/commits_spec.js.es6
0 → 100644
View file @
72e0ed0a
/* global CommitsList */
//= require jquery.endless-scroll
//= require pager
//= require commits
(() => {
describe('Commits List', () => {
beforeEach(() => {
setFixtures(`
<form class="commits-search-form" action="/h5bp/html5-boilerplate/commits/master">
<input id="commits-search">
</form>
<ol id="commits-list"></ol>
`);
});
it('should be defined', () => {
expect(CommitsList).toBeDefined();
});
describe('on entering input', () => {
let ajaxSpy;
beforeEach(() => {
CommitsList.init(25);
CommitsList.searchField.val('');
spyOn(history, 'replaceState').and.stub();
ajaxSpy = spyOn(jQuery, 'ajax').and.callFake((req) => {
req.success({
data: '<li>Result</li>',
});
});
});
it('should save the last search string', () => {
CommitsList.searchField.val('GitLab');
CommitsList.filterResults();
expect(ajaxSpy).toHaveBeenCalled();
expect(CommitsList.lastSearch).toEqual('GitLab');
});
it('should not make ajax call if the input does not change', () => {
CommitsList.filterResults();
expect(ajaxSpy).not.toHaveBeenCalled();
expect(CommitsList.lastSearch).toEqual('');
});
});
});
})();
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