summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClement Ho <ClemMakesApps@gmail.com>2017-06-06 18:18:31 -0500
committerClement Ho <ClemMakesApps@gmail.com>2017-06-06 18:18:31 -0500
commitd565b30ce60e0ad83f8a63b235eb923524665712 (patch)
treeeb541f60e1fd2f0780615cf10fc8652c29721240
parentf1dc6b57d78ff1af6758061873f2dd7e85feeff7 (diff)
downloadgitlab-ce-d565b30ce60e0ad83f8a63b235eb923524665712.tar.gz
Add jasmine spec for searchStateauto-search-when-state-changed
-rw-r--r--app/assets/javascripts/filtered_search/filtered_search_manager.js6
-rw-r--r--spec/javascripts/filtered_search/filtered_search_manager_spec.js43
2 files changed, 47 insertions, 2 deletions
diff --git a/app/assets/javascripts/filtered_search/filtered_search_manager.js b/app/assets/javascripts/filtered_search/filtered_search_manager.js
index 4f0bba81e26..215cc81f256 100644
--- a/app/assets/javascripts/filtered_search/filtered_search_manager.js
+++ b/app/assets/javascripts/filtered_search/filtered_search_manager.js
@@ -506,9 +506,11 @@ class FilteredSearchManager {
// return class name that has a prefix of `state-`
const stateClassName = [].find.call(target.classList, name => name.match(/(state-)(\w+)/g));
- const state = stateClassName.replace('state-', '');
- this.search(state);
+ if (stateClassName) {
+ const state = stateClassName.replace('state-', '');
+ this.search(state);
+ }
}
search(state = null) {
diff --git a/spec/javascripts/filtered_search/filtered_search_manager_spec.js b/spec/javascripts/filtered_search/filtered_search_manager_spec.js
index 6e59ee96c6b..406b25db083 100644
--- a/spec/javascripts/filtered_search/filtered_search_manager_spec.js
+++ b/spec/javascripts/filtered_search/filtered_search_manager_spec.js
@@ -97,6 +97,49 @@ describe('Filtered Search Manager', () => {
});
});
+ describe('searchState', () => {
+ beforeEach(() => {
+ spyOn(gl.FilteredSearchManager.prototype, 'search').and.callFake(() => {});
+ });
+
+ it('should blur button', () => {
+ const e = {
+ currentTarget: {
+ blur: () => {},
+ classList: [],
+ },
+ };
+ spyOn(e.currentTarget, 'blur').and.callThrough();
+ manager.searchState(e);
+
+ expect(e.currentTarget.blur).toHaveBeenCalled();
+ });
+
+ it('should not call search if there is no state', () => {
+ const e = {
+ currentTarget: {
+ blur: () => {},
+ classList: [],
+ },
+ };
+
+ manager.searchState(e);
+ expect(gl.FilteredSearchManager.prototype.search).not.toHaveBeenCalled();
+ });
+
+ it('should call search when there is state', () => {
+ const e = {
+ currentTarget: {
+ blur: () => {},
+ classList: ['class-name', 'state-opened'],
+ },
+ };
+
+ manager.searchState(e);
+ expect(gl.FilteredSearchManager.prototype.search).toHaveBeenCalledWith('opened');
+ });
+ });
+
describe('search', () => {
const defaultParams = '?scope=all&utf8=%E2%9C%93&state=opened';