File: radio_test.go

package info (click to toggle)
golang-github-gcla-gowid 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,456 kB
  • sloc: makefile: 4
file content (81 lines) | stat: -rw-r--r-- 2,219 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2019-2022 Graham Clark. All rights reserved.  Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.

package radio

import (
	"testing"

	"github.com/gcla/gowid"
	"github.com/gcla/gowid/gwtest"
	"github.com/gcla/gowid/widgets/columns"
	"github.com/stretchr/testify/assert"
)

//======================================================================

func TestRadioButton1(t *testing.T) {
	rbgroup := make([]IWidget, 0)
	rb1 := New(&rbgroup)
	rb2 := New(&rbgroup)
	rb3 := New(&rbgroup)

	assert.Equal(t, rb1.IsChecked(), true)
	assert.Equal(t, rb2.IsChecked(), false)
	assert.Equal(t, rb3.IsChecked(), false)

	c1 := rb1.Render(gowid.RenderFixed{}, gowid.Focused, gwtest.D)
	assert.Equal(t, c1.String(), "(X)")
	c2 := rb2.Render(gowid.RenderFixed{}, gowid.Focused, gwtest.D)
	assert.Equal(t, c2.String(), "( )")

	ct1 := &RadioButtonTester{State: true}
	assert.Equal(t, ct1.State, true)
	rb1.OnClick(ct1)
	ct2 := &RadioButtonTester{State: false}
	assert.Equal(t, ct2.State, false)
	rb2.OnClick(ct2)

	rb2.Click(gwtest.D)
	assert.Equal(t, rb1.IsChecked(), false)
	assert.Equal(t, ct1.State, false)
	assert.Equal(t, rb2.IsChecked(), true)
	assert.Equal(t, ct2.State, true)
	assert.Equal(t, rb3.IsChecked(), false)

	fixed := gowid.RenderFixed{}

	ccols := []gowid.IContainerWidget{
		&gowid.ContainerWidget{rb1, fixed},
		&gowid.ContainerWidget{rb2, fixed},
		&gowid.ContainerWidget{rb3, fixed},
	}

	cols := columns.New(ccols)

	c3 := cols.Render(gowid.RenderFixed{}, gowid.Focused, gwtest.D)
	assert.Equal(t, c3.String(), "( )(X)( )")
	cpos := c3.CursorCoords()
	cx, cy := cpos.X, cpos.Y
	assert.Equal(t, c3.CursorEnabled(), true)
	assert.Equal(t, cx, 1)
	assert.Equal(t, cy, 0)
	assert.Equal(t, c3.String(), "( )(X)( )")

	ev := gwtest.CursorRight()

	cols.UserInput(ev, gowid.RenderFixed{}, gowid.Focused, gwtest.D)
	c3 = cols.Render(gowid.RenderFixed{}, gowid.Focused, gwtest.D)
	cx = c3.CursorCoords().X

	assert.Equal(t, cx, 4)

	gwtest.RenderBoxManyTimes(t, cols, 0, 20, 0, 20)
	gwtest.RenderFlowManyTimes(t, cols, 0, 20)
}

//======================================================================
// Local Variables:
// mode: Go
// fill-column: 110
// End: