UNPKG

@tdb/util

Version:
69 lines 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var chai_1 = require("chai"); var rxjs_1 = require("rxjs"); var operators_1 = require("rxjs/operators"); var _1 = require("."); describe('mouse', function () { describe('events$', function () { it('fromProps', function () { var props = {}; var events = _1.mouse.fromProps(props); var unmounted$ = new rxjs_1.Subject(); events.events$.pipe(operators_1.takeUntil(unmounted$)); }); }); describe('handler', function () { it('single handler', function () { var res = _1.mouse.handle('CLICK', function (e) { return true; }); chai_1.expect(res).to.be.an.instanceof(Function); }); it('multiple handlers', function () { var res = _1.mouse.handle('CLICK', function (e) { return true; }, function (e) { return false; }); chai_1.expect(res).to.be.an.instanceof(Function); }); it('no handlers (undefined)', function () { var res = _1.mouse.handle('CLICK'); chai_1.expect(res).to.eql(undefined); }); }); describe('handlers', function () { it('generic handler (for all mouse events)', function () { var res = _1.mouse.handlers(function (e) { return true; }); chai_1.expect(res.isActive).to.eql(true); chai_1.expect(res.events$).to.be.an.instanceof(rxjs_1.Observable); chai_1.expect(res.events.onClick).to.be.an.instanceof(Function); chai_1.expect(res.events.onDoubleClick).to.be.an.instanceof(Function); chai_1.expect(res.events.onMouseDown).to.be.an.instanceof(Function); chai_1.expect(res.events.onMouseUp).to.be.an.instanceof(Function); chai_1.expect(res.events.onMouseEnter).to.be.an.instanceof(Function); chai_1.expect(res.events.onMouseLeave).to.be.an.instanceof(Function); }); it('no handlers', function () { var res = _1.mouse.handlers(); chai_1.expect(res.isActive).to.eql(false); chai_1.expect(res.events$).to.be.an.instanceof(rxjs_1.Observable); chai_1.expect(res.events.onClick).to.eql(undefined); chai_1.expect(res.events.onDoubleClick).to.eql(undefined); chai_1.expect(res.events.onMouseDown).to.eql(undefined); chai_1.expect(res.events.onMouseUp).to.eql(undefined); chai_1.expect(res.events.onMouseEnter).to.eql(undefined); chai_1.expect(res.events.onMouseLeave).to.eql(undefined); }); it('no generic handler, one specific handler (all handlers returned)', function () { var res = _1.mouse.handlers(undefined, { onMouseEnter: function (e) { return true; }, onMouseLeave: function (e) { return true; }, }); chai_1.expect(res.isActive).to.eql(true); chai_1.expect(res.events$).to.be.an.instanceof(rxjs_1.Observable); chai_1.expect(res.events.onClick).to.eql(undefined); chai_1.expect(res.events.onDoubleClick).to.eql(undefined); chai_1.expect(res.events.onMouseDown).to.eql(undefined); chai_1.expect(res.events.onMouseUp).to.eql(undefined); chai_1.expect(res.events.onMouseEnter).to.be.an.instanceof(Function); chai_1.expect(res.events.onMouseLeave).to.be.an.instanceof(Function); }); }); }); //# sourceMappingURL=mouse.test.js.map