56 lines
2.3 KiB
Go
56 lines
2.3 KiB
Go
package components_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"git.sapphic.engineer/roleypoly/v4/templates/components"
|
|
"git.sapphic.engineer/roleypoly/v4/templates/templatetesting"
|
|
"git.sapphic.engineer/roleypoly/v4/types/fixtures"
|
|
"git.sapphic.engineer/roleypoly/v4/utils"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRoleTemplate(t *testing.T) {
|
|
c := &fixtures.CategoryMulti
|
|
r := &fixtures.RoleWithDarkColor
|
|
data := components.Role(c, r, true)
|
|
html := templatetesting.Template(t, "components/role", data)
|
|
assert.Contains(t, html, "--role-color: #a20000;", "role color is set")
|
|
assert.Contains(t, html, `type="checkbox"`, "multi has input type=checkbox")
|
|
assert.Contains(t, html, fmt.Sprintf("--contrast-color: %s;", utils.RgbToString(utils.AltColor(162, 0, 0))), "contrast color is set")
|
|
assert.Contains(t, html, fmt.Sprintf(`id="%s"`, utils.RoleInputID(c, r)), "input has ID attr")
|
|
assert.Contains(t, html, fmt.Sprintf(`for="%s"`, utils.RoleInputID(c, r)), "label has for attr")
|
|
assert.NotContains(t, html, fmt.Sprintf(`name="%s"`, utils.RoleInputName(c)), "multi has no name attr")
|
|
// TODO: selected?
|
|
|
|
c = &fixtures.CategorySingle
|
|
r = &fixtures.RoleWithLightColor
|
|
data = components.Role(c, r, false)
|
|
html = templatetesting.Template(t, "components/role", data)
|
|
assert.Contains(t, html, `type="radio"`, "single has input type=radio")
|
|
assert.Contains(t, html, fmt.Sprintf("--contrast-color: %s;", utils.RgbToString(utils.AltColor(0xff, 0xaa, 0x88))), "contrast color")
|
|
assert.Contains(t, html, fmt.Sprintf(`name="%s"`, utils.RoleInputName(c)), "single has name attr")
|
|
}
|
|
|
|
func TestRole(t *testing.T) {
|
|
r := components.Role(&fixtures.CategoryMulti, &fixtures.RoleWithDarkColor, true)
|
|
assert.Equal(t, fixtures.RoleWithDarkColor.ID, r.ID)
|
|
assert.Equal(t, fixtures.RoleWithDarkColor.Name, r.Name)
|
|
assert.Equal(t, components.InputCheckbox, r.InputType)
|
|
assert.Equal(t, "#a20000", r.Colors.Main)
|
|
assert.True(t, r.Selected)
|
|
|
|
r = components.Role(&fixtures.CategorySingle, &fixtures.RoleWithDarkColor, false)
|
|
assert.Equal(t, components.InputRadio, r.InputType)
|
|
assert.False(t, r.Selected)
|
|
|
|
r = components.Role(&fixtures.CategorySingle, &fixtures.RoleWithLightColor, true)
|
|
assert.True(t, r.Selected)
|
|
}
|
|
|
|
func TestNewRoleColors(t *testing.T) {
|
|
c := components.NewRoleColors(0xa20000)
|
|
assert.Equal(t, "#a20000", c.Main)
|
|
assert.Equal(t, "#ffd8d8", c.Alt)
|
|
}
|