Files
micronomicon/backend/uframe/tests/test_components.py
2026-04-03 10:15:30 +02:00

124 lines
3.0 KiB
Python

"""Tests for components and standard library."""
import uframe
def test_inline_component():
source = '''page "Test" 50
component greeting(name)
heading 1 "Hello $name"
text "Welcome, $name!"
greeting "Alice"
greeting "Bob"'''
result = uframe.compile(source)
assert "Hello Alice" in result.ascii
assert "Welcome, Alice!" in result.ascii
assert "Hello Bob" in result.ascii
assert "Welcome, Bob!" in result.ascii
def test_component_with_gauge():
source = '''page "Test" 50
component stat(label, value, max)
gauge "$label" $value $max 20
stat "CPU" 62 100
stat "MEM" 84 100'''
result = uframe.compile(source)
assert "CPU" in result.ascii
assert "MEM" in result.ascii
assert "" in result.ascii
def test_use_std_dashboard():
source = '''page "Test" 60
use std/dashboard
banner "My Node" "Mesh Network"'''
result = uframe.compile(source)
assert "My Node" in result.ascii
assert "Mesh Network" in result.ascii
assert "" in result.ascii # double box from banner
def test_use_std_dashboard_resources():
source = '''page "Test" 60
use std/dashboard
resources 42 67'''
result = uframe.compile(source)
assert "CPU" in result.ascii
assert "MEM" in result.ascii
assert "Resources" in result.ascii
def test_use_std_nav():
source = '''page "Test" 50
use std/nav
nav_link "Home" "/page/index.mu"
nav_divider
nav_link "About" "/page/about.mu"'''
result = uframe.compile(source)
assert "Home" in result.ascii
assert "About" in result.ascii
def test_use_std_status_bar():
source = '''page "Test" 60
use std/status-bar
status_bar "Uptime" 95 100'''
result = uframe.compile(source)
assert "Uptime" in result.ascii
assert "" in result.ascii
def test_use_std_status_bar_item():
source = '''page "Test" 60
use std/status-bar
status_item "Gateway" online'''
result = uframe.compile(source)
assert "Gateway" in result.ascii
assert "" in result.ascii
def test_use_std_status_bar_row():
source = '''page "Test" 60
use std/status-bar
status_row "East" online "West" offline'''
result = uframe.compile(source)
assert "East" in result.ascii
assert "West" in result.ascii
def test_use_std_network_peer_list():
source = '''page "Test" 60
use std/network
peer_list "Active Peers"'''
result = uframe.compile(source)
assert "Active Peers" in result.ascii
def test_use_std_form_search():
source = '''page "Test" 60
use std/form
search_form "search" "/page/results.mu"'''
result = uframe.compile(source)
assert "Search" in result.ascii
assert "results.mu" in result.micron
def test_use_std_form_login():
source = '''page "Test" 60
use std/form
login_form "/page/auth.mu"'''
result = uframe.compile(source)
assert "Login" in result.ascii
assert "auth.mu" in result.micron
def test_unknown_component_ignored():
source = '''page "Test" 50
heading 1 "Hello"
nonexistent_thing "arg"'''
result = uframe.compile(source)
assert "Hello" in result.ascii