-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentswitcher_test.go
59 lines (50 loc) · 2.83 KB
/
contentswitcher_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
52
53
54
55
56
57
58
59
package carbon
import (
"bytes"
"testing"
)
func TestContentSwitcher(t *testing.T) {
expected := `<div role="tablist" class="bx--content-switcher"><button type="button" role="tab" tabindex="0" aria-selected class="bx--content-switcher-btn bx--content-switcher--selected"><span class="bx--content-switcher__label">Latest news</span></button><button type="button" role="tab" tabindex="-1" class="bx--content-switcher-btn"><span class="bx--content-switcher__label">Trending</span></button></div>`
b := &bytes.Buffer{}
ContentSwitcher(
Switch("Latest news"),
Switch("Trending"),
).Render(b)
if b.String() != expected {
t.Errorf("got %s, want %s", b.String(), expected)
}
}
func TestContentInitialSelectedIndex(t *testing.T) {
expected := `<div role="tablist" class="bx--content-switcher"><button type="button" role="tab" tabindex="-1" class="bx--content-switcher-btn"><span class="bx--content-switcher__label">Latest news</span></button><button type="button" role="tab" tabindex="0" aria-selected class="bx--content-switcher-btn bx--content-switcher--selected"><span class="bx--content-switcher__label">Trending</span></button><button type="button" role="tab" tabindex="-1" class="bx--content-switcher-btn"><span class="bx--content-switcher__label">Recommended</span></button></div>`
b := &bytes.Buffer{}
ContentSwitcher(
Switch("Latest news"),
Switch("Trending"),
Switch("Recommended"),
).SelectedIndex(1).Render(b)
if b.String() != expected {
t.Errorf("got %s, want %s", b.String(), expected)
}
}
func TestContentSizeXL(t *testing.T) {
expected := `<div role="tablist" class="bx--content-switcher bx--content-switcher--xl"><button type="button" role="tab" tabindex="0" aria-selected class="bx--content-switcher-btn bx--content-switcher--selected"><span class="bx--content-switcher__label">Latest news</span></button><button type="button" role="tab" tabindex="-1" class="bx--content-switcher-btn"><span class="bx--content-switcher__label">Trending</span></button></div>`
b := &bytes.Buffer{}
ContentSwitcher(
Switch("Latest news"),
Switch("Trending"),
).Size("xl").Render(b)
if b.String() != expected {
t.Errorf("got %s, want %s", b.String(), expected)
}
}
func TestContentSwitcherDisabled(t *testing.T) {
expected := `<div role="tablist" class="bx--content-switcher"><button type="button" role="tab" tabindex="0" aria-selected disabled class="bx--content-switcher-btn bx--content-switcher--selected"><span class="bx--content-switcher__label">Latest news</span></button><button type="button" role="tab" tabindex="-1" disabled class="bx--content-switcher-btn"><span class="bx--content-switcher__label">Trending</span></button></div>`
b := &bytes.Buffer{}
ContentSwitcher(
Switch("Latest news").Disabled(true),
Switch("Trending").Disabled(true),
).Render(b)
if b.String() != expected {
t.Errorf("got %s, want %s", b.String(), expected)
}
}