2018-01-25 07:15:40 -06:00
|
|
|
import { VariableEditorCtrl } from '../editor_ctrl';
|
|
|
|
|
|
|
|
let mockEmit;
|
|
|
|
jest.mock('app/core/app_events', () => {
|
|
|
|
mockEmit = jest.fn();
|
|
|
|
return {
|
|
|
|
emit: mockEmit,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('VariableEditorCtrl', () => {
|
|
|
|
let scope = {
|
|
|
|
runQuery: () => {
|
|
|
|
return Promise.resolve({});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('When running a variable query and the data source returns an error', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const variableSrv = {
|
|
|
|
updateOptions: () => {
|
|
|
|
return Promise.reject({
|
|
|
|
data: { message: 'error' },
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-01-25 07:49:51 -06:00
|
|
|
return new VariableEditorCtrl(scope, {}, variableSrv, {});
|
2018-01-25 07:15:40 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should emit an error', () => {
|
|
|
|
return scope.runQuery().then(res => {
|
|
|
|
expect(mockEmit).toBeCalled();
|
|
|
|
expect(mockEmit.mock.calls[0][0]).toBe('alert-error');
|
|
|
|
expect(mockEmit.mock.calls[0][1][0]).toBe('Templating');
|
|
|
|
expect(mockEmit.mock.calls[0][1][1]).toBe('Template variables could not be initialized: error');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|