aboutsummaryrefslogtreecommitdiff
path: root/client/menu_test.go
blob: 224b242aa04bd40018b6d43c22609a59744dbfaf (plain)
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
package client

import (
	"io/ioutil"
	"os"
	"reflect"
	"shell-game-launcher/config"
	"testing"
)

func TestDisplayMenu(t *testing.T) {
	realStdout := os.Stdout
	t.Cleanup(func() { os.Stdout = realStdout })
	r, w, _ := os.Pipe()
	os.Stdout = w

	// Complete menu
	state := State{
		config: &config.Config{
			Menus: map[string]config.Menu{
				"test": config.Menu{
					Banner:  "TEST TEST TEST",
					XOffset: 5,
					YOffset: 3,
					MenuEntries: []config.MenuEntry{
						config.MenuEntry{
							Key:    "q",
							Label:  "quit",
							Action: "quit",
						},
					},
				},
			},
		},
		currentMenu: "test",
		login:       "nil",
	}
	want := []byte("\033[2J" +
		"TEST TEST TEST\n" +
		"\n\n\n" +
		"     q) quit\n")
	state.displayMenu()
	// back to normal state
	w.Close()
	out, _ := ioutil.ReadAll(r)
	if !reflect.DeepEqual(out, want) {
		t.Fatalf("menu displayed incorrectly:\nwant:%+v\ngot: %+v", want, out)
	}
}