-
Notifications
You must be signed in to change notification settings - Fork 190
/
environment.ts
75 lines (62 loc) · 2.41 KB
/
environment.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
import { IDOMChanges, DOMChanges } from '@glimmer/runtime';
import { Simple, Maybe } from '@glimmer/interfaces';
import { NodeDOMTreeConstruction } from '@glimmer/node';
import * as SimpleDOM from 'simple-dom';
import LazyTestEnvironment from '../lazy/environment';
import LazyRenderDelegate from '../lazy/render-delegate';
import EagerRenderDelegate from '../eager/render-delegate';
import RenderDelegate from '../../../render-delegate';
import { RenderTest } from '../../../render-test';
export interface NodeEnvironmentOptions {
document: Simple.Document;
appendOperations?: NodeDOMTreeConstruction;
updateOperations?: IDOMChanges;
}
function testOptions(options: NodeEnvironmentOptions) {
let document = options.document;
let appendOperations: Maybe<NodeDOMTreeConstruction> = options && options.appendOperations;
let updateOperations: Maybe<IDOMChanges> = options && options.updateOperations;
if (!appendOperations) {
appendOperations = new NodeDOMTreeConstruction(document);
}
if (!updateOperations) {
updateOperations = new DOMChanges(document as HTMLDocument);
}
return { appendOperations, updateOperations, document };
}
export class NodeEnv extends LazyTestEnvironment {
protected document: Simple.Document;
constructor(options: NodeEnvironmentOptions) {
super(testOptions(options));
this.document = options.document;
}
}
export class NodeLazyRenderDelegate extends LazyRenderDelegate {
constructor() {
super(new NodeEnv({ document: new SimpleDOM.Document() }));
}
}
export class NodeEagerRenderDelegate extends EagerRenderDelegate {
constructor() {
super(new NodeEnv({ document: new SimpleDOM.Document() }));
}
}
export class AbstractNodeTest extends RenderTest {
protected serializer: SimpleDOM.HTMLSerializer;
constructor(delegate: RenderDelegate) {
super(delegate);
this.serializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap);
}
assertHTML(html: string) {
let serialized = this.serializer.serializeChildren(this.element);
this.assert.equal(serialized, html);
}
assertComponent(html: string) {
let el = this.element.firstChild! as Element;
this.assert.equal(el.getAttribute('class'), 'ember-view');
this.assert.ok(el.getAttribute('id'));
this.assert.ok(el.getAttribute('id')!.indexOf('ember') > -1);
let serialized = this.serializer.serializeChildren(this.element.firstChild!);
this.assert.equal(serialized, html);
}
}