Passed
Pull Request — main (#166)
by Yume
02:23
created

app/v2/views/layout/base.layout_test.go   A

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 37
dl 0
loc 58
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B layout_test.TestBase 0 38 7
1
package layout_test
2
3
import (
4
	"context"
5
	"io"
6
	"testing"
7
8
	"github.com/PuerkitoBio/goquery"
9
	"github.com/memnix/memnix-rest/app/v2/views/layout"
10
)
11
12
type BaseArgs struct {
13
	title         string
14
	username      string
15
	errMsgs       []string
16
	sucMsgs       []string
17
	fromProtected bool
18
	isError       bool
19
}
20
21
func TestBase(t *testing.T) {
22
	r, w := io.Pipe()
23
	args := BaseArgs{
24
		title:         "Memnix",
25
		username:      "",
26
		fromProtected: false,
27
		isError:       false,
28
		errMsgs:       nil,
29
		sucMsgs:       nil,
30
	}
31
	go func() {
32
		_ = layout.Base(args.title, args.username, args.fromProtected, args.isError, args.errMsgs, args.sucMsgs).Render(context.Background(), w)
33
		_ = w.Close()
34
	}()
35
36
	doc, err := goquery.NewDocumentFromReader(r)
37
	if err != nil {
38
		t.Fatalf("Error reading document: %s", err)
39
	}
40
41
	// Assert that the title exists
42
	if doc.Find("title").Text() != args.title {
43
		t.Errorf("Expected to find a title")
44
	}
45
46
	// Assert that the header exists
47
	if doc.Find("header").Length() != 1 {
48
		t.Errorf("Expected to find a header")
49
	}
50
51
	// Assert that the footer exists
52
	if doc.Find("footer").Length() != 1 {
53
		t.Errorf("Expected to find a footer")
54
	}
55
56
	// Assert that the main exists
57
	if doc.Find("main").Length() != 1 {
58
		t.Errorf("Expected to find a main")
59
	}
60
}
61