提交 d565b30c 编写于 作者: C Clement Ho

Add jasmine spec for searchState

上级 f1dc6b57
......@@ -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) {
......
......@@ -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';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册