1
0
Fork 0

test(handleSelected): Add tests on selectionMethod

This commit is contained in:
Pixelastic 2018-11-22 11:33:12 +01:00 committed by Tim Carry
parent fa57746307
commit d42ec07cac

View file

@ -484,6 +484,59 @@ describe('DocSearch', () => {
resolve();
});
});
describe('default handleSelected', () => {
it('enterKey: should change the page', () => {
const options = {
apiKey: 'key',
indexName: 'foo',
inputSelector: '#input',
};
const mockSetVal = jest.fn();
const mockInput = { setVal: mockSetVal };
const mockSuggestion = { url: 'www.example.com' };
const mockContext = { selectionMethod: 'enterKey' };
new DocSearch(options).handleSelected(
mockInput,
undefined, // Event
mockSuggestion,
undefined, // Dataset
mockContext
);
return new Promise(resolve => {
expect(mockSetVal).toHaveBeenCalledWith('');
expect(window.location.assign).toHaveBeenCalledWith(
'www.example.com'
);
resolve();
});
});
it('click: should not change the page', () => {
const options = {
apiKey: 'key',
indexName: 'foo',
inputSelector: '#input',
};
const mockSetVal = jest.fn();
const mockInput = { setVal: mockSetVal };
const mockContext = { selectionMethod: 'click' };
new DocSearch(options).handleSelected(
mockInput,
undefined, // Event
undefined, // Suggestion
undefined, // Dataset
mockContext
);
return new Promise(resolve => {
expect(mockSetVal).not.toHaveBeenCalled();
expect(window.location.assign).not.toHaveBeenCalled();
resolve();
});
});
});
});
describe('handleShown', () => {