2017-05-25 20:09:29 +07:00
|
|
|
|
|
|
|
import sinon = require("sinon");
|
|
|
|
import jquery = require("jquery");
|
|
|
|
|
|
|
|
|
|
|
|
export interface JQueryMock extends sinon.SinonStub {
|
|
|
|
get: sinon.SinonStub;
|
|
|
|
post: sinon.SinonStub;
|
|
|
|
ajax: sinon.SinonStub;
|
|
|
|
notify: sinon.SinonStub;
|
|
|
|
}
|
|
|
|
|
2017-08-05 02:20:31 +07:00
|
|
|
export interface JQueryElementsMock {
|
|
|
|
ready: sinon.SinonStub;
|
|
|
|
show: sinon.SinonStub;
|
|
|
|
hide: sinon.SinonStub;
|
|
|
|
html: sinon.SinonStub;
|
|
|
|
addClass: sinon.SinonStub;
|
|
|
|
removeClass: sinon.SinonStub;
|
|
|
|
fadeIn: sinon.SinonStub;
|
2017-09-03 16:34:19 +07:00
|
|
|
fadeOut: sinon.SinonStub;
|
2017-08-05 02:20:31 +07:00
|
|
|
on: sinon.SinonStub;
|
|
|
|
}
|
|
|
|
|
2017-05-25 20:09:29 +07:00
|
|
|
export interface JQueryDeferredMock {
|
|
|
|
done: sinon.SinonStub;
|
|
|
|
fail: sinon.SinonStub;
|
|
|
|
}
|
|
|
|
|
2017-08-05 02:20:31 +07:00
|
|
|
export function JQueryMock(): { jquery: JQueryMock, element: JQueryElementsMock } {
|
2017-05-25 20:09:29 +07:00
|
|
|
const jquery = sinon.stub() as any;
|
2017-08-05 02:20:31 +07:00
|
|
|
const jqueryInstance: JQueryElementsMock = {
|
2017-05-25 20:09:29 +07:00
|
|
|
ready: sinon.stub(),
|
|
|
|
show: sinon.stub(),
|
|
|
|
hide: sinon.stub(),
|
2017-08-05 02:20:31 +07:00
|
|
|
html: sinon.stub(),
|
|
|
|
addClass: sinon.stub(),
|
|
|
|
removeClass: sinon.stub(),
|
|
|
|
fadeIn: sinon.stub(),
|
2017-09-03 16:34:19 +07:00
|
|
|
fadeOut: sinon.stub(),
|
2017-05-25 20:09:29 +07:00
|
|
|
on: sinon.stub()
|
|
|
|
};
|
|
|
|
jquery.ajax = sinon.stub();
|
|
|
|
jquery.get = sinon.stub();
|
|
|
|
jquery.post = sinon.stub();
|
|
|
|
jquery.notify = sinon.stub();
|
|
|
|
jquery.returns(jqueryInstance);
|
2017-08-05 02:20:31 +07:00
|
|
|
return {
|
|
|
|
jquery: jquery,
|
|
|
|
element: jqueryInstance
|
|
|
|
};
|
2017-05-25 20:09:29 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function JQueryDeferredMock(): JQueryDeferredMock {
|
|
|
|
return {
|
|
|
|
done: sinon.stub(),
|
|
|
|
fail: sinon.stub()
|
|
|
|
};
|
|
|
|
}
|