mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
d84cfdbb0f
* Refactor: adds version column and fixes tests * Chore: adds version check when patching the library panel * Refactor: adds support for version in FrontEnd
99 lines
3.2 KiB
Go
99 lines
3.2 KiB
Go
package librarypanels
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCreateLibraryPanel(t *testing.T) {
|
|
scenarioWithLibraryPanel(t, "When an admin tries to create a library panel that already exists, it should fail",
|
|
func(t *testing.T, sc scenarioContext) {
|
|
command := getCreateCommand(sc.folder.Id, "Text - Library Panel")
|
|
resp := sc.service.createHandler(sc.reqContext, command)
|
|
require.Equal(t, 400, resp.Status())
|
|
})
|
|
|
|
scenarioWithLibraryPanel(t, "When an admin tries to create a library panel that does not exists, it should succeed",
|
|
func(t *testing.T, sc scenarioContext) {
|
|
var expected = libraryPanelResult{
|
|
Result: libraryPanel{
|
|
ID: 1,
|
|
OrgID: 1,
|
|
FolderID: 1,
|
|
UID: sc.initialResult.Result.UID,
|
|
Name: "Text - Library Panel",
|
|
Model: map[string]interface{}{
|
|
"datasource": "${DS_GDEV-TESTDATA}",
|
|
"id": float64(1),
|
|
"title": "Text - Library Panel",
|
|
"type": "text",
|
|
},
|
|
Version: 1,
|
|
Meta: LibraryPanelDTOMeta{
|
|
CanEdit: true,
|
|
ConnectedDashboards: 0,
|
|
Created: sc.initialResult.Result.Meta.Created,
|
|
Updated: sc.initialResult.Result.Meta.Updated,
|
|
CreatedBy: LibraryPanelDTOMetaUser{
|
|
ID: 1,
|
|
Name: "signed_in_user",
|
|
AvatarUrl: "/avatar/37524e1eb8b3e32850b57db0a19af93b",
|
|
},
|
|
UpdatedBy: LibraryPanelDTOMetaUser{
|
|
ID: 1,
|
|
Name: "signed_in_user",
|
|
AvatarUrl: "/avatar/37524e1eb8b3e32850b57db0a19af93b",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
if diff := cmp.Diff(expected, sc.initialResult, getCompareOptions()...); diff != "" {
|
|
t.Fatalf("Result mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
|
|
testScenario(t, "When an admin tries to create a library panel where name and panel title differ, it should update panel title",
|
|
func(t *testing.T, sc scenarioContext) {
|
|
command := getCreateCommand(1, "Library Panel Name")
|
|
resp := sc.service.createHandler(sc.reqContext, command)
|
|
var result = validateAndUnMarshalResponse(t, resp)
|
|
var expected = libraryPanelResult{
|
|
Result: libraryPanel{
|
|
ID: 1,
|
|
OrgID: 1,
|
|
FolderID: 1,
|
|
UID: result.Result.UID,
|
|
Name: "Library Panel Name",
|
|
Model: map[string]interface{}{
|
|
"datasource": "${DS_GDEV-TESTDATA}",
|
|
"id": float64(1),
|
|
"title": "Library Panel Name",
|
|
"type": "text",
|
|
},
|
|
Version: 1,
|
|
Meta: LibraryPanelDTOMeta{
|
|
CanEdit: true,
|
|
ConnectedDashboards: 0,
|
|
Created: result.Result.Meta.Created,
|
|
Updated: result.Result.Meta.Updated,
|
|
CreatedBy: LibraryPanelDTOMetaUser{
|
|
ID: 1,
|
|
Name: "signed_in_user",
|
|
AvatarUrl: "/avatar/37524e1eb8b3e32850b57db0a19af93b",
|
|
},
|
|
UpdatedBy: LibraryPanelDTOMetaUser{
|
|
ID: 1,
|
|
Name: "signed_in_user",
|
|
AvatarUrl: "/avatar/37524e1eb8b3e32850b57db0a19af93b",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
if diff := cmp.Diff(expected, result, getCompareOptions()...); diff != "" {
|
|
t.Fatalf("Result mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
}
|