-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle_test.go
51 lines (42 loc) · 2.84 KB
/
toggle_test.go
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 carbon
import (
"bytes"
"math/rand"
"testing"
)
func TestToggle(t *testing.T) {
rand.Seed(1)
expected := `<div bx--form-item><input role="switch" type="checkbox" class="bx--toggle-input" id="ccs-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLS" /><label for="ccs-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLS" aria-label="Push notifications" class="bx--toggle-input__label"><span>Push notifications</span><span class="bx--toggle__switch"><span aria-hidden="true" class="bx--toggle__text--off">Off</span><span aria-hidden="true" class="bx--toggle__text--on">On</span></span></label></div>`
b := &bytes.Buffer{}
Toggle().LabelText("Push notifications").Render(b)
if b.String() != expected {
t.Errorf("got %s, want %s", b.String(), expected)
}
}
func TestToggleOn(t *testing.T) {
rand.Seed(1)
expected := `<div bx--form-item><input role="switch" type="checkbox" class="bx--toggle-input" id="ccs-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLS" checked /><label for="ccs-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLS" aria-label="Push notifications" class="bx--toggle-input__label"><span>Push notifications</span><span class="bx--toggle__switch"><span aria-hidden="true" class="bx--toggle__text--off">Off</span><span aria-hidden="true" class="bx--toggle__text--on">On</span></span></label></div>`
b := &bytes.Buffer{}
Toggle().LabelText("Push notifications").Toggled(true).Render(b)
if b.String() != expected {
t.Errorf("got %s, want %s", b.String(), expected)
}
}
func TestToggleHiddenLabel(t *testing.T) {
rand.Seed(1)
expected := `<div bx--form-item><input role="switch" type="checkbox" class="bx--toggle-input" id="ccs-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLS" /><label for="ccs-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLS" aria-label="Push notifications" class="bx--toggle-input__label"><span class="bx--visually-hidden">Push notifications</span><span class="bx--toggle__switch"><span aria-hidden="true" class="bx--toggle__text--off">Off</span><span aria-hidden="true" class="bx--toggle__text--on">On</span></span></label></div>`
b := &bytes.Buffer{}
Toggle().LabelText("Push notifications").HideLabel(true).Render(b)
if b.String() != expected {
t.Errorf("got %s, want %s", b.String(), expected)
}
}
func TestToggleDisabled(t *testing.T) {
rand.Seed(1)
expected := `<div bx--form-item><input role="switch" type="checkbox" class="bx--toggle-input" id="ccs-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLS" disabled /><label for="ccs-XVlBzgbaiCMRAjWwhTHctcuAxhxKQFDaFpLS" aria-label="Push notifications" class="bx--toggle-input__label"><span>Push notifications</span><span class="bx--toggle__switch"><span aria-hidden="true" class="bx--toggle__text--off">Off</span><span aria-hidden="true" class="bx--toggle__text--on">On</span></span></label></div>`
b := &bytes.Buffer{}
Toggle().LabelText("Push notifications").Disabled(true).Render(b)
if b.String() != expected {
t.Errorf("got %s, want %s", b.String(), expected)
}
}