v4/templates/components/category_test.go

43 lines
1.7 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"
"git.sapphic.engineer/roleypoly/v4/types/fixtures"
"git.sapphic.engineer/roleypoly/v4/utils"
"github.com/stretchr/testify/assert"
)
func TestCategoryTemplate(t *testing.T) {
c := components.CategoryTemplateData{
ID: "123",
Name: "Multi",
Type: types.CategoryMultiple,
Roles: []components.RoleTemplateData{
components.Role(&fixtures.CategoryMulti, &fixtures.RoleWithDarkColor, true, true),
},
}
html := templatetesting.Template(t, "components/category", c)
assert.Contains(t, html, "<h3>Multi</h3>", "has header")
assert.Contains(t, html, `data-testid="category-123"`, "has testid")
assert.NotContains(t, html, `<input type="radio"`, "has no radios")
assert.NotContains(t, html, fmt.Sprintf(`id="%s"`, utils.RoleInputID("123", fixtures.RoleWithDarkColor.ID)), "has the role")
c = components.CategoryTemplateData{
ID: "456",
Name: "Single",
Roles: []components.RoleTemplateData{
components.Role(&fixtures.CategorySingle, &fixtures.RoleWithDarkColor, true, true),
},
}
html = templatetesting.Template(t, "components/category", c)
assert.Contains(t, html, "<h3>Single</h3>", "has header")
assert.Contains(t, html, `data-testid="category-456"`, "has testid")
assert.NotContains(t, html, `<input type="checkbox"`, "has no checkboxes")
assert.NotContains(t, html, fmt.Sprintf(`id="%s"`, utils.RoleInputID("456", "456")), "has no checkboxes")
assert.NotContains(t, html, fmt.Sprintf(`id="%s"`, utils.RoleInputID("456", fixtures.RoleWithDarkColor.ID)), "has the role")
}