mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
LibraryPanels: Fixes error when importing plugin dashboard (#34557)
This commit is contained in:
@@ -572,106 +572,6 @@ func TestConnectLibraryPanelsForDashboard(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestImportDashboard(t *testing.T) {
|
||||
scenarioWithLibraryPanel(t, "When an admin tries to import a dashboard with a library panel, it should connect the two",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
importedJSON := map[string]interface{}{
|
||||
"panels": []interface{}{},
|
||||
}
|
||||
importedDashboard := models.Dashboard{
|
||||
Title: "Dummy dash that simulates an imported dash",
|
||||
Data: simplejson.NewFromAny(importedJSON),
|
||||
}
|
||||
importedDashInDB := createDashboard(t, sc.sqlStore, sc.user, &importedDashboard, sc.folder.Id)
|
||||
elements, err := sc.elementService.GetElementsForDashboard(sc.reqContext, importedDashInDB.Id)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, elements, 0)
|
||||
|
||||
dashJSON := map[string]interface{}{
|
||||
"title": "Testing ImportDashboard",
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": int64(1),
|
||||
"gridPos": map[string]interface{}{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"id": int64(2),
|
||||
"gridPos": map[string]interface{}{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 6,
|
||||
"y": 0,
|
||||
},
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"libraryPanel": map[string]interface{}{
|
||||
"uid": sc.initialResult.Result.UID,
|
||||
"name": sc.initialResult.Result.Name,
|
||||
},
|
||||
"title": "Text - Library Panel",
|
||||
"type": "text",
|
||||
},
|
||||
},
|
||||
}
|
||||
dash := simplejson.NewFromAny(dashJSON)
|
||||
err = sc.service.ImportDashboard(sc.reqContext, dash, importedDashInDB.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
elements, err = sc.elementService.GetElementsForDashboard(sc.reqContext, importedDashInDB.Id)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, elements, 1)
|
||||
require.Equal(t, sc.initialResult.Result.UID, elements[sc.initialResult.Result.UID].UID)
|
||||
})
|
||||
|
||||
scenarioWithLibraryPanel(t, "When an admin tries to import a dashboard with a library panel without uid, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
importedJSON := map[string]interface{}{
|
||||
"panels": []interface{}{},
|
||||
}
|
||||
importedDashboard := models.Dashboard{
|
||||
Title: "Dummy dash that simulates an imported dash",
|
||||
Data: simplejson.NewFromAny(importedJSON),
|
||||
}
|
||||
importedDashInDB := createDashboard(t, sc.sqlStore, sc.user, &importedDashboard, sc.folder.Id)
|
||||
|
||||
dashJSON := map[string]interface{}{
|
||||
"panels": []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": int64(1),
|
||||
"gridPos": map[string]interface{}{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"id": int64(2),
|
||||
"gridPos": map[string]interface{}{
|
||||
"h": 6,
|
||||
"w": 6,
|
||||
"x": 6,
|
||||
"y": 0,
|
||||
},
|
||||
"datasource": "${DS_GDEV-TESTDATA}",
|
||||
"libraryPanel": map[string]interface{}{
|
||||
"name": sc.initialResult.Result.Name,
|
||||
},
|
||||
"title": "Text - Library Panel",
|
||||
"type": "text",
|
||||
},
|
||||
},
|
||||
}
|
||||
dash := simplejson.NewFromAny(dashJSON)
|
||||
err := sc.service.ImportDashboard(sc.reqContext, dash, importedDashInDB.Id)
|
||||
require.EqualError(t, err, errLibraryPanelHeaderUIDMissing.Error())
|
||||
})
|
||||
}
|
||||
|
||||
type libraryPanel struct {
|
||||
ID int64
|
||||
OrgID int64
|
||||
|
||||
Reference in New Issue
Block a user