forked from PolymerLabs/arcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiplexer-test.ts
121 lines (92 loc) · 4.11 KB
/
multiplexer-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* @license
* Copyright (c) 2017 Google Inc. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* Code distributed by Google as part of this project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
import {assert} from '../../platform/chai-web.js';
import {Arc} from '../arc.js';
import {ArcId} from '../id.js';
import {Loader} from '../../platform/loader.js';
import {Manifest} from '../manifest.js';
import {checkDefined} from '../testing/preconditions.js';
import {FakeSlotComposer} from '../testing/fake-slot-composer.js';
import {collectionHandleForTest} from '../testing/handle-for-test.js';
import {Flags} from '../flags.js';
describe('Multiplexer', () => {
it('Processes multiple inputs', async () => {
const manifest = await Manifest.parse(`
import 'src/runtime/tests/artifacts/Common/Multiplexer.manifest'
import 'src/runtime/tests/artifacts/test-particles.manifest'
recipe
slot0: slot 'rootslotid-slotid'
handle0: use 'test:1'
Multiplexer
hostedParticle: ConsumerParticle
annotation: consumes slot0
list: reads handle0
`, {loader: new Loader(), fileName: ''});
const recipe = manifest.recipes[0];
const barType = checkDefined(manifest.findTypeByName('Bar'));
const slotComposer = new FakeSlotComposer({rootContainer: {'slotid': 'dummy-container'}});
const slotComposerCreateHostedSlot = slotComposer.createHostedSlot;
let slotsCreated = 0;
slotComposer.createHostedSlot = (...args) => {
slotsCreated++;
return slotComposerCreateHostedSlot.apply(slotComposer, args);
};
const arc = new Arc({id: ArcId.newForTest('test'), context: manifest, slotComposer, loader: new Loader()});
const barStore = await arc.createStore(barType.collectionOf(), null, 'test:1');
const barHandle = await collectionHandleForTest(arc, barStore);
recipe.handles[0].mapToStorage(barStore);
assert(recipe.normalize(), 'normalize');
assert(recipe.isResolved());
await arc.instantiate(recipe);
await arc.idle;
await barHandle.add(new barHandle.entityClass({value: 'one'}));
await barHandle.add(new barHandle.entityClass({value: 'two'}));
await barHandle.add(new barHandle.entityClass({value: 'three'}));
await arc.idle;
assert.strictEqual(slotsCreated, 3);
});
it('Processes multiple inputs', async () => {
const manifest = await Manifest.parse(`
import 'src/runtime/tests/artifacts/Common/Multiplexer.manifest'
import 'src/runtime/tests/artifacts/test-particles.manifest'
recipe
slot0: slot 'rootslotid-slotid'
handle0: use 'test:1'
Multiplexer
hostedParticle: ConsumerParticle
annotation: consumes slot0
list: reads handle0
`, {loader: new Loader(), fileName: ''});
const recipe = manifest.recipes[0];
const barType = checkDefined(manifest.findTypeByName('Bar'));
const slotComposer = new FakeSlotComposer({rootContainer: {'slotid': 'dummy-container'}});
const slotComposerCreateHostedSlot = slotComposer.createHostedSlot;
let slotsCreated = 0;
slotComposer.createHostedSlot = (...args) => {
slotsCreated++;
return slotComposerCreateHostedSlot.apply(slotComposer, args);
};
const arc = new Arc({id: ArcId.newForTest('test'), context: manifest, slotComposer, loader: new Loader()});
const barStore = await arc.createStore(barType.collectionOf(), null, 'test:1');
const barHandle = await collectionHandleForTest(arc, barStore);
recipe.handles[0].mapToStorage(barStore);
const options = {errors: new Map()};
const n = recipe.normalize(options);
assert(n, 'normalizes');
assert(recipe.isResolved());
await arc.instantiate(recipe);
await arc.idle;
await barHandle.add(new barHandle.entityClass({value: 'one'}));
await barHandle.add(new barHandle.entityClass({value: 'two'}));
await barHandle.add(new barHandle.entityClass({value: 'three'}));
await arc.idle;
assert.strictEqual(slotsCreated, 3);
});
});