grafana/pkg/services/navtree/models_test.go
Torkel Ödegaard e31cb93ec0
NavTree: Make it possible to configure where in nav tree plugins live (#55484)
* NewIA: Plugin nav config

* progress

* Progress

* Things are working

* Add monitoring node

* Add alerts and incidents

* added experiment with standalone page

* Refactoring by adding a type for navtree root

* First test working

* More tests

* more tests

* Progress on richer config and sorting

* Sort weight working

* Path config

* Improving logic for not including admin or cfg nodes, making it the last step so that enterprise can add admin nodes without having to worry about the section not existing

* fixed index routes

* removed file

* Fixes

* Fixing tests

* Fixing more tests and adding support for weight config

* Updates

* Remove unused fake

* More fixes

* Minor tweak

* Minor fix

* Can now control position using sortweight even when existing items have no sortweight

* Added tests for frontend standalone page logic

* more tests

* Remove unused fake and fixed lint issue

* Moving reading settings to navtree impl package

* remove nav_id setting prefix

* Remove old test file

* Fix trailing newline

* Fixed bug with adding nil node

* fixing lint issue

* remove some code we have to rethink

* move read settings to PrivideService and switch to util.SplitString
2022-09-28 08:29:35 +02:00

90 lines
2.1 KiB
Go

package navtree
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestNavTreeRoot(t *testing.T) {
t.Run("Should remove empty admin and server admin sections", func(t *testing.T) {
treeRoot := NavTreeRoot{
Children: []*NavLink{
{Id: NavIDCfg},
{Id: NavIDAdmin},
},
}
treeRoot.RemoveEmptySectionsAndApplyNewInformationArchitecture(false)
require.Equal(t, 0, len(treeRoot.Children))
})
t.Run("Should not remove admin sections when they have children", func(t *testing.T) {
treeRoot := NavTreeRoot{
Children: []*NavLink{
{Id: NavIDCfg, Children: []*NavLink{{Id: "child"}}},
{Id: NavIDAdmin, Children: []*NavLink{{Id: "child"}}},
},
}
treeRoot.RemoveEmptySectionsAndApplyNewInformationArchitecture(false)
require.Equal(t, 2, len(treeRoot.Children))
})
t.Run("Should move admin section into cfg and rename when topnav is enabled", func(t *testing.T) {
treeRoot := NavTreeRoot{
Children: []*NavLink{
{Id: NavIDCfg},
{Id: NavIDAdmin, Children: []*NavLink{{Id: "child"}}},
},
}
treeRoot.RemoveEmptySectionsAndApplyNewInformationArchitecture(true)
require.Equal(t, "Administration", treeRoot.Children[0].Text)
require.Equal(t, NavIDAdmin, treeRoot.Children[0].Children[0].Id)
})
t.Run("Should move reports into Dashboards", func(t *testing.T) {
treeRoot := NavTreeRoot{
Children: []*NavLink{
{Id: NavIDDashboards},
{Id: NavIDReporting},
},
}
treeRoot.RemoveEmptySectionsAndApplyNewInformationArchitecture(true)
require.Equal(t, NavIDReporting, treeRoot.Children[0].Children[0].Id)
})
t.Run("Sorting by index", func(t *testing.T) {
treeRoot := NavTreeRoot{
Children: []*NavLink{
{Id: "1"},
{Id: "2"},
{Id: "3"},
},
}
treeRoot.Sort()
require.Equal(t, "1", treeRoot.Children[0].Id)
require.Equal(t, "3", treeRoot.Children[2].Id)
})
t.Run("Sorting by index and SortWeight", func(t *testing.T) {
treeRoot := NavTreeRoot{
Children: []*NavLink{
{Id: "1"},
{Id: "2"},
{Id: "3"},
{Id: "4", SortWeight: 1},
},
}
treeRoot.Sort()
require.Equal(t, "1", treeRoot.Children[0].Id)
require.Equal(t, "4", treeRoot.Children[1].Id)
})
}