fractal-core
Version:
A minimalist and well crafted app, content or component is our conviction
93 lines • 3.95 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const ava_1 = require("ava");
const _1 = require(".");
const testUtils_1 = require("./testUtils");
// Propagation tests
ava_1.default('Propagation: Individual', (t) => __awaiter(this, void 0, void 0, function* () {
const app = yield testUtils_1.createApp({
state: {
_nest: {
Child: _1.clone(testUtils_1.ChildComp),
},
},
inputs: (s, F) => ({
$Child_changed: (r) => __awaiter(this, void 0, void 0, function* () { return yield F.set('result', r); }),
})
});
yield app.moduleAPI.toComp('Root$Child', 'inc');
t.deepEqual(app.rootCtx.components.Root.state.result, 1, 'Expect the input value');
}));
ava_1.default('Propagation: Groupal', (t) => __awaiter(this, void 0, void 0, function* () {
const app = yield testUtils_1.createApp({
state: {
_nest: {
A_1: _1.clone(testUtils_1.ChildComp),
A_2: _1.clone(testUtils_1.ChildComp),
A_3: _1.clone(testUtils_1.ChildComp),
},
},
inputs: (s, F) => ({
$A_changed: (r) => __awaiter(this, void 0, void 0, function* () { return yield F.set('result', r); }),
})
});
yield app.moduleAPI.toComp('Root$A_2', 'inc');
t.deepEqual(app.rootCtx.components.Root.state.result, ['2', 1], 'Expect the component scoped name and the value');
}));
ava_1.default('Propagation: Global', (t) => __awaiter(this, void 0, void 0, function* () {
const app = yield testUtils_1.createApp({
state: {
_nest: {
A_1: _1.clone(testUtils_1.ChildComp),
B: _1.clone(testUtils_1.ChildComp),
A_2: _1.clone(testUtils_1.ChildComp),
C: _1.clone(testUtils_1.ChildComp),
},
},
inputs: (s, F) => ({
$_changed: (r) => __awaiter(this, void 0, void 0, function* () { return yield F.set('result', r); }),
})
});
yield app.moduleAPI.toComp('Root$A_1', 'inc');
t.deepEqual(app.rootCtx.components.Root.state.result, ['A_1', 1], 'Expect the component name and the value');
}));
ava_1.default('Lifecycle Hooks', (t) => __awaiter(this, void 0, void 0, function* () {
const compSeq = [];
const moduleSeq = [];
const mod = yield testUtils_1.createApp({
state: { sequence: [] },
inputs: (s, F) => ({
onInit: () => __awaiter(this, void 0, void 0, function* () {
compSeq.push('onInit');
}),
onDestroy: () => __awaiter(this, void 0, void 0, function* () {
compSeq.push('onDestroy');
}),
}),
}, {
onBeforeInit: () => {
moduleSeq.push('onBeforeInit');
},
onInit: () => {
moduleSeq.push('onInit');
},
onBeforeDestroy: () => {
moduleSeq.push('onBeforeDestroy');
},
onDestroy: () => {
moduleSeq.push('onDestroy');
},
});
yield mod.moduleAPI.destroy();
t.deepEqual(compSeq, ['onInit', 'onDestroy'], 'Component Lifecycle');
t.deepEqual(moduleSeq, ['onBeforeInit', 'onInit', 'onBeforeDestroy', 'onDestroy'], 'Module Lifecycle');
}));
//# sourceMappingURL=module.spec.js.map