Files
bruno/packages/bruno-app/src/test-utils/mocks/codemirror.js
Sanjai Kumar 34614f039f Autocomplete random variables (#4695)
* Feature: adding dynamic variable support (#3609)


Co-authored-by: Raghav Sethi <109696225+rsxc@users.noreply.github.com>
Co-authored-by: sanjai0py <sanjailucifer666@gmail.com>
2025-06-18 20:06:45 +05:30

46 lines
1.1 KiB
JavaScript

const CodeMirror = jest.fn((node, options) => {
const editor = {
options,
_currentValue: '',
_onKeyUpMockDataHints: null,
getCursor: jest.fn(() => ({ line: 0, ch: editor._currentValue?.length || 0 })),
getRange: jest.fn((from, to) => editor._currentValue?.slice(0, to.ch) || ''),
getValue: jest.fn(() => editor._currentValue),
setValue: jest.fn(function (val) {
editor._currentValue = val;
}),
getLine: jest.fn(() => editor._currentValue || ''),
setOption: jest.fn(),
refresh: jest.fn(),
off: jest.fn(),
showHint: jest.fn(),
on: jest.fn(function (event, handler) {
if (event === 'keyup') {
if (handler && handler.name === '_onKeyUpMockDataHints') {
this._onKeyUpMockDataHints = handler;
}
}
})
};
return editor;
});
CodeMirror.commands = {
autocomplete: jest.fn()
};
CodeMirror.hint = {};
CodeMirror.registerHelper = jest.fn((type, name, value) => {
if (!CodeMirror[type]) {
CodeMirror[type] = {};
}
CodeMirror[type][name] = value;
});
CodeMirror.fromTextArea = jest.fn();
CodeMirror.defineMode = jest.fn();
module.exports = CodeMirror;