UNPKG

wechaty-redux

Version:

Wechaty Redux Plugin Powered By Ducks

77 lines 4.14 kB
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const tstest_1 = require("tstest"); const wechaty_puppet_mock_1 = require("wechaty-puppet-mock"); const duck = __importStar(require("./duck/mod.js")); const mod_js_1 = require("./registry/mod.js"); const puppet__js_1 = require("./puppet$.js"); (0, tstest_1.test)('puppet$() & getPuppet()', async (t) => { const spy = tstest_1.sinon.spy(); const puppet = new wechaty_puppet_mock_1.PuppetMock(); const store = { dispatch: spy, }; t.notOk((0, mod_js_1.getPuppet)(puppet.id), 'should not have puppet in registry'); const $ = (0, puppet__js_1.puppet$)(puppet, { store }); const sub = $.subscribe(store.dispatch); t.ok(spy.calledOnce, 'should have one action after subscribe'); t.same(spy.args[0][0], duck.actions.REGISTER_PUPPET_COMMAND(puppet.id), 'should get puppet register action'); t.equal((0, mod_js_1.getPuppet)(puppet.id), puppet, 'should have puppet in registry'); spy.resetHistory(); sub.unsubscribe(); t.ok(spy.calledOnce, 'should have one action after unsubscribe'); t.same(spy.args[0][0], duck.actions.DEREGISTER_PUPPET_COMMAND(puppet.id), 'should get puppet deregister action'); t.notOk((0, mod_js_1.getPuppet)(puppet.id), 'should not have puppet in registry'); }); (0, tstest_1.test)('puppet$() start/stop actions', async (t) => { const spy = tstest_1.sinon.spy(); const puppet = new wechaty_puppet_mock_1.PuppetMock(); const store = { dispatch: spy, }; const $ = (0, puppet__js_1.puppet$)(puppet, { store }); const sub = $.subscribe(store.dispatch); t.ok(spy.calledOnce, 'should have one action after subscribe'); t.same(spy.args[0][0], duck.actions.REGISTER_PUPPET_COMMAND(puppet.id), 'should emit register puppet action'); spy.resetHistory(); await puppet.start(); t.ok(spy.calledThrice, 'should have three action after start'); t.same(spy.args[0][0], duck.actions.STATE_ACTIVATED_EVENT(puppet.id, 'pending'), 'should emit `pending` active state action'); t.same(spy.args[1][0], duck.actions.STATE_ACTIVATED_EVENT(puppet.id, true), 'should emit `true` active state action'); t.same(spy.args[2][0], duck.actions.STARTED_EVENT(puppet.id), 'should emit start event action'); spy.resetHistory(); await puppet.stop(); t.ok(spy.calledThrice, 'should have three action after stop'); t.same(spy.args[0][0], duck.actions.STATE_INACTIVATED_EVENT(puppet.id, 'pending'), 'should emit `pending` inactive state action'); t.same(spy.args[1][0], duck.actions.STATE_INACTIVATED_EVENT(puppet.id, true), 'should emit `true` inactive state action'); t.same(spy.args[2][0], duck.actions.STOPPED_EVENT(puppet.id), 'should emit stop event action'); spy.resetHistory(); sub.unsubscribe(); t.ok(spy.calledOnce, 'should have one action after unsubscribe'); t.same(spy.args[0][0], duck.actions.DEREGISTER_PUPPET_COMMAND(puppet.id), 'should get puppet deregister action'); }); //# sourceMappingURL=puppet$.spec.js.map