-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathsetup-component.js
More file actions
111 lines (87 loc) · 2.58 KB
/
setup-component.js
File metadata and controls
111 lines (87 loc) · 2.58 KB
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
'use strict';
const SimpleDOM = require('simple-dom');
const buildOwner = require('./build-owner');
const { loadEmber, clearEmber } = require('./load-ember');
module.exports = function (hooks) {
hooks.beforeEach(function () {
let { Ember, compile } = loadEmber();
this.compile = compile;
this.Ember = Ember;
Ember.testing = true;
this.run = Ember.run;
setupComponentTest.call(this);
});
hooks.afterEach(function () {
let module = this;
if (this.component) {
this.run(function () {
module.component.destroy();
});
this.component = null;
}
this.run(this.owner, 'destroy');
this.owner = null;
this.Ember = null;
clearEmber();
});
};
function setupComponentTest() {
let module = this;
module.element = new SimpleDOM.Document();
module.owner = buildOwner(this.Ember, { resolve: function () {} });
module.owner.register('service:-document', new SimpleDOM.Document(), {
instantiate: false,
});
this._hasRendered = false;
let OutletView = module.owner.factoryFor('view:-outlet');
let outletTemplateFactory = module.owner.lookup('template:-outlet');
let environment = module.owner.lookup('-environment:main');
module.component = OutletView.create({ environment, template: outletTemplateFactory });
this._outletState = {
render: {
owner: module.owner || undefined,
name: 'application',
controller: module,
model: undefined,
template: outletTemplateFactory(module.owner),
},
outlets: {},
};
this.run(function () {
module.component.setOutletState(module._outletState);
});
module.render = render;
module.serializeElement = serializeElement;
module.set = function (property, value) {
module.run(function () {
module.Ember.set(module, property, value);
});
};
}
function render(_template) {
let module = this;
let templateFactory = this.compile(_template);
let stateToRender = {
owner: this.owner,
name: 'index',
controller: this,
model: undefined,
template: templateFactory(this.owner),
};
stateToRender.name = 'index';
this._outletState.outlets.main = { render: stateToRender, outlets: {} };
this.run(function () {
module.component.setOutletState(module._outletState);
});
if (!this._hasRendered) {
this.run(function () {
module.component.appendTo(module.element);
});
this._hasRendered = true;
}
return this.serializeElement();
}
function serializeElement() {
let serializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap);
return serializer.serialize(this.element);
}