1 | define(["require", "exports", "aurelia-templating", "./wait"], function (require, exports, aurelia_templating_1, wait_1) {
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | var StageComponent = (function () {
|
5 | function StageComponent() {
|
6 | }
|
7 | StageComponent.withResources = function (resources) {
|
8 | if (resources === void 0) { resources = []; }
|
9 | return new ComponentTester().withResources(resources);
|
10 | };
|
11 | return StageComponent;
|
12 | }());
|
13 | exports.StageComponent = StageComponent;
|
14 | var ComponentTester = (function () {
|
15 | function ComponentTester() {
|
16 | this.resources = [];
|
17 | }
|
18 | ComponentTester.prototype.configure = function (aurelia) {
|
19 | return aurelia.use.standardConfiguration();
|
20 | };
|
21 | ComponentTester.prototype.bootstrap = function (configure) {
|
22 | this.configure = configure;
|
23 | };
|
24 | ComponentTester.prototype.withResources = function (resources) {
|
25 | this.resources = resources;
|
26 | return this;
|
27 | };
|
28 | ComponentTester.prototype.inView = function (html) {
|
29 | this.html = html;
|
30 | return this;
|
31 | };
|
32 | ComponentTester.prototype.boundTo = function (bindingContext) {
|
33 | this.bindingContext = bindingContext;
|
34 | return this;
|
35 | };
|
36 | ComponentTester.prototype.manuallyHandleLifecycle = function () {
|
37 | this._prepareLifecycle();
|
38 | return this;
|
39 | };
|
40 | ComponentTester.prototype.create = function (bootstrap) {
|
41 | var _this = this;
|
42 | return bootstrap(function (aurelia) {
|
43 | return Promise.resolve(_this.configure(aurelia)).then(function () {
|
44 | if (_this.resources) {
|
45 | aurelia.use.globalResources(_this.resources);
|
46 | }
|
47 | return aurelia.start().then(function () {
|
48 | _this.host = document.createElement('div');
|
49 | _this.host.innerHTML = _this.html;
|
50 | document.body.appendChild(_this.host);
|
51 | return aurelia.enhance(_this.bindingContext, _this.host).then(function () {
|
52 | _this.rootView = aurelia.root;
|
53 | _this.element = _this.host.firstElementChild;
|
54 | if (aurelia.root.controllers.length) {
|
55 | _this.viewModel = aurelia.root.controllers[0].viewModel;
|
56 | }
|
57 | return new Promise(function (resolve) { return setTimeout(function () { return resolve(); }, 0); });
|
58 | });
|
59 | });
|
60 | });
|
61 | });
|
62 | };
|
63 | ComponentTester.prototype.dispose = function () {
|
64 | if (this.host === undefined || this.rootView === undefined) {
|
65 | throw new Error('Cannot call ComponentTester.dispose() before ComponentTester.create()');
|
66 | }
|
67 | this.rootView.detached();
|
68 | this.rootView.unbind();
|
69 | return this.host.parentNode.removeChild(this.host);
|
70 | };
|
71 | ComponentTester.prototype._prepareLifecycle = function () {
|
72 | var _this = this;
|
73 |
|
74 | var bindPrototype = aurelia_templating_1.View.prototype.bind;
|
75 |
|
76 | aurelia_templating_1.View.prototype.bind = function () { };
|
77 | this.bind = function (bindingContext) { return new Promise(function (resolve) {
|
78 | aurelia_templating_1.View.prototype.bind = bindPrototype;
|
79 | if (bindingContext !== undefined) {
|
80 | _this.bindingContext = bindingContext;
|
81 | }
|
82 | _this.rootView.bind(_this.bindingContext);
|
83 | setTimeout(function () { return resolve(); }, 0);
|
84 | }); };
|
85 |
|
86 | var attachedPrototype = aurelia_templating_1.View.prototype.attached;
|
87 |
|
88 | aurelia_templating_1.View.prototype.attached = function () { };
|
89 | this.attached = function () { return new Promise(function (resolve) {
|
90 | aurelia_templating_1.View.prototype.attached = attachedPrototype;
|
91 | _this.rootView.attached();
|
92 | setTimeout(function () { return resolve(); }, 0);
|
93 | }); };
|
94 |
|
95 | this.detached = function () { return new Promise(function (resolve) {
|
96 | _this.rootView.detached();
|
97 | setTimeout(function () { return resolve(); }, 0);
|
98 | }); };
|
99 |
|
100 | this.unbind = function () { return new Promise(function (resolve) {
|
101 | _this.rootView.unbind();
|
102 | setTimeout(function () { return resolve(); }, 0);
|
103 | }); };
|
104 | };
|
105 | ComponentTester.prototype.waitForElement = function (selector, options) {
|
106 | var _this = this;
|
107 | return wait_1.waitFor(function () { return _this.element.querySelector(selector); }, options);
|
108 | };
|
109 | ComponentTester.prototype.waitForElements = function (selector, options) {
|
110 | var _this = this;
|
111 | return wait_1.waitFor(function () { return _this.element.querySelectorAll(selector); }, options);
|
112 | };
|
113 | return ComponentTester;
|
114 | }());
|
115 | exports.ComponentTester = ComponentTester;
|
116 | });
|