40 lines
1.7 KiB
Go
40 lines
1.7 KiB
Go
package components_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"git.sapphic.engineer/roleypoly/v4/presentation"
|
|
"git.sapphic.engineer/roleypoly/v4/templates/templatetesting"
|
|
"git.sapphic.engineer/roleypoly/v4/types"
|
|
"git.sapphic.engineer/roleypoly/v4/types/fixtures"
|
|
"git.sapphic.engineer/roleypoly/v4/utils"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func renderRole(t *testing.T, c *types.Category, r *types.Role, s bool) string {
|
|
data := presentation.Role(c, r, s)
|
|
return templatetesting.Template(t, "components/role", data)
|
|
}
|
|
|
|
func TestRole(t *testing.T) {
|
|
c := &fixtures.CategoryMulti
|
|
r := &fixtures.RoleWithDarkColor
|
|
html := renderRole(t, c, r, false)
|
|
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
|
|
html = renderRole(t, c, r, true)
|
|
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")
|
|
}
|
|
|
|
// TODO: these can probably be string utils that are injected as functions into template
|