Skip to content

Commit

Permalink
[Tests] Support "dark mode" and custom page title, in html logger
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesJJ committed Feb 21, 2025
1 parent 442c81c commit 98acb5b
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/html/map1.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-bs-theme="light">
<head>
<meta charset="utf-8" />
<meta
Expand All @@ -25,7 +25,7 @@

<body onload="check_age();">
<div
class="navbar navbar-light bg-light border-bottom border-danger"
class="navbar navbar-light border-bottom border-danger"
id="summary"
>
<div class="container-fluid">
Expand Down
4 changes: 2 additions & 2 deletions tests/html/test1.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-bs-theme="light">
<head>
<meta charset="utf-8" />
<meta
Expand All @@ -25,7 +25,7 @@

<body onload="check_age();">
<div
class="navbar navbar-light bg-light border-bottom border-danger"
class="navbar navbar-light border-bottom border-danger"
id="summary"
>
<div class="container-fluid">
Expand Down
4 changes: 2 additions & 2 deletions tests/html/test2.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-bs-theme="light">
<head>
<meta charset="utf-8" />
<meta
Expand All @@ -25,7 +25,7 @@

<body onload="check_age();">
<div
class="navbar navbar-light bg-light border-bottom border-danger"
class="navbar navbar-light border-bottom border-danger"
id="summary"
>
<div class="container-fluid">
Expand Down
175 changes: 175 additions & 0 deletions tests/html/test3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>

<title>FAIL@fake_hostname.local monitor</title>

<script src="main.bundle.js"></script>
<meta http-equiv="refresh" content="30" />
<script language="javascript" type="text/javascript">
function check_age() {
var generated = 1587211200;
var now = Date.parse(new Date()) / 1000;
var diff = now - generated;
if (diff > (30 * 2)) {
too_old();
}
}
</script>
</head>

<body onload="check_age();">
<div
class="navbar navbar-light border-bottom border-danger"
id="summary"
>
<div class="container-fluid">
<div class="navbar-brand">Custom NavBar Title</div>
<div class="navbar-text d-none d-lg-block" id="updated">
Updated at 2020-04-18 12:00:00+00:00 by fake_hostname.local (__VERSION__)
</div>
<div class="navbar-text" id="refresh_status">
<span class="badge bg-warning d-none" id="refresh_badge"
>OUT OF DATE</span
>
</div>
<div class="navbar-text"><span class="badge bg-success">1 OK</span> <span class="badge bg-danger">1 FAIL</span> <span class="badge bg-secondary">1 DISABLED</span> </div>
</div>
</div>
<table class="table table-borderless table-striped table-hover table-sm">
<tr>
<th scope="col">Monitor</th>
<th scope="col">Status</th>
<th scope="col">Host</th>
<th scope="col">Failed at</th>
<th scope="col">VFC</th>
<th scope="col">Up/downtime</th>
<th scope="col">Detail</th>
<th scope="col">Failures</th>
<th scope="col">Last Failure</th>
<th scope="col">Age</th>
</tr>
<tr class="table-danger">
<td>
<span
data-toggle="tooltip"
data-placement="right"
title="A monitor which always fails."
>fail</span
>
</td>
<td>FAIL</td>
<td>fake_hostname</td>
<td>2020-04-18 12:00:00+00:00</td>
<td>1</td>
<td>0+00:00:00 (<span
data-toggle="tooltip"
data-placement="right"
title="0.00000%"
>0.00%</span
>)
</td>
<td>This monitor always fails.</td>

<td>1</td>
<td>2020-04-18 12:00:00+00:00</td>

<td></td>
</tr>
<tr>
<td>
<span
data-toggle="tooltip"
data-placement="right"
title="A monitor which always fails."
>disabled</span
>
</td>
<td>DISABLED</td>
<td>fake_hostname</td>
<td></td>
<td></td>
<td>0+00:00:00 (<span
data-toggle="tooltip"
data-placement="right"
title="0.00000%"
>0.00%</span
>)
</td>
<td></td>

<td></td><td></td>

<td></td>
</tr>
<tr>
<td>
<span
data-toggle="tooltip"
data-placement="right"
title="(Monitor did not write an auto-biography.)"
>unnamed</span
>
</td>
<td class="table-success">OK</td>
<td>fake_hostname</td>
<td></td>
<td></td>
<td>0+00:00:00 (<span
data-toggle="tooltip"
data-placement="right"
title="0.00000%"
>0.00%</span
>)
</td>
<td></td>

<td></td><td></td>

<td></td>
</tr>
</table>
<div class="navbar-text d-block d-lg-none" id="updatedfooter">
Updated at 2020-04-18 12:00:00+00:00<br />by fake_hostname.local (__VERSION__)
</div>
<div class="container-fluid">
<div class="text-end text-muted">
SimpleMonitor __VERSION__
<a
href="https://simplemonitor.readthedocs.io/en/latest/index.html"
target="_blank"
>&raquo; Documentation</a
>
|
<a href="https://github.com/jamesoff/simplemonitor" target="_blank"
>&raquo; Code</a
>
</div>
</div>
<script language="javascript" type="text/javascript">
$(function () {
var tooltipTriggerList = [].slice.call(
document.querySelectorAll('[data-toggle="tooltip"]')
);
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
check_age();
setTimeout(too_old, (30 * 2000));
update_props = {
timestamp: 1587211200,
host: "fake_hostname.local",
version: "__VERSION__",
updated: "2020-04-18 12:00:00+00:00",
};
setInterval(update_age, 5000, update_props);
update_age(update_props);
});
</script>
</body>
</html>
7 changes: 7 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ def test_html_map(self):
golden_file = "tests/html/map1.html"
self._compare_files(test_file, golden_file)

def test_html_custom_appearance(self):
test_file = self._write_html(
{"navbar_title": "Custom NavBar Title", "visual_theme":"dark"}
)
golden_file = "tests/html/test3.html"
self._compare_files(test_file, golden_file)

def test_config_start(self):
with self.assertRaises(RuntimeError):
_ = HTMLLogger({"map": "1", "filename": "something"})
Expand Down

0 comments on commit 98acb5b

Please sign in to comment.