editor_ctrl.test.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { VariableEditorCtrl } from '../editor_ctrl';
  2. let mockEmit;
  3. jest.mock('app/core/app_events', () => {
  4. mockEmit = jest.fn();
  5. return {
  6. emit: mockEmit,
  7. };
  8. });
  9. describe('VariableEditorCtrl', () => {
  10. const scope = {
  11. runQuery: () => {
  12. return Promise.resolve({});
  13. },
  14. };
  15. describe('When running a variable query and the data source returns an error', () => {
  16. beforeEach(() => {
  17. const variableSrv = {
  18. updateOptions: () => {
  19. return Promise.reject({
  20. data: { message: 'error' },
  21. });
  22. },
  23. };
  24. return new VariableEditorCtrl(scope, {}, variableSrv, {});
  25. });
  26. it('should emit an error', () => {
  27. return scope.runQuery().then(res => {
  28. expect(mockEmit).toBeCalled();
  29. expect(mockEmit.mock.calls[0][0]).toBe('alert-error');
  30. expect(mockEmit.mock.calls[0][1][0]).toBe('Templating');
  31. expect(mockEmit.mock.calls[0][1][1]).toBe('Template variables could not be initialized: error');
  32. });
  33. });
  34. });
  35. });