|
| 1 | +{% extends "base.html" %} |
| 2 | +{% block content %} |
| 3 | +<h2>Test runs</h2> |
| 4 | + |
| 5 | +<div class="d-flex justify-content-end mb-3"> |
| 6 | + <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#triggerTestRunModal"> |
| 7 | + <i class="bi bi-play-fill"></i> Trigger test run |
| 8 | + </button> |
| 9 | +</div> |
| 10 | + |
| 11 | +<table class="table table-bordered device-table"> |
| 12 | + <thead class="table-light"> |
| 13 | + <tr> |
| 14 | + <th>ID</th> |
| 15 | + <th>Config</th> |
| 16 | + <th>Status</th> |
| 17 | + <th>Started</th> |
| 18 | + <th>Finished</th> |
| 19 | + <th style="width: 20%">Actions</th> |
| 20 | + </tr> |
| 21 | + </thead> |
| 22 | + <tbody> |
| 23 | + {% for run in runs %} |
| 24 | + <tr> |
| 25 | + <td>{{ run.id }}</td> |
| 26 | + <td>{{ run.config_name }}</td> |
| 27 | + <td> |
| 28 | + {% if run.status == 'finished' %} |
| 29 | + <span class="badge bg-success">Passed</span> |
| 30 | + {% elif run.status == 'failed' %} |
| 31 | + <span class="badge bg-danger">Failed</span> |
| 32 | + {% elif run.status == 'pending' %} |
| 33 | + <span class="badge bg-secondary">Pending</span> |
| 34 | + {% elif run.status == 'running' %} |
| 35 | + <span class="badge bg-warning text-dark">Running</span> |
| 36 | + {% elif run.status == 'aborted' %} |
| 37 | + <span class="badge bg-secondary">Aborted</span> |
| 38 | + {% endif %} |
| 39 | + </td> |
| 40 | + <td>{{ run.started_at or '-' }}</td> |
| 41 | + <td>{{ run.finished_at or '-' }}</td> |
| 42 | + <td> |
| 43 | + <button class="btn btn-sm btn-outline-primary btn-details" data-run-id="{{ run.id }}">Details</button> |
| 44 | + <button class="btn btn-sm btn-outline-danger btn-abort" data-run-id="{{ run.id }}" {% if run.status not in ['pending'] %}disabled{% endif %}>Abort</button> |
| 45 | + </td> |
| 46 | + </tr> |
| 47 | + {% else %} |
| 48 | + <tr><td colspan="6" class="text-center text-muted">No test runs yet</td></tr> |
| 49 | + {% endfor %} |
| 50 | + </tbody> |
| 51 | +</table> |
| 52 | + |
| 53 | +<!-- Trigger Test Run Modal --> |
| 54 | +<div class="modal fade" id="triggerTestRunModal" tabindex="-1" aria-labelledby="triggerTestRunModalLabel" aria-hidden="true"> |
| 55 | + <div class="modal-dialog"> |
| 56 | + <div class="modal-content"> |
| 57 | + <form id="triggerRunForm"> |
| 58 | + <div class="modal-header"> |
| 59 | + <h5 class="modal-title" id="triggerTestRunModalLabel">Trigger new test run</h5> |
| 60 | + <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
| 61 | + </div> |
| 62 | + <div class="modal-body"> |
| 63 | + <div class="mb-3"> |
| 64 | + <label for="configSelect" class="form-label">Configuration</label> |
| 65 | + <select id="configSelect" class="form-select" required> |
| 66 | + {% for cfg in configs %} |
| 67 | + <option value="{{ cfg.name }}">{{ cfg.name }}</option> |
| 68 | + {% endfor %} |
| 69 | + </select> |
| 70 | + </div> |
| 71 | + <div class="mb-3"> |
| 72 | + <label for="testSuiteName" class="form-label">Test suite</label> |
| 73 | + <input type="text" name="name" class="form-control" id="testSuiteName"> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + <div class="modal-footer"> |
| 77 | + <button type="submit" class="btn btn-primary">Trigger</button> |
| 78 | + <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> |
| 79 | + </div> |
| 80 | + </form> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | +</div> |
| 84 | + |
| 85 | +<!-- Test Details Modal --> |
| 86 | +<div class="modal fade" id="testDetailsModal" tabindex="-1" aria-labelledby="testDetailsModalLabel" aria-hidden="true"> |
| 87 | + <div class="modal-dialog modal-lg"> |
| 88 | + <div class="modal-content"> |
| 89 | + <div class="modal-header"> |
| 90 | + <h5 class="modal-title" id="testDetailsModalLabel">Test Run Details</h5> |
| 91 | + <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
| 92 | + </div> |
| 93 | + <div class="modal-body"> |
| 94 | + <dl class="row"> |
| 95 | + <dt class="col-sm-3">Run ID</dt><dd class="col-sm-9" id="detail-id">-</dd> |
| 96 | + <dt class="col-sm-3">Config</dt><dd class="col-sm-9" id="detail-config">-</dd> |
| 97 | + <dt class="col-sm-3">Status</dt><dd class="col-sm-9" id="detail-status">-</dd> |
| 98 | + <dt class="col-sm-3">Start time</dt><dd class="col-sm-9" id="detail-start">-</dd> |
| 99 | + <dt class="col-sm-3">Finish time</dt><dd class="col-sm-9" id="detail-end">-</dd> |
| 100 | + </dl> |
| 101 | + <h6>Artifacts</h6> |
| 102 | + <ul id="artifact-list" class="list-group mb-3"> |
| 103 | + <li class="list-group-item text-muted">No artifacts</li> |
| 104 | + </ul> |
| 105 | + <div class="text-end"> |
| 106 | + <a id="report-link" href="#" class="btn btn-outline-secondary" target="_blank"> |
| 107 | + <i class="bi bi-file-earmark-text"></i> Download CSV Report |
| 108 | + </a> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + </div> |
| 113 | +</div> |
| 114 | + |
| 115 | +<script> |
| 116 | +document.addEventListener("DOMContentLoaded", function () { |
| 117 | + // Trigger run form |
| 118 | + document.getElementById('triggerRunForm').addEventListener('submit', async (e) => { |
| 119 | + e.preventDefault(); |
| 120 | + const config = document.getElementById('configSelect').value; |
| 121 | + const testSuite = document.getElementById('testSuiteName').value; |
| 122 | + let payload = { config_name: config, test_suite_name: testSuite}; |
| 123 | + |
| 124 | + const resp = await fetch('/api/v1/test-runs', { |
| 125 | + method: 'POST', |
| 126 | + headers: { 'Content-Type': 'application/json' }, |
| 127 | + body: JSON.stringify(payload) |
| 128 | + }); |
| 129 | + |
| 130 | + if (resp.ok) location.reload(); |
| 131 | + else alert('Failed to trigger test run'); |
| 132 | + }); |
| 133 | + |
| 134 | + // Details modal |
| 135 | + document.querySelectorAll('.btn-details').forEach(btn => { |
| 136 | + btn.addEventListener('click', async (e) => { |
| 137 | + const id = e.target.closest("button").dataset.runId; |
| 138 | + const resp = await fetch(`/api/v1/test-runs/${id}`); |
| 139 | + if (!resp.ok) return alert('Failed to fetch run details'); |
| 140 | + const data = await resp.json(); |
| 141 | + |
| 142 | + const resp_art = await fetch(`/api/v1/test-runs/${id}/artifacts`); |
| 143 | + if (!resp_art.ok) return alert('Failed to fetch run artifacts'); |
| 144 | + const data_art = await resp_art.json(); |
| 145 | + |
| 146 | + document.getElementById('detail-id').textContent = data.id; |
| 147 | + document.getElementById('detail-config').textContent = data.config_name; |
| 148 | + document.getElementById('detail-status').textContent = data.status; |
| 149 | + document.getElementById('detail-start').textContent = data.started_at || '-'; |
| 150 | + document.getElementById('detail-end').textContent = data.finished_at || '-'; |
| 151 | + |
| 152 | + // Populate artifacts |
| 153 | + const artifactList = document.getElementById('artifact-list'); |
| 154 | + artifactList.innerHTML = ''; |
| 155 | + if (data_art && data_art.length > 0) { |
| 156 | + data_art.forEach(artifact => { |
| 157 | + const li = document.createElement('li'); |
| 158 | + li.className = 'list-group-item d-flex justify-content-between align-items-center'; |
| 159 | + li.textContent = artifact.name; |
| 160 | + const a = document.createElement('a'); |
| 161 | + a.href = `/api/v1/test-runs/${id}/artifacts/${encodeURIComponent(artifact.name)}`; |
| 162 | + a.className = 'btn btn-sm btn-outline-primary'; |
| 163 | + a.textContent = 'Download'; |
| 164 | + li.appendChild(a); |
| 165 | + artifactList.appendChild(li); |
| 166 | + }); |
| 167 | + } else { |
| 168 | + artifactList.innerHTML = '<li class="list-group-item text-muted">No artifacts</li>'; |
| 169 | + } |
| 170 | + |
| 171 | + // Report link |
| 172 | + const reportLink = document.getElementById('report-link'); |
| 173 | + reportLink.href = `/api/v1/test-runs/${id}/report`; |
| 174 | + |
| 175 | + new bootstrap.Modal(document.getElementById('testDetailsModal')).show(); |
| 176 | + }); |
| 177 | + }); |
| 178 | +}); |
| 179 | +</script> |
| 180 | +{% endblock %} |
| 181 | + |
0 commit comments