tui_test.go 1.85 KB
Newer Older
liming6's avatar
liming6 committed
1
2
3
4
package tui

import (
	"fmt"
5
	"get-container/cmd/hytop/backend"
liming6's avatar
liming6 committed
6
	"testing"
liming6's avatar
liming6 committed
7
	"time"
liming6's avatar
liming6 committed
8
9

	"github.com/charmbracelet/lipgloss"
liming6's avatar
liming6 committed
10
11
)

liming6's avatar
liming6 committed
12
13
14
15
16
17
const S = `├───────────────────────────────┼──────────────────────┼──────────────────────┼
│ 2    BW200,            manual │ 0000:5e:00.0     Off │ Off               On │ DCU: ░░░░░░░░░░░░░░░░░░░░░░░░░   0% │`

func TestLine(t *testing.T) {
	t.Logf("%d", lipgloss.Width(S))
}
liming6's avatar
liming6 committed
18

liming6's avatar
liming6 committed
19
20
21
22
23
24
func TestHeader(t *testing.T) {
	m := ModelHeader{}
	cmd := m.Init()
	m.Update(cmd)
	fmt.Println(m.View())
}
liming6's avatar
liming6 committed
25
26
27
28
29
30
31
32
33
34

func TestAis(t *testing.T) {
	for i := 10; i < 180; i++ {
		str := genXAxis(i)
		if lipgloss.Width(str) != i {
			t.Error("error length")
		}
		fmt.Println(str)
	}
}
liming6's avatar
liming6 committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

func TestFormatStr(t *testing.T) {
	str := lipgloss.NewStyle().Foreground(lipgloss.Color("#2b95ffff")).SetString("hello world!").String()
	t.Logf("|%s|", FormatStr(str, 5, lipgloss.Left))
	t.Logf("|%s|", FormatStr(str, 5, lipgloss.Right))
	t.Logf("|%s|", FormatStr(str, 20, lipgloss.Left))
	t.Logf("|%s|", FormatStr(str, 20, lipgloss.Right))
}

func TestModel(t *testing.T) {
	m := NewModelMain(200, 100)
	m.Init()
	m.DCUInfo.Update(m.modelMsg)
	str := m.View()
	t.Log(str)
}
liming6's avatar
liming6 committed
51
52

func TestBinaryHeap(t *testing.T) {
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
	err := backend.Init()
	if err != nil {
		t.Error(err)
	}
	defer backend.Shutdown()
	main := NewModelMain(200, 60)
	c := main.Init()
	main.Update(c)
	main.View()
}

func TestSysloadInit(t *testing.T) {

	start := time.Now()
	sys := NewModelSysLoad(200)
	d := time.Since(start)
	t.Logf("%d ms", d.Milliseconds())
	start = time.Now()
	ts := sys.init()
	d = time.Since(start)
	t.Logf("%d ms", d.Milliseconds())
	for _, tt := range ts[1:] {
		t.Logf("%d ms", tt.Sub(ts[0]).Milliseconds())
	}
liming6's avatar
liming6 committed
77
}