"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var testSearcher_1 = require("./testSearcher");
var testRunner_1 = require("../testRunner");
var queryParser_1 = require("../partial-src/component/queryParser");
var Page = (function (_super) {
    __extends(Page, _super);
    function Page() {
        var _this = _super.call(this) || this;
        _this.testSearcher = new testSearcher_1.TestSearcher();
        _this.testSearcher.events.listenBy(_this, "test", function (path) {
            window.location.hash = "testcase=" + path;
            var pathes = [];
            if (path === "all") {
                pathes = _this.getMatchesTest("");
            }
            else {
                pathes = [path];
            }
            _this.runTests(pathes);
        });
        return _this;
    }
    Page.prototype.runTests = function (pathes) {
        var runner = new (testRunner_1.TestRunner.bind.apply(testRunner_1.TestRunner, [void 0].concat(pathes)))();
        this.UI.mocha.innerHTML = "";
        runner.run();
    };
    Page.prototype.initialCheck = function () {
        var urlObject = queryParser_1.QueryParser.parse(window.location.hash.slice(1));
        if (urlObject["testcase"]) {
            var path = urlObject["testcase"];
            if (path == "all")
                path = "";
            var matches = this.getMatchesTest(path);
            this.runTests(matches);
        }
    };
    Page.prototype.getMatchesTest = function (path) {
        var matches = LeafTestContext.scripts.filter(function (item) { return item.scriptPath.indexOf("test.js") >= 0; }).map(function (item) { return item.scriptPath; }).filter(function (name) { return name.indexOf(path) >= 0; });
        return matches;
    };
    return Page;
}(R.Page));
exports.Page = Page;
//# sourceMappingURL=page.js.map