rastrillo / fiesta Public

Clone
git clone https://amadan.net/rastrillo/fiesta

Plain git — no account needed to clone.

Download

Download this file

1package check
2
3import (
4 "regexp"
5 "strings"
6 "testing"
7)
8
9// The button sample is the set that behaves differently, not every
10// combination: four variants at the default size, the three sizes on
11// primary, each labelled with its size, a link wearing the look, a
12// full-width one and a disabled one. The busy state is form-foot's idle/working pair, so it is not
13// drawn twice. A combination missing here is a size or variant a
14// reader of the gallery never sees on a button.
15func TestTheButtonSampleShowsEachDistinctBehaviour(t *testing.T) {
16 sample := idiomMarkup(t, "button")
17 for _, want := range []string{
18 `<button rst-btn type="button">`,
19 `<button rst-btn="primary" type="button">`,
20 `<button rst-btn="ghost" type="button">`,
21 `<button rst-btn="danger" type="button">`,
22 `<button rst-btn="primary sm" type="button">`,
23 `<button rst-btn="primary lg" type="button">`,
24 `<a rst-btn href="`,
25 `<button rst-btn="primary block" type="button">`,
26 `<button rst-btn type="button" disabled>`,
27 } {
28 if !strings.Contains(sample, want) {
29 t.Errorf("the button sample has no %s", want)
30 }
31 }
32 if n := len(regexp.MustCompile(`\srst-btn[\s=>]`).FindAllString(sample, -1)); n != 10 {
33 t.Errorf("the button sample draws %d buttons, want the 10 that behave differently", n)
34 }
35 // The size row names each size on its button, small to large, so a
36 // reader comparing them does not have to guess which is which: the
37 // row used to be three buttons all reading "Save".
38 const sizes = `<p><button rst-btn="primary sm" type="button">Small</button> <button rst-btn="primary" type="button">Default</button> <button rst-btn="primary lg" type="button">Large</button> <a rst-btn href="/orders">View orders</a></p>`
39 if !strings.Contains(sample, sizes) {
40 t.Errorf("the button sample has no size row %s", sizes)
41 }
42 if strings.Contains(sample, "aria-busy") || strings.Contains(sample, "rst-spin") {
43 t.Error("the button sample draws the busy state, which form-foot's pair already shows")
44 }
45}
46