未验证 提交 a2f3acfe 编写于 作者: S sercan

#480 connection tests

上级 eef18bad
......@@ -4,11 +4,13 @@ import sinon from 'sinon';
import { expect } from 'chai';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Connection } from '/client/imports/ui';
import { SessionManager } from '/client/imports/modules';
import { Communicator } from '/client/imports/facades';
import { ErrorHandler, SessionManager, Notification } from '/client/imports/modules';
import { Communicator, ReactivityProvider } from '/client/imports/facades';
import $ from 'jquery';
import Helper from '/client/imports/helpers/helper';
require('/client/plugins/colorpicker/js/bootstrap-colorpicker.min');
describe('Connection', () => {
describe('prepareModal tests', () => {
const translated = 'TESTTRANSLATED';
......@@ -97,4 +99,134 @@ describe('Connection', () => {
expect(FlowRouter.go.calledWithExactly('/databaseStats')).to.equals(true);
});
});
describe('prepareContextMenu tests', () => {
const connectionId = '12321312';
const connection = { x: 1, y: true, z: 'sercan' };
beforeEach(() => {
sinon.stub($, 'contextMenu');
sinon.stub($.prototype, 'data');
sinon.stub($.prototype, 'modal');
sinon.stub($.prototype, 'DataTable').returns({ row: sinon.stub().returns({ data: sinon.stub().returns({ _id: connectionId }) }) });
sinon.stub(ReactivityProvider, 'findOne').returns(connection);
sinon.stub(ErrorHandler, 'showMeteorFuncError');
sinon.stub(Notification, 'success');
sinon.stub(Connection, 'populateConnectionsTable');
});
afterEach(() => {
$.contextMenu.restore();
$.prototype.data.restore();
$.prototype.modal.restore();
$.prototype.DataTable.restore();
ReactivityProvider.findOne.restore();
ErrorHandler.showMeteorFuncError.restore();
Notification.success.restore();
Connection.populateConnectionsTable.restore();
});
it('prepareContextMenu colorize callback', () => {
// prepare
// execute
Connection.prepareContextMenu();
$.contextMenu.getCall(0).args[0].items.colorize.callback(null, { $trigger: ['something'] });
// verify
expect($.contextMenu.callCount).to.equal(1);
expect($.contextMenu.getCall(0).args[0].items).to.have.property('colorize');
expect($.contextMenu.getCall(0).args[0].items).to.have.property('clear_color');
expect($.prototype.data.callCount).to.equal(1);
expect($.prototype.data.calledWithExactly('connection', connectionId)).to.equal(true);
expect($.prototype.modal.callCount).to.equal(1);
expect($.prototype.modal.calledWithExactly('show')).to.equal(true);
});
it('prepareContextMenu clear_color callback && communicator yields to error', () => {
// prepare
const error = { error: '123' };
sinon.stub(Communicator, 'call').yieldsTo('callback', error, null);
// execute
Connection.prepareContextMenu();
$.contextMenu.getCall(0).args[0].items.clear_color.callback(null, { $trigger: ['something'] });
// verify
expect($.contextMenu.callCount).to.equal(1);
expect($.contextMenu.getCall(0).args[0].items).to.have.property('colorize');
expect($.contextMenu.getCall(0).args[0].items).to.have.property('clear_color');
expect(Communicator.call.callCount).to.equal(1);
expect(Communicator.call.calledWithMatch({
methodName: 'saveConnection',
args: { connection: Object.assign({ color: '' }, connection) },
callback: sinon.match.func
})).to.equal(true);
expect(ErrorHandler.showMeteorFuncError.callCount).to.equal(1);
expect(ErrorHandler.showMeteorFuncError.calledWithExactly(error, null)).to.equal(true);
// cleanup
Communicator.call.restore();
});
it('prepareContextMenu clear_color callback && communicator yields to success', () => {
// prepare
sinon.stub(Communicator, 'call').yieldsTo('callback');
// execute
Connection.prepareContextMenu();
$.contextMenu.getCall(0).args[0].items.clear_color.callback(null, { $trigger: ['something'] });
// verify
expect($.contextMenu.callCount).to.equal(1);
expect($.contextMenu.getCall(0).args[0].items).to.have.property('colorize');
expect($.contextMenu.getCall(0).args[0].items).to.have.property('clear_color');
expect(Communicator.call.callCount).to.equal(1);
expect(Communicator.call.calledWithMatch({
methodName: 'saveConnection',
args: { connection: Object.assign({ color: '' }, connection) },
callback: sinon.match.func
})).to.equal(true);
expect(ErrorHandler.showMeteorFuncError.callCount).to.equal(0);
expect(Notification.success.callCount).to.equal(1);
expect(Notification.success.calledWithExactly('saved-successfully')).to.equal(true);
expect(Connection.populateConnectionsTable.callCount).to.equal(1);
expect(Connection.populateConnectionsTable.calledWithExactly()).to.equal(true);
// cleanup
Communicator.call.restore();
});
});
describe('prepareColorizeModal tests', () => {
const color = '#111111';
beforeEach(() => {
const connectionId = '1231235612';
sinon.stub($.prototype, 'colorpicker');
sinon.stub($.prototype, 'on').yields(null);
sinon.stub($.prototype, 'data').withArgs('connection').returns(connectionId);
sinon.stub(ReactivityProvider, 'findOne').withArgs(ReactivityProvider.types.Connections, { _id: connectionId }).returns({ color });
});
afterEach(() => {
$.prototype.colorpicker.restore();
$.prototype.on.restore();
$.prototype.data.restore();
ReactivityProvider.findOne.restore();
});
it('prepareColorizeModal', () => {
// prepare
// execute
Connection.prepareColorizeModal();
// verify
expect($.prototype.colorpicker.callCount).to.equals(2);
expect($.prototype.colorpicker.calledWithMatch({ align: 'left', format: 'hex' })).to.equals(true);
expect($.prototype.colorpicker.calledWithMatch('setValue', color)).to.equals(true);
expect($.prototype.on.callCount).to.equals(1);
expect($.prototype.on.calledWithMatch('shown.bs.modal', sinon.match.func)).to.equals(true);
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册