mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 12:14:08 -06:00
82892331c1
* Remove bus from signup and playlist api * Remove bus from playlist play
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package search
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSearch_SortedResults(t *testing.T) {
|
|
bus.AddHandler("test", func(_ context.Context, query *FindPersistedDashboardsQuery) error {
|
|
query.Result = HitList{
|
|
&Hit{ID: 16, Title: "CCAA", Type: "dash-db", Tags: []string{"BB", "AA"}},
|
|
&Hit{ID: 10, Title: "AABB", Type: "dash-db", Tags: []string{"CC", "AA"}},
|
|
&Hit{ID: 15, Title: "BBAA", Type: "dash-db", Tags: []string{"EE", "AA", "BB"}},
|
|
&Hit{ID: 25, Title: "bbAAa", Type: "dash-db", Tags: []string{"EE", "AA", "BB"}},
|
|
&Hit{ID: 17, Title: "FOLDER", Type: "dash-folder"},
|
|
}
|
|
return nil
|
|
})
|
|
|
|
bus.AddHandler("test", func(_ context.Context, query *models.GetUserStarsQuery) error {
|
|
query.Result = map[int64]bool{10: true, 12: true}
|
|
return nil
|
|
})
|
|
|
|
bus.AddHandler("test", func(_ context.Context, query *models.GetSignedInUserQuery) error {
|
|
query.Result = &models.SignedInUser{IsGrafanaAdmin: true}
|
|
return nil
|
|
})
|
|
|
|
svc := &SearchService{}
|
|
|
|
query := &Query{
|
|
Limit: 2000,
|
|
SignedInUser: &models.SignedInUser{
|
|
IsGrafanaAdmin: true,
|
|
},
|
|
}
|
|
|
|
err := svc.SearchHandler(context.Background(), query)
|
|
require.Nil(t, err)
|
|
|
|
// Assert results are sorted.
|
|
assert.Equal(t, "FOLDER", query.Result[0].Title)
|
|
assert.Equal(t, "AABB", query.Result[1].Title)
|
|
assert.Equal(t, "BBAA", query.Result[2].Title)
|
|
assert.Equal(t, "bbAAa", query.Result[3].Title)
|
|
assert.Equal(t, "CCAA", query.Result[4].Title)
|
|
|
|
// Assert tags are sorted.
|
|
assert.Equal(t, "AA", query.Result[3].Tags[0])
|
|
assert.Equal(t, "BB", query.Result[3].Tags[1])
|
|
assert.Equal(t, "EE", query.Result[3].Tags[2])
|
|
}
|