Commit d565b30c authored by Clement Ho's avatar Clement Ho

Add jasmine spec for searchState

parent f1dc6b57
...@@ -506,10 +506,12 @@ class FilteredSearchManager { ...@@ -506,10 +506,12 @@ class FilteredSearchManager {
// return class name that has a prefix of `state-` // return class name that has a prefix of `state-`
const stateClassName = [].find.call(target.classList, name => name.match(/(state-)(\w+)/g)); const stateClassName = [].find.call(target.classList, name => name.match(/(state-)(\w+)/g));
const state = stateClassName.replace('state-', '');
if (stateClassName) {
const state = stateClassName.replace('state-', '');
this.search(state); this.search(state);
} }
}
search(state = null) { search(state = null) {
const paths = []; const paths = [];
......
...@@ -97,6 +97,49 @@ describe('Filtered Search Manager', () => { ...@@ -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', () => { describe('search', () => {
const defaultParams = '?scope=all&utf8=%E2%9C%93&state=opened'; const defaultParams = '?scope=all&utf8=%E2%9C%93&state=opened';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment