-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent_test.go
More file actions
51 lines (43 loc) · 1.13 KB
/
component_test.go
File metadata and controls
51 lines (43 loc) · 1.13 KB
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
package uiok
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type testComponent struct {
containerInit string
containerEnd string
partial string
}
func newTestComponent() *testComponent {
c := &testComponent{
containerInit: "<div>",
containerEnd: "</div>",
partial: "<div>Initial Partial Content</div>",
}
return c
}
func (c *testComponent) Change(context.Context) error {
return nil
}
func (c *testComponent) Render() ([]byte, error) {
partial, _ := c.Partial()
return fmt.Appendf(nil, "%s%s%s",
c.containerInit, string(partial), c.containerEnd), nil
}
func (c *testComponent) Partial() ([]byte, error) {
return []byte(c.partial), nil
}
func TestComponent(t *testing.T) {
t.Run("Should render and provide a parcial", func(t *testing.T) {
testComp := newTestComponent()
expectedRendered := []byte(
"<div><div>Initial Partial Content</div></div>")
rendered, _ := testComp.Render()
assert.Equal(t, expectedRendered, rendered)
expectedPartial := []byte("<div>Initial Partial Content</div>")
partial, _ := testComp.Partial()
assert.Equal(t, expectedPartial, partial)
})
}