camunda-modeler
Version:
Camunda Modeler for BPMN, DMN and CMMN, based on bpmn.io
190 lines (157 loc) • 3.96 kB
JavaScript
'use strict';
var assign = require('lodash/object/assign');
var spyOn = require('test/helper/util/spy-on');
var BaseDialog = require('../../../lib/external/base-dialog');
/**
* A mock dialog implementation.
*/
function Dialog(events) {
BaseDialog.call(this, events);
this.openResponse = null;
this.closeResponse = null;
this.saveAsResponse = null;
this.savingDeniedResponse = null;
this.namespaceResponse = null;
this.reimportWarningResponse = null;
this.contentChangedResponse = null;
this.setResponse = function(type, fileOrError) {
this[type + 'Response'] = fileOrError;
};
this.contentChanged = function(done) {
done(this.contentChangedResponse);
};
this._doOpen = function(args, callback) {
var _args;
args.shift();
_args = args;
if (!(args[0] instanceof Error)) {
_args.unshift(null);
}
callback.apply(null, _args);
};
/**
* Ask for how to save the file and callback with (err, file).
*
* @param {File} file
* @param {Function} done
*/
this.saveAs = function(file, done) {
if (this.saveAsResponse instanceof Error) {
done(this.saveAsResponse);
} else {
// make sure we return with a proper
// file.path (as we expect from an actual implementation)
var response = null;
if (this.saveAsResponse) {
response = assign({}, file, this.saveAsResponse);
}
done(null, response);
}
};
/**
* Open save error dialog and callback with (err).
*
* @param {File} file
* @param {Function} done
*/
this.saveError = function(file, done) {
done(null);
};
/**
* Open saving denied error dialog and callback with (err).
*
* @param {File} file
* @param {Function} done
*/
this.savingDenied = function(done) {
if (this.savingDeniedResponse instanceof Error) {
done(this.savingDeniedResponse);
} else {
done(null, this.savingDeniedResponse);
}
};
/**
* Open an open dialog and callback with (err, file).
*
* @param {Function} done
*/
this.open = function(done) {
this._open('file:open', this.openResponse, done);
};
/**
* Display open error dialog and callback with (err).
*
* @param {Error} err
* @param {Function} done
*/
this.openError = function(err, done) {
done(null);
};
/**
* Open a 'close' dialog and callback with (err, file).
*
* @param {Function} done
*/
this.close = function(file, done) {
if (this.closeResponse instanceof Error) {
done(this.closeResponse);
} else {
done(null, this.closeResponse);
}
};
/**
* Open a 'name' dialog and callback with (err, answer).
*
* @param {Function} done
*/
this.convertNamespace = function(done) {
if (this.namespaceResponse instanceof Error) {
done(this.namespaceResponse);
} else {
done(null, this.namespaceResponse);
}
};
/**
* Open a 'name' dialog and callback with (err, answer).
*
* @param {Function} done
*/
this.reimportWarning = function(done) {
if (this.reimportWarningResponse instanceof Error) {
done(this.reimportWarningResponse);
} else {
done(null, this.reimportWarningResponse);
}
};
/**
* Open unrecognized file error dialog and invoke callback with (err).
*
* @param {Function} done
*/
this.unrecognizedFileError = function(file, done) {
done(null);
};
/**
* Displays an error that a diagram export has failed.
*
* @param {Error} err
* @param {Function} done
*/
this.exportError = function(err, done) {
done(null);
};
/**
* Displays an error that a diagram import has failed.
*
* @param {Error} err
* @param {Function} done
*/
this.importError = function(filename, trace, done) {
done(null);
};
this._clear = function() {
this._resetSpies();
};
this._resetSpies = spyOn(this);
}
module.exports = Dialog;