-cases.js 2.6 KB
Newer Older
S
sushuang 已提交
1 2 3 4 5
(function () {

    var testHelper = window.testHelper;
    var encodeHTML = testHelper.encodeHTML;

S
sushuang 已提交
6
    var caseFrame = window.caseFrame;
S
sushuang 已提交
7

S
sushuang 已提交
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
    var filters = [{
        name: 'primary-cases',
        whiteList: [
            'ut/ut.html',
            'ie8.html',
            'touch-slide.html',
            'touch-test.html',
            'touch-candlestick.html',
            'tooltip-touch.html',
            'bar.html',
            'line.html',
            'geoLine.html',
            'graph.html',
            'graph-grid.html',
            'map.html',
            'media-finance.html',
            'axes.html',
            'dataZoom-axes.html',
            'dataZoom-axis-type.html',
            'dataZoom-dynamic.html',
            'visualMap-continuous.html',
            'visualMap-opacity.html',
            'brush.html',
            'brush2.html'
        ]
    }, {
        name: 'stream-cases',
        whiteList: [
            'lines-ny-appendData.html',
            'scatter-random-stream.html',
            'scatter-random-stream-fix-axis.html',
            'scatter-gps.html',
            'scatter-weibo.html',
            'lines-flight.html',
            'stream-filter.html',
            'scatter-stream-visual.html'
        ]
    }];


S
sushuang 已提交
48
    function run() {
S
sushuang 已提交
49

S
sushuang 已提交
50
        // Init list
S
sushuang 已提交
51
        var url = testHelper.dir() + '/';
S
sushuang 已提交
52
        $.ajax({
S
sushuang 已提交
53
            url: url
S
sushuang 已提交
54 55
        }).then(
            function (content) {
S
sushuang 已提交
56
                var pagePaths = fetchPagePaths(content);
S
sushuang 已提交
57
                if (pagePaths.length) {
S
sushuang 已提交
58 59
                    caseFrame.init({
                        dom: document.getElementById('main'),
S
sushuang 已提交
60 61
                        pagePaths: pagePaths,
                        filters: filters
S
sushuang 已提交
62
                    });
S
sushuang 已提交
63 64 65 66
                }
                else {
                    renderFailInfo(url);
                }
S
sushuang 已提交
67 68 69 70 71
            },
            function () {
                renderFailInfo(url);
            }
        );
S
sushuang 已提交
72 73
    }

S
sushuang 已提交
74 75 76 77 78 79
    function renderFailInfo(url) {
        url = encodeHTML(url);
        document.body.innerHTML = 'Error: This page requires a server that is able to list files when visiting'
            + ' <a target="_blank" href="' + url + '">' + url + '</a>.';
    }

S
sushuang 已提交
80 81 82
    function fetchPagePaths(content) {
        var pageList = [];

S
tweak  
sushuang 已提交
83 84
        singleFetch(/"([^"/]*\/)*([^"/]+\.html)\s*"/g);
        singleFetch(/'([^'/]*\/)*([^'/]+\.html)\s*'/g);
S
sushuang 已提交
85 86 87 88

        function singleFetch(pattern) {
            var result;
            while ((result = pattern.exec(content)) != null) {
S
tweak  
sushuang 已提交
89
                pageList.push(result[result.length - 1]);
S
sushuang 已提交
90 91 92 93 94 95
            }
        }

        return pageList;
    }

S
sushuang 已提交
96
    run();
S
sushuang 已提交
97 98

})();