UNPKG

2.33 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var xstream_1 = require("xstream");
4var adapt_1 = require("@cycle/run/lib/adapt");
5var SCOPE_PREFIX = '___';
6var MockedDOMSource = /** @class */ (function () {
7 function MockedDOMSource(_mockConfig) {
8 this._mockConfig = _mockConfig;
9 if (_mockConfig.elements) {
10 this._elements = _mockConfig.elements;
11 }
12 else {
13 this._elements = adapt_1.adapt(xstream_1.default.empty());
14 }
15 }
16 MockedDOMSource.prototype.elements = function () {
17 var out = this
18 ._elements;
19 out._isCycleSource = 'MockedDOM';
20 return out;
21 };
22 MockedDOMSource.prototype.element = function () {
23 var output$ = this.elements()
24 .filter(function (arr) { return arr.length > 0; })
25 .map(function (arr) { return arr[0]; })
26 .remember();
27 var out = adapt_1.adapt(output$);
28 out._isCycleSource = 'MockedDOM';
29 return out;
30 };
31 MockedDOMSource.prototype.events = function (eventType, options, bubbles) {
32 var streamForEventType = this._mockConfig[eventType];
33 var out = adapt_1.adapt(streamForEventType || xstream_1.default.empty());
34 out._isCycleSource = 'MockedDOM';
35 return out;
36 };
37 MockedDOMSource.prototype.select = function (selector) {
38 var mockConfigForSelector = this._mockConfig[selector] || {};
39 return new MockedDOMSource(mockConfigForSelector);
40 };
41 MockedDOMSource.prototype.isolateSource = function (source, scope) {
42 return source.select('.' + SCOPE_PREFIX + scope);
43 };
44 MockedDOMSource.prototype.isolateSink = function (sink, scope) {
45 return adapt_1.adapt(xstream_1.default.fromObservable(sink).map(function (vnode) {
46 if (vnode.sel && vnode.sel.indexOf(SCOPE_PREFIX + scope) !== -1) {
47 return vnode;
48 }
49 else {
50 vnode.sel += "." + SCOPE_PREFIX + scope;
51 return vnode;
52 }
53 }));
54 };
55 return MockedDOMSource;
56}());
57exports.MockedDOMSource = MockedDOMSource;
58function mockDOMSource(mockConfig) {
59 return new MockedDOMSource(mockConfig);
60}
61exports.mockDOMSource = mockDOMSource;
62//# sourceMappingURL=mockDOMSource.js.map
\No newline at end of file