Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
20fec4d2
Commit
20fec4d2
authored
Mar 24, 2019
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Panels: Added more tests for change panel plugin
parent
0d55141a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
4 deletions
+47
-4
packages/grafana-ui/src/types/panel.ts
+1
-1
public/app/core/utils/emitter.ts
+5
-1
public/app/features/dashboard/state/PanelModel.test.ts
+39
-0
public/app/features/dashboard/state/PanelModel.ts
+2
-2
No files found.
packages/grafana-ui/src/types/panel.ts
View file @
20fec4d2
...
...
@@ -32,7 +32,7 @@ export type PanelMigrationHandler<TOptions = any> = (exiting: any, oldVersion?:
export
type
PanelTypeChangedHandler
<
TOptions
=
any
>
=
(
options
:
Partial
<
TOptions
>
,
prevPluginId
:
string
,
prevOptions
?
:
any
prevOptions
:
any
)
=>
Partial
<
TOptions
>
;
export
class
ReactPanelPlugin
<
TOptions
=
any
>
{
...
...
public/app/core/utils/emitter.ts
View file @
20fec4d2
import
{
EventEmitter
}
from
'eventemitter3'
;
export
class
Emitter
{
emitter
:
any
;
private
emitter
:
EventEmitter
;
constructor
()
{
this
.
emitter
=
new
EventEmitter
();
...
...
@@ -29,4 +29,8 @@ export class Emitter {
off
(
name
,
handler
)
{
this
.
emitter
.
off
(
name
,
handler
);
}
getEventCount
():
number
{
return
(
this
.
emitter
as
any
).
_eventsCount
;
}
}
public/app/features/dashboard/state/PanelModel.test.ts
View file @
20fec4d2
import
{
PanelModel
}
from
'./PanelModel'
;
import
{
getPanelPlugin
}
from
'../../plugins/__mocks__/pluginMocks'
;
import
{
ReactPanelPlugin
}
from
'@grafana/ui/src/types/panel'
;
describe
(
'PanelModel'
,
()
=>
{
describe
(
'when creating new panel model'
,
()
=>
{
...
...
@@ -96,6 +97,44 @@ describe('PanelModel', () => {
});
});
describe
(
'when changing from angular panel'
,
()
=>
{
let
tearDownPublished
=
false
;
beforeEach
(()
=>
{
model
.
events
.
on
(
'panel-teardown'
,
()
=>
{
tearDownPublished
=
true
;
});
model
.
changePlugin
(
getPanelPlugin
({
id
:
'graph'
,
exports
:
{}
}));
});
it
(
'should teardown / destroy panel so angular panels event subscriptions are removed'
,
()
=>
{
expect
(
tearDownPublished
).
toBe
(
true
);
expect
(
model
.
events
.
getEventCount
()).
toBe
(
0
);
});
});
describe
(
'when changing to react panel'
,
()
=>
{
const
onPanelTypeChanged
=
jest
.
fn
();
const
reactPanel
=
new
ReactPanelPlugin
({}
as
any
).
setPanelChangeHandler
(
onPanelTypeChanged
as
any
);
beforeEach
(()
=>
{
model
.
changePlugin
(
getPanelPlugin
({
id
:
'react'
,
exports
:
{
reactPanel
,
},
})
);
});
it
(
'should call react onPanelTypeChanged'
,
()
=>
{
expect
(
onPanelTypeChanged
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
onPanelTypeChanged
.
mock
.
calls
[
0
][
1
]).
toBe
(
'table'
);
expect
(
onPanelTypeChanged
.
mock
.
calls
[
0
][
2
].
thresholds
).
toBeDefined
();
});
});
describe
(
'get panel options'
,
()
=>
{
it
(
'should apply defaults'
,
()
=>
{
model
.
options
=
{
existingProp
:
10
};
...
...
public/app/features/dashboard/state/PanelModel.ts
View file @
20fec4d2
...
...
@@ -282,11 +282,11 @@ export class PanelModel {
this
.
type
=
pluginId
;
this
.
plugin
=
newPlugin
;
//
Callback that can validate and migrate any existing settings
//
Let panel plugins inspect options from previous panel and keep any that it can use
const
onPanelTypeChanged
=
reactPanel
?
reactPanel
.
onPanelTypeChanged
:
null
;
if
(
onPanelTypeChanged
)
{
this
.
options
=
this
.
options
||
{};
const
old
=
oldOptions
?
oldOptions
.
options
:
null
;
const
old
=
oldOptions
?
oldOptions
.
options
:
{}
;
Object
.
assign
(
this
.
options
,
onPanelTypeChanged
(
this
.
options
,
oldPluginId
,
old
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment