UNPKG

@rxx/worker

Version:

React MVI micro framework.

104 lines (103 loc) 3.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var rxjs_1 = require("rxjs"); var power_assert_1 = tslib_1.__importDefault(require("power-assert")); var assert_1 = tslib_1.__importDefault(require("assert")); var provisioning_1 = require("../provisioning"); var state_handler_1 = require("../handler/state-handler"); var store_1 = require("../store/store"); var intent_1 = require("../intent/intent"); var operators_1 = require("rxjs/operators"); var factory_1 = require("../factory"); var TestStore = (function () { function TestStore() { } TestStore.prototype.initialize = function () { return { view: { test: 1, }, }; }; TestStore = tslib_1.__decorate([ store_1.store ], TestStore); return TestStore; }()); var TestIntent = (function () { function TestIntent() { } TestIntent.prototype.getIntent = function () { return this.intent; }; TestIntent.prototype.getHandler = function () { return this.testHandler; }; TestIntent = tslib_1.__decorate([ intent_1.intent ], TestIntent); return TestIntent; }()); var TestHandler = (function (_super) { tslib_1.__extends(TestHandler, _super); function TestHandler() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.subscribed = false; return _this; } TestHandler.prototype.subscribe = function (a) { this.subscribed = true; return new rxjs_1.Subscription(); }; TestHandler.prototype.isSubscribed = function () { return this.subscribed; }; TestHandler.prototype.push = function (k, a) { return new Promise(function (r) { }); }; TestHandler.prototype.clone = function () { return new TestHandler(); }; return TestHandler; }(state_handler_1.StateHandler)); describe('Provisioning', function () { var testHandler = new TestHandler(); beforeAll(function () { state_handler_1.registerHandlers({ testHandler: testHandler, }); }); describe('#prepare', function () { it('should connect store and intent and handler', function () { var p = new provisioning_1.Provisioning({ intent: TestIntent }, [TestStore], undefined, {}); p.prepare(); assert_1.default.deepStrictEqual(p.getState(), { view: { test: 1 }, }); power_assert_1.default.ok(p.getHandlers().testHandler.isSubscribed()); }); it('should accept intent map', function () { var p = new provisioning_1.Provisioning({ test: TestIntent }, [TestStore], undefined, {}); p.prepare(); assert_1.default.deepStrictEqual(p.getState(), { view: { test: 1 }, }); power_assert_1.default.ok(p.getHandlers().testHandler.isSubscribed()); }); it('should accept state factories', function () { var p = new provisioning_1.Provisioning({}, [], factory_1.makeApp({ test: function (observable, state) { return { view: observable.pipe(operators_1.startWith(state)), }; }, }, { test: 1 }), {}); p.prepare(); assert_1.default.deepStrictEqual(p.getState(), { view: { test: 1 }, }); power_assert_1.default.ok(p.getHandlers().testHandler.isSubscribed()); }); }); });