From cc346022cbb390961c50bdd3e36e036244bfef4d Mon Sep 17 00:00:00 2001 From: bashbunni Date: Fri, 10 Jan 2025 10:13:00 -0800 Subject: [PATCH] test(tree): add TestInheritedStyles for items added to existing Tree --- tree/testdata/TestInheritedStyles.golden | 12 +++++++++ tree/tree_test.go | 32 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tree/testdata/TestInheritedStyles.golden diff --git a/tree/testdata/TestInheritedStyles.golden b/tree/testdata/TestInheritedStyles.golden new file mode 100644 index 00000000..780caa73 --- /dev/null +++ b/tree/testdata/TestInheritedStyles.golden @@ -0,0 +1,12 @@ +⁜ Makeup +├── Glossier +│  ├── Apparel +│  │  ├── Pink Hoodie +│  │  ╰── Baseball Cap +│  ╰── Makeup +├── Fenty Beauty +│  ├── Gloss Bomb Universal Lip Luminizer +│  ╰── Hot Cheeks Velour Blushlighter +├── Nyx +├── Mac +╰── Milk \ No newline at end of file diff --git a/tree/tree_test.go b/tree/tree_test.go index 94fd0d9f..ad177a0a 100644 --- a/tree/tree_test.go +++ b/tree/tree_test.go @@ -426,6 +426,38 @@ func TestRootStyle(t *testing.T) { golden.RequireEqual(t, []byte(tree.String())) } +func TestInheritedStyles(t *testing.T) { + enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("63")).MarginRight(1) + rootStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("35")) + itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("212")) + + tr := tree. + Root("⁜ Makeup"). + Child( + "Glossier", + "Fenty Beauty", + tree.New().Child( + "Gloss Bomb Universal Lip Luminizer", + "Hot Cheeks Velour Blushlighter", + ), + "Nyx", + "Mac", + "Milk", + ). + Enumerator(tree.RoundedEnumerator). + EnumeratorStyle(enumeratorStyle). + RootStyle(rootStyle). + ItemStyle(itemStyle) + // Add a Tree as a Child of "Glossier" + tr.Replace(0, tr.Children().At(0).Child( + tree.Root("Apparel").Child("Pink Hoodie", "Baseball Cap"), + )) + + // Add a Leaf as a Child of "Glossier" + tr.Children().At(0).Child("Makeup") + golden.RequireEqual(t, []byte(tr.String())) +} + func TestAt(t *testing.T) { data := tree.NewStringData("Foo", "Bar")