File size: 3,187 Bytes
530729e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package common

import (
	"fmt"
	"net/http"

	"github.com/GoAdminGroup/go-admin/modules/config"
	"github.com/GoAdminGroup/go-admin/modules/language"
	"github.com/GoAdminGroup/go-admin/plugins/admin/modules/constant"
	"github.com/GoAdminGroup/go-admin/plugins/admin/modules/form"
	"github.com/gavv/httpexpect"
)

func menuTest(e *httpexpect.Expect, sesID *http.Cookie) {

	fmt.Println()
	printlnWithColor("Menu", "blue")
	fmt.Println("============================")

	// show

	printlnWithColor("show", "green")
	formBody := e.GET(config.Url("/menu")).
		WithCookie(sesID.Name, sesID.Value).
		Expect().
		Status(200).
		Body().Contains(language.Get("menus manage"))

	token := reg.FindStringSubmatch(formBody.Raw())

	// new menu tester

	printlnWithColor("new menu test", "green")
	res := e.POST(config.Url("/menu/new")).
		WithCookie(sesID.Name, sesID.Value).
		WithMultipart().
		WithFormField("roles[]", "1").
		WithForm(map[string]interface{}{
			"parent_id":      0,
			"title":          "test menu",
			"header":         "",
			"icon":           "fa-angellist",
			"uri":            "/example/test",
			form.PreviousKey: "/admin/menu",
			form.TokenKey:    token[1],
		}).Expect().Status(200)
	res.Header("X-Pjax-Url").Contains(config.Url("/menu"))
	res.Body().Contains("test menu").Contains("/example/test")

	// show form: without id

	//printlnWithColor("show form: without id", "green")
	//e.GET(config.Url("/menu/edit/show")).
	//	WithCookie(sesID.Name, sesID.Value).
	//	Expect().Status(200).Body().Contains(errors.WrongID)

	// show form

	printlnWithColor("show form", "green")
	formBody = e.GET(config.Url("/menu/edit/show")).
		WithQuery(constant.EditPKKey, "3").
		WithCookie(sesID.Name, sesID.Value).
		Expect().Status(200).Body()

	token = reg.FindStringSubmatch(formBody.Raw())

	// edit form

	printlnWithColor("edit form", "green")
	res = e.POST(config.Url("/menu/edit")).
		WithCookie(sesID.Name, sesID.Value).
		WithMultipart().
		WithFormField("roles[]", "1").
		WithForm(map[string]interface{}{
			"parent_id":      0,
			"title":          "test2 menu",
			"header":         "",
			"icon":           "fa-angellist",
			"uri":            "/example/test",
			form.PreviousKey: "/admin/menu",
			form.TokenKey:    token[1],
			"id":             "3",
		}).Expect().Status(200)
	res.Header("X-Pjax-Url").Contains(config.Url("/menu"))
	res.Body().Contains("test2 menu").Contains("/example/test")

	// new tester2

	printlnWithColor("new tester2", "green")
	e.POST(config.Url("/menu/new")).
		WithCookie(sesID.Name, sesID.Value).
		WithMultipart().
		WithFormField("roles[]", "1").
		WithForm(map[string]interface{}{
			"parent_id":      0,
			"title":          "test2 menu",
			"header":         "",
			"icon":           "fa-angellist",
			"uri":            "/example/test2",
			form.PreviousKey: "/admin/menu",
			form.TokenKey:    token[1],
		}).Expect().Status(200)

	// delete tester2

	printlnWithColor("delete menu tester2", "green")
	e.POST(config.Url("/menu/delete")).
		WithQuery("id", "9").
		WithCookie(sesID.Name, sesID.Value).
		WithMultipart().
		Expect().Status(200).JSON().Object().
		ValueEqual("code", 200).
		ValueEqual("msg", "delete succeed")
}