about summary refs log tree commit diff stats
path: root/html/attributes_test.go
diff options
context:
space:
mode:
authorKen Powers2024-10-30 10:06:20 -0400
committerGitHub2024-10-30 15:06:20 +0100
commit900ef87aac4f4c6c0be49faeb1fc7c190c17a482 (patch)
tree62b8c2c71512362e8a0edbe09a9159e3a119e20f /html/attributes_test.go
parent2e44d495769421423921bfcb06ebfc53f8370dd3 (diff)
downloadgomponents-900ef87aac4f4c6c0be49faeb1fc7c190c17a482.tar.lz
gomponents-900ef87aac4f4c6c0be49faeb1fc7c190c17a482.tar.zst
gomponents-900ef87aac4f4c6c0be49faeb1fc7c190c17a482.zip
Add popover attributes (#236)
This PR adds popover attributes as detailed here:
https://developer.mozilla.org/en-US/docs/Web/API/Popover_API/Using

---------

Co-authored-by: Markus Wüstenberg <markus@maragu.dk>
Diffstat (limited to 'html/attributes_test.go')
-rw-r--r--html/attributes_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/html/attributes_test.go b/html/attributes_test.go
index 67b98f4..cfb64b5 100644
--- a/html/attributes_test.go
+++ b/html/attributes_test.go
@@ -78,6 +78,8 @@ func TestSimpleAttributes(t *testing.T) {
 		{Name: "name", Func: Name},
 		{Name: "pattern", Func: Pattern},
 		{Name: "placeholder", Func: Placeholder},
+		{Name: "popovertarget", Func: PopoverTarget},
+		{Name: "popovertargetaction", Func: PopoverTargetAction},
 		{Name: "poster", Func: Poster},
 		{Name: "preload", Func: Preload},
 		{Name: "rel", Func: Rel},
@@ -107,6 +109,37 @@ func TestSimpleAttributes(t *testing.T) {
 	}
 }
 
+func TestVariadicAttributes(t *testing.T) {
+	tests := []struct {
+		Name string
+		Func func(...string) g.Node
+	}{
+		{Name: "popover", Func: Popover},
+	}
+
+	for _, test := range tests {
+		t.Run(test.Name + "(no args)", func(t *testing.T) {
+			n := g.El("div", test.Func())
+			assert.Equal(t, fmt.Sprintf(`<div %v></div>`, test.Name), n)
+		})
+
+		t.Run(test.Name +"(one arg)", func(t *testing.T) {
+			n := g.El("div", test.Func("hat"))
+			assert.Equal(t, fmt.Sprintf(`<div %v="hat"></div>`, test.Name), n)
+		})
+
+		t.Run(test.Name + "(two args panics)", func(t *testing.T) {
+			defer func() {
+				if r := recover(); r == nil {
+					t.Errorf("expected a panic")
+				}
+			}()
+			n := g.El("div", test.Func("hat", "party"))
+			assert.Equal(t, "unreachable", n)
+		})
+	}
+}
+
 func TestAria(t *testing.T) {
 	t.Run("returns an attribute which name is prefixed with aria-", func(t *testing.T) {
 		n := Aria("selected", "true")