• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html lang="en">
3
4<head>
5    <meta charset="UTF-8">
6    <title>Test case management</title>
7    <script src="index.js"></script>
8    <link rel="stylesheet" href="page.css">
9</head>
10
11<body>
12<div class="allPage">
13    <div class="prAddress">
14        <button class="custom-button" id="buttonEleAdd" onclick="allCheckBoxT()">全选</button>
15        <button class="custom-button" id="buttonEleDel" onclick="deleteCheckBox()">置空</button>
16        <button class="custom-button checkBoxClass" onclick="closeCheckBox()">折叠</button>
17        <button class="custom-button checkBoxClass" onclick="openCheckBox()">展开</button>
18        <input id="prInput" class='middle-input__inner' type="text"
19               value="https://gitee.com/openharmony/arkui_ace_engine/pulls/36631">
20    </div>
21    <div id="divId" class="divClass">
22        <table id="tableEle">
23            <tr>
24                <th>Project Name</th>
25                <th>Component Name</th>
26                <th>File Name</th>
27            </tr>
28        </table>
29    </div>
30</div>
31<div class="hsize2">
32    <H5 id="tooltip" style="margin-left: 30px;"></H5>
33</div>
34<div class="hsize">
35    <H3>执行结果:</H3>
36</div>
37<div class="execute">
38    <div id="executeMes"></div>
39    <button class="custom-button" id="buttonEle" onclick="execute()">开始执行</button>
40
41</div>
42
43</div>
44
45</div>
46
47<script>
48    let projectMap = new Map();
49    let componentMap = new Map();
50    let testCase = [];
51    let checkboxLst = [];
52    let isCaseStatus = false;
53    let isInterval = false;
54    window.onload = async function () {
55        await readCSV();
56        await execute('refresh');
57    };
58
59    async function readCSV() {
60        await readCsv().then((res) => {
61            testCase = res;
62            showTable(testCase);
63        })
64    }
65
66    function showTable(caseList) {
67        const tableEle = document.getElementById('tableEle');
68        const caseTree = listToTree(caseList);
69        for (let index = 0; index < caseTree.length; index++) {
70            projectMap.set(`${caseTree[index].name}`, `${caseTree[index].id}`);
71            for (let j = 0; j < caseTree[index].value.length; j++) {
72                componentMap.set(`${caseTree[index].name}_${caseTree[index].value[j].name}`, caseTree[index].value[j].id);
73            }
74        }
75        for (let i = 0; i < caseList.length; i++) {
76            let id;
77            const trEle = document.createElement('tr');
78            ['Project Name', 'Component Name', 'File Name'].forEach((name) => {
79                let tdEle;
80                if (name === 'Project Name') {
81                    id = projectMap.get(caseList[i]['Project Name']);
82                } else if (name === 'Component Name') {
83                    id = componentMap.get(`${caseList[i]['Project Name']}_${caseList[i]['Component Name']}`);
84                } else {
85                    id = caseList[i]['File Name'];
86                }
87                if (i === 0 || caseList[i][name] !== caseList[i - 1][name]) {
88                    tdEle = createCheckboxCell(name, caseList[i][name], caseTree, id);
89                } else {
90                    if (caseList[i]['Project Name'] !== caseList[i - 1]['Project Name'] &&
91                        caseList[i]['Component Name'] === caseList[i - 1]['Component Name'] && i !== 0) {
92                        tdEle = createCheckboxCell(name, caseList[i][name], caseTree, id);
93                    } else {
94                        tdEle = document.createElement('td');
95                    }
96                }
97                trEle.appendChild(tdEle);
98            });
99            trEle.setAttribute(`${caseList[i]['Project Name']}`, '');
100            trEle.setAttribute(`${id}`, '');
101            tableEle.appendChild(trEle);
102        }
103
104        document.querySelectorAll('td').forEach(function (td) {
105            td.addEventListener('mouseenter', function () {
106                const tooltip = document.getElementById('tooltip');
107                let inputData;
108                let a = td.querySelectorAll('input')[0].attributes;
109                if (td.querySelectorAll('input')[0]) {
110                    inputData = td.querySelectorAll('input')[0].getAttribute('value');
111                } else {
112                    return;
113                }
114                let jsonData = JSON.parse(inputData);
115                let shows = jsonData[2];
116                if (inputData) {
117                    tooltip.textContent = td.getAttribute('data-tooltip');
118                    tooltip.style.display = 'block';
119                    if ("File Name" === jsonData[1]) {
120                        tooltip.innerHTML = `<span style="color: brown;font-size: 20px;width: 347px;display: inline-block">${shows[0][0]}</span>
121                         <span style="color: #2640c5;font-size: 20px;width: 380px;display: inline-block">${shows[0][1]}</span>
122                         <span style="color: #7dbbd8;font-size: 20px">${shows[0][2]}</span>`;
123                    } else if ("Component Name" === jsonData[1]) {
124                        tooltip.innerHTML = `<span style="color: brown;font-size: 20px;width: 347px;display: inline-block">${shows[0][0]}</span>
125                         <span style="color: #2640c5;font-size: 20px;width: 380px">${shows[0][1]}</span>`;
126                    }
127                }
128            });
129        });
130    }
131
132    function allCheckBoxT() {
133        checkboxLst = this.addCheckBox();
134    }
135
136    function deleteCheckBox() {
137        this.removeCheckBox();
138        checkboxLst = [];
139    }
140
141    function closeCheckBox() {
142        let array = uniqueArray(testCase);
143        let projectName = '';
144        let tempName;
145        let index = 0;
146        for (let i = 0; i < array.length; i++) {
147            tempName = array[i]["Project Name"];
148            let ent = {
149                target: {
150                    textContent: '-'
151                }
152            };
153            if (projectName !== tempName) {
154                foldTr(tempName, "Project Name", ent);
155                document.getElementsByClassName('checkBoxButton')[index].innerHTML = '+';
156                projectName = array[i]["Project Name"];
157                index++;
158            }
159        }
160    }
161
162    function openCheckBox() {
163        let array = uniqueArray(testCase);
164        let projectName = '';
165        let tempName;
166        let index = 0;
167        for (let i = 0; i < array.length; i++) {
168            tempName = array[i]["Project Name"];
169            let ent = {
170                target: {
171                    textContent: '+'
172                }
173            };
174            if (projectName !== tempName) {
175                foldTr(tempName, "Project Name", ent);
176                document.getElementsByClassName('checkBoxButton')[index].innerHTML = '-';
177                projectName = array[i]["Project Name"];
178                index++;
179            }
180        }
181    }
182
183    function uniqueArray(arr) {
184        return [...new Set(arr)];
185    }
186
187    function startInterval() {
188        const executeMes = document.getElementById('executeMes');
189        isInterval = true;
190        return new Promise(() => {
191            let setIntervalId = setInterval(() => {
192                fetch('/api/getExecuteStatus')
193                    .then(response => response.json())
194                    .then(status => {
195                        if (status.execResult === -1) {
196                            document.getElementById('buttonEle').innerHTML = '开始执行';
197                        } else if (status.execResult === 0) {
198                            executeMes.style.color = '#2ef604';
199                            executeMes.innerText = 'Success';
200                            this.removeCheckBox();
201                        } else if (status.execResult === 1) {
202                            executeMes.style.color = '#fd0026';
203                            executeMes.innerText = status.mes;
204                        } else if (status.execResult === 2) {
205                            return;
206                        }
207                        updateUI();
208                    })
209                    .catch((error) => {
210                        updateUI();
211                        throw error;
212                    });
213            }, 1500);
214
215            function updateUI() {
216                clearInterval(setIntervalId);
217                isCaseStatus = false;
218                isInterval = false;
219                document.getElementById('buttonEle').innerText = '开始执行';
220            }
221        })
222    }
223
224    function execute(refresh_status) {
225        let tempList = checkboxLst;
226        document.getElementById('executeMes').innerText = '';
227        fetch('/api/getExecuteStatus')
228            .then(response => response.json())
229            .then(status => {
230                if (status.execResult === 2 || isCaseStatus) {
231                    document.getElementById('buttonEle').innerHTML = '用例执行中...';
232                    if (refresh_status !== 'refresh') {
233                        alert("请等待用例执行完成在继续操作!!!");
234                    }
235                    if (!isCaseStatus && !isInterval) {
236                        startInterval();
237                    }
238                } else {
239                    if (tempList.length !== 0) {
240                        tempList = uniqueArray(tempList);
241                        isCaseStatus = true;
242                        document.getElementById('buttonEle').innerHTML = '用例执行中...';
243                        startInterval();
244                        run(tempList, document.getElementById('prInput').value);
245                    }
246                }
247            });
248    }
249
250    function removeCheckBox() {
251        let checkedCheckboxes = document.querySelectorAll('input[type="checkbox"]:checked');
252        for (let i = 0; i <= checkedCheckboxes.length - 1; i++)
253            if (checkedCheckboxes[i].checked) {
254                checkedCheckboxes[i].checked = false;
255            }
256    }
257
258    function addCheckBox() {
259        let dataArray = [];
260        let checkedCheckboxes = document.querySelectorAll('input[type="checkbox"]');
261        for (let i = 0; i <= checkedCheckboxes.length - 1; i++)
262            if (!checkedCheckboxes[i].checked) {
263                checkedCheckboxes[i].checked = true;
264            }
265        let checkboxes = document.querySelectorAll('input[type="checkbox"]:checked');
266        checkboxes.forEach((e) => {
267            let val = e.value;
268            let array = [];
269            if (e.value.includes("File Name")) {
270                let t = [];
271                t = JSON.parse(e.value)[2];
272                if (t.length > 0) {
273                    dataArray.push(t[0]);
274                }
275            }
276        })
277        return dataArray;
278    }
279
280
281</script>
282<style>
283    .allPage {
284        width: 1376px;
285        height: 600px;
286        background-color: #f0f8ff;
287    }
288
289    body {
290        display: block;
291        margin: 8px;
292        height: 100%;
293    }
294
295    .middle-input__inner {
296        margin: 70px;
297        -webkit-appearance: none;
298        background-color: #fff;
299        background-image: none;
300        border-radius: 4px;
301        border: 1px solid #dcdfe6;
302        box-sizing: border-box;
303        color: #606266;
304        display: inline-block;
305        font-size: inherit;
306        height: 60px;
307        line-height: 60px;
308        outline: none;
309        padding: 0 15px;
310        transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
311        width: 100%;
312    }
313
314    #prInput {
315        width: 400px;
316        background-color: #e3ebf3;
317        height: 28px;
318        font-size: 15px;
319        margin-left: 30px;
320        margin-top: 80px;
321    }
322
323    table {
324        height: auto;
325    }
326
327    .titles {
328        margin: 80px;
329    }
330
331    .prAddress {
332        margin-top: -70px;
333        margin-bottom: 15px;
334        width: 1200px;
335        margin-left: 188px;
336    }
337
338    table {
339        position: relative;
340        box-sizing: border-box;
341        flex: 1;
342        width: 1280px;
343        height: 50px;
344        background-color: #fff;
345        font-size: 14px;
346        color: #606266;
347        border: 1px solid #ebeef5;
348        border-right: none;
349        border-bottom: none;
350        position: absolute;
351        z-index: 0;
352    }
353
354    th {
355        background-color: #a0d6fb;
356        overflow: hidden;
357        text-overflow: ellipsis;
358        white-space: normal;
359        word-break: break-all;
360        line-height: 23px;
361        padding-left: 10px;
362        padding-right: 10px;
363    }
364
365    td {
366        overflow: hidden;
367        text-overflow: ellipsis;
368        white-space: normal;
369        word-break: break-all;
370        line-height: 23px;
371        padding-left: 10px;
372        padding-right: 10px;
373    }
374
375    #executeMes {
376        background-color: #F6F7F2;
377        width: 1000px;
378        margin-left: 30px;
379        border-radius: 5px;
380        border: 1px solid #3b3030;
381        position: relative;
382        display: inline-block;
383        vertical-align: bottom;
384        font-size: 14px;
385    }
386
387    .hsize {
388        float: left;
389        margin-left: 30px;
390        height: 40px;
391        width: 50%;
392    }
393
394    .hsize2 {
395        float: left;
396        margin-right: 100px;
397        height: 40px;
398        width: 80%;
399    }
400
401    .custom-button {
402        display: inline-block;
403        line-height: 1;
404        white-space: nowrap;
405        cursor: pointer;
406        background: #5084ec;
407        border: 1px solid #dcdfe6;
408        color: #fff;
409        -webkit-appearance: none;
410        text-align: center;
411        box-sizing: border-box;
412        outline: none;
413        margin: 0;
414        transition: .1s;
415        font-weight: 300;
416        -moz-user-select: none;
417        -webkit-user-select: none;
418        -ms-user-select: none;
419        padding: 12px 20px;
420        font-size: 14px;
421        border-radius: 4px;
422        margin-right: -5px;
423        margin-top: 80px;
424    }
425
426    #buttonEleAdd {
427        margin-top: 30px;
428        margin-left: 30px;
429    }
430
431    #buttonEleDel {
432        margin-top: 30px;
433        margin-left: 30px;
434        background-color: rgba(211, 30, 30, 0.829);
435    }
436
437    ::-webkit-scrollbar {
438        width: 8px;
439        height: 12px;
440    }
441
442    ::-webkit-scrollbar-track {
443        background: #f0f8ff;
444    }
445
446    ::-webkit-scrollbar-thumb {
447        background: #f0f8ff;
448        border-radius: 5px;
449        opacity: 0.8;
450    }
451
452    #buttonEle {
453        margin-right: 140px;
454        margin-top: 103px;
455        width: 12%;
456    }
457
458    ::-webkit-scrollbar-thumb:hover {
459        background: #7dbbd8;
460        opacity: 0.8;
461    }
462
463    .execute {
464        width: 100%;
465        margin-left: 0px;
466        margin-top: 27px;
467    }
468
469    body,
470    html {
471        margin: 0;
472        padding: 0;
473        width: 100%;
474        height: 100%;
475        background-color: #f0f8ff;
476        font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif;
477        -webkit-font-smoothing: antialiased;
478        -webkit-tap-highlight-color: transparent;
479    }
480
481    .demo-block {
482        margin-bottom: 24px;
483    }
484
485    .execute {
486        width: 96%;
487    }
488
489    .divClass {
490        position: relative;
491        overflow-y: auto;
492        box-sizing: border-box;
493        flex: 1;
494        background-color: #f0f8ff;
495        font-size: 14px;
496        width: 1300px;
497        height: 500px;
498        color: #606266;
499        margin-top: -70px;
500        margin-left: 30px;
501        z-index: 1;
502    }
503
504    #tableEle {
505        z-index: 0;
506    }
507
508    .checkBoxClass {
509        margin-top: 30px;
510        margin-left: 30px;
511    }
512</style>
513</body>
514
515</html>