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
1626a66b
Unverified
Commit
1626a66b
authored
Jun 14, 2018
by
Marcus Efraimsson
Committed by
GitHub
Jun 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12275 from dehrax/12224-exporter
karma to jest: exporter, playlist_edit_ctrl
parents
25e1d723
23abf044
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
206 additions
and
200 deletions
+206
-200
public/app/features/dashboard/specs/exporter.jest.ts
+194
-0
public/app/features/dashboard/specs/exporter_specs.ts
+0
-187
public/app/features/playlist/specs/playlist_edit_ctrl.jest.ts
+12
-13
No files found.
public/app/features/dashboard/specs/exporter.jest.ts
0 → 100644
View file @
1626a66b
jest
.
mock
(
'app/core/store'
,
()
=>
{
return
{
getBool
:
jest
.
fn
(),
};
});
import
_
from
'lodash'
;
import
config
from
'app/core/config'
;
import
{
DashboardExporter
}
from
'../export/exporter'
;
import
{
DashboardModel
}
from
'../dashboard_model'
;
describe
(
'given dashboard with repeated panels'
,
()
=>
{
var
dash
,
exported
;
beforeEach
(
done
=>
{
dash
=
{
templating
:
{
list
:
[
{
name
:
'apps'
,
type
:
'query'
,
datasource
:
'gfdb'
,
current
:
{
value
:
'Asd'
,
text
:
'Asd'
},
options
:
[{
value
:
'Asd'
,
text
:
'Asd'
}],
},
{
name
:
'prefix'
,
type
:
'constant'
,
current
:
{
value
:
'collectd'
,
text
:
'collectd'
},
options
:
[],
},
{
name
:
'ds'
,
type
:
'datasource'
,
query
:
'testdb'
,
current
:
{
value
:
'prod'
,
text
:
'prod'
},
options
:
[],
},
],
},
annotations
:
{
list
:
[
{
name
:
'logs'
,
datasource
:
'gfdb'
,
},
],
},
panels
:
[
{
id
:
6
,
datasource
:
'gfdb'
,
type
:
'graph'
},
{
id
:
7
},
{
id
:
8
,
datasource
:
'-- Mixed --'
,
targets
:
[{
datasource
:
'other'
}],
},
{
id
:
9
,
datasource
:
'$ds'
},
{
id
:
2
,
repeat
:
'apps'
,
datasource
:
'gfdb'
,
type
:
'graph'
,
},
{
id
:
3
,
repeat
:
null
,
repeatPanelId
:
2
},
],
};
config
.
buildInfo
=
{
version
:
'3.0.2'
,
};
//Stubs test function calls
var
datasourceSrvStub
=
{
get
:
jest
.
fn
(
arg
=>
getStub
(
arg
))
};
config
.
panels
[
'graph'
]
=
{
id
:
'graph'
,
name
:
'Graph'
,
info
:
{
version
:
'1.1.0'
},
};
dash
=
new
DashboardModel
(
dash
,
{});
var
exporter
=
new
DashboardExporter
(
datasourceSrvStub
);
exporter
.
makeExportable
(
dash
).
then
(
clean
=>
{
exported
=
clean
;
done
();
});
});
it
(
'should replace datasource refs'
,
()
=>
{
var
panel
=
exported
.
panels
[
0
];
expect
(
panel
.
datasource
).
toBe
(
'${DS_GFDB}'
);
});
it
(
'should replace datasource in variable query'
,
()
=>
{
expect
(
exported
.
templating
.
list
[
0
].
datasource
).
toBe
(
'${DS_GFDB}'
);
expect
(
exported
.
templating
.
list
[
0
].
options
.
length
).
toBe
(
0
);
expect
(
exported
.
templating
.
list
[
0
].
current
.
value
).
toBe
(
undefined
);
expect
(
exported
.
templating
.
list
[
0
].
current
.
text
).
toBe
(
undefined
);
});
it
(
'should replace datasource in annotation query'
,
()
=>
{
expect
(
exported
.
annotations
.
list
[
1
].
datasource
).
toBe
(
'${DS_GFDB}'
);
});
it
(
'should add datasource as input'
,
()
=>
{
expect
(
exported
.
__inputs
[
0
].
name
).
toBe
(
'DS_GFDB'
);
expect
(
exported
.
__inputs
[
0
].
pluginId
).
toBe
(
'testdb'
);
expect
(
exported
.
__inputs
[
0
].
type
).
toBe
(
'datasource'
);
});
it
(
'should add datasource to required'
,
()
=>
{
var
require
=
_
.
find
(
exported
.
__requires
,
{
name
:
'TestDB'
});
expect
(
require
.
name
).
toBe
(
'TestDB'
);
expect
(
require
.
id
).
toBe
(
'testdb'
);
expect
(
require
.
type
).
toBe
(
'datasource'
);
expect
(
require
.
version
).
toBe
(
'1.2.1'
);
});
it
(
'should not add built in datasources to required'
,
()
=>
{
var
require
=
_
.
find
(
exported
.
__requires
,
{
name
:
'Mixed'
});
expect
(
require
).
toBe
(
undefined
);
});
it
(
'should add datasources used in mixed mode'
,
()
=>
{
var
require
=
_
.
find
(
exported
.
__requires
,
{
name
:
'OtherDB'
});
expect
(
require
).
not
.
toBe
(
undefined
);
});
it
(
'should add panel to required'
,
()
=>
{
var
require
=
_
.
find
(
exported
.
__requires
,
{
name
:
'Graph'
});
expect
(
require
.
name
).
toBe
(
'Graph'
);
expect
(
require
.
id
).
toBe
(
'graph'
);
expect
(
require
.
version
).
toBe
(
'1.1.0'
);
});
it
(
'should add grafana version'
,
()
=>
{
var
require
=
_
.
find
(
exported
.
__requires
,
{
name
:
'Grafana'
});
expect
(
require
.
type
).
toBe
(
'grafana'
);
expect
(
require
.
id
).
toBe
(
'grafana'
);
expect
(
require
.
version
).
toBe
(
'3.0.2'
);
});
it
(
'should add constant template variables as inputs'
,
()
=>
{
var
input
=
_
.
find
(
exported
.
__inputs
,
{
name
:
'VAR_PREFIX'
});
expect
(
input
.
type
).
toBe
(
'constant'
);
expect
(
input
.
label
).
toBe
(
'prefix'
);
expect
(
input
.
value
).
toBe
(
'collectd'
);
});
it
(
'should templatize constant variables'
,
()
=>
{
var
variable
=
_
.
find
(
exported
.
templating
.
list
,
{
name
:
'prefix'
});
expect
(
variable
.
query
).
toBe
(
'${VAR_PREFIX}'
);
expect
(
variable
.
current
.
text
).
toBe
(
'${VAR_PREFIX}'
);
expect
(
variable
.
current
.
value
).
toBe
(
'${VAR_PREFIX}'
);
expect
(
variable
.
options
[
0
].
text
).
toBe
(
'${VAR_PREFIX}'
);
expect
(
variable
.
options
[
0
].
value
).
toBe
(
'${VAR_PREFIX}'
);
});
});
// Stub responses
var
stubs
=
[];
stubs
[
'gfdb'
]
=
{
name
:
'gfdb'
,
meta
:
{
id
:
'testdb'
,
info
:
{
version
:
'1.2.1'
},
name
:
'TestDB'
},
};
stubs
[
'other'
]
=
{
name
:
'other'
,
meta
:
{
id
:
'other'
,
info
:
{
version
:
'1.2.1'
},
name
:
'OtherDB'
},
};
stubs
[
'-- Mixed --'
]
=
{
name
:
'mixed'
,
meta
:
{
id
:
'mixed'
,
info
:
{
version
:
'1.2.1'
},
name
:
'Mixed'
,
builtIn
:
true
,
},
};
stubs
[
'-- Grafana --'
]
=
{
name
:
'-- Grafana --'
,
meta
:
{
id
:
'grafana'
,
info
:
{
version
:
'1.2.1'
},
name
:
'grafana'
,
builtIn
:
true
,
},
};
function
getStub
(
arg
)
{
return
Promise
.
resolve
(
stubs
[
arg
]);
}
public/app/features/dashboard/specs/exporter_specs.ts
deleted
100644 → 0
View file @
25e1d723
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
import
_
from
'lodash'
;
import
config
from
'app/core/config'
;
import
{
DashboardExporter
}
from
'../export/exporter'
;
import
{
DashboardModel
}
from
'../dashboard_model'
;
describe
(
'given dashboard with repeated panels'
,
function
()
{
var
dash
,
exported
;
beforeEach
(
done
=>
{
dash
=
{
templating
:
{
list
:
[]
},
annotations
:
{
list
:
[]
},
};
config
.
buildInfo
=
{
version
:
'3.0.2'
,
};
dash
.
templating
.
list
.
push
({
name
:
'apps'
,
type
:
'query'
,
datasource
:
'gfdb'
,
current
:
{
value
:
'Asd'
,
text
:
'Asd'
},
options
:
[{
value
:
'Asd'
,
text
:
'Asd'
}],
});
dash
.
templating
.
list
.
push
({
name
:
'prefix'
,
type
:
'constant'
,
current
:
{
value
:
'collectd'
,
text
:
'collectd'
},
options
:
[],
});
dash
.
templating
.
list
.
push
({
name
:
'ds'
,
type
:
'datasource'
,
query
:
'testdb'
,
current
:
{
value
:
'prod'
,
text
:
'prod'
},
options
:
[],
});
dash
.
annotations
.
list
.
push
({
name
:
'logs'
,
datasource
:
'gfdb'
,
});
dash
.
panels
=
[
{
id
:
6
,
datasource
:
'gfdb'
,
type
:
'graph'
},
{
id
:
7
},
{
id
:
8
,
datasource
:
'-- Mixed --'
,
targets
:
[{
datasource
:
'other'
}],
},
{
id
:
9
,
datasource
:
'$ds'
},
];
dash
.
panels
.
push
({
id
:
2
,
repeat
:
'apps'
,
datasource
:
'gfdb'
,
type
:
'graph'
,
});
dash
.
panels
.
push
({
id
:
3
,
repeat
:
null
,
repeatPanelId
:
2
});
var
datasourceSrvStub
=
{
get
:
sinon
.
stub
()
};
datasourceSrvStub
.
get
.
withArgs
(
'gfdb'
).
returns
(
Promise
.
resolve
({
name
:
'gfdb'
,
meta
:
{
id
:
'testdb'
,
info
:
{
version
:
'1.2.1'
},
name
:
'TestDB'
},
})
);
datasourceSrvStub
.
get
.
withArgs
(
'other'
).
returns
(
Promise
.
resolve
({
name
:
'other'
,
meta
:
{
id
:
'other'
,
info
:
{
version
:
'1.2.1'
},
name
:
'OtherDB'
},
})
);
datasourceSrvStub
.
get
.
withArgs
(
'-- Mixed --'
).
returns
(
Promise
.
resolve
({
name
:
'mixed'
,
meta
:
{
id
:
'mixed'
,
info
:
{
version
:
'1.2.1'
},
name
:
'Mixed'
,
builtIn
:
true
,
},
})
);
datasourceSrvStub
.
get
.
withArgs
(
'-- Grafana --'
).
returns
(
Promise
.
resolve
({
name
:
'-- Grafana --'
,
meta
:
{
id
:
'grafana'
,
info
:
{
version
:
'1.2.1'
},
name
:
'grafana'
,
builtIn
:
true
,
},
})
);
config
.
panels
[
'graph'
]
=
{
id
:
'graph'
,
name
:
'Graph'
,
info
:
{
version
:
'1.1.0'
},
};
dash
=
new
DashboardModel
(
dash
,
{});
var
exporter
=
new
DashboardExporter
(
datasourceSrvStub
);
exporter
.
makeExportable
(
dash
).
then
(
clean
=>
{
exported
=
clean
;
done
();
});
});
it
(
'should replace datasource refs'
,
function
()
{
var
panel
=
exported
.
panels
[
0
];
expect
(
panel
.
datasource
).
to
.
be
(
'${DS_GFDB}'
);
});
it
(
'should replace datasource in variable query'
,
function
()
{
expect
(
exported
.
templating
.
list
[
0
].
datasource
).
to
.
be
(
'${DS_GFDB}'
);
expect
(
exported
.
templating
.
list
[
0
].
options
.
length
).
to
.
be
(
0
);
expect
(
exported
.
templating
.
list
[
0
].
current
.
value
).
to
.
be
(
undefined
);
expect
(
exported
.
templating
.
list
[
0
].
current
.
text
).
to
.
be
(
undefined
);
});
it
(
'should replace datasource in annotation query'
,
function
()
{
expect
(
exported
.
annotations
.
list
[
1
].
datasource
).
to
.
be
(
'${DS_GFDB}'
);
});
it
(
'should add datasource as input'
,
function
()
{
expect
(
exported
.
__inputs
[
0
].
name
).
to
.
be
(
'DS_GFDB'
);
expect
(
exported
.
__inputs
[
0
].
pluginId
).
to
.
be
(
'testdb'
);
expect
(
exported
.
__inputs
[
0
].
type
).
to
.
be
(
'datasource'
);
});
it
(
'should add datasource to required'
,
function
()
{
var
require
=
_
.
find
(
exported
.
__requires
,
{
name
:
'TestDB'
});
expect
(
require
.
name
).
to
.
be
(
'TestDB'
);
expect
(
require
.
id
).
to
.
be
(
'testdb'
);
expect
(
require
.
type
).
to
.
be
(
'datasource'
);
expect
(
require
.
version
).
to
.
be
(
'1.2.1'
);
});
it
(
'should not add built in datasources to required'
,
function
()
{
var
require
=
_
.
find
(
exported
.
__requires
,
{
name
:
'Mixed'
});
expect
(
require
).
to
.
be
(
undefined
);
});
it
(
'should add datasources used in mixed mode'
,
function
()
{
var
require
=
_
.
find
(
exported
.
__requires
,
{
name
:
'OtherDB'
});
expect
(
require
).
to
.
not
.
be
(
undefined
);
});
it
(
'should add panel to required'
,
function
()
{
var
require
=
_
.
find
(
exported
.
__requires
,
{
name
:
'Graph'
});
expect
(
require
.
name
).
to
.
be
(
'Graph'
);
expect
(
require
.
id
).
to
.
be
(
'graph'
);
expect
(
require
.
version
).
to
.
be
(
'1.1.0'
);
});
it
(
'should add grafana version'
,
function
()
{
var
require
=
_
.
find
(
exported
.
__requires
,
{
name
:
'Grafana'
});
expect
(
require
.
type
).
to
.
be
(
'grafana'
);
expect
(
require
.
id
).
to
.
be
(
'grafana'
);
expect
(
require
.
version
).
to
.
be
(
'3.0.2'
);
});
it
(
'should add constant template variables as inputs'
,
function
()
{
var
input
=
_
.
find
(
exported
.
__inputs
,
{
name
:
'VAR_PREFIX'
});
expect
(
input
.
type
).
to
.
be
(
'constant'
);
expect
(
input
.
label
).
to
.
be
(
'prefix'
);
expect
(
input
.
value
).
to
.
be
(
'collectd'
);
});
it
(
'should templatize constant variables'
,
function
()
{
var
variable
=
_
.
find
(
exported
.
templating
.
list
,
{
name
:
'prefix'
});
expect
(
variable
.
query
).
to
.
be
(
'${VAR_PREFIX}'
);
expect
(
variable
.
current
.
text
).
to
.
be
(
'${VAR_PREFIX}'
);
expect
(
variable
.
current
.
value
).
to
.
be
(
'${VAR_PREFIX}'
);
expect
(
variable
.
options
[
0
].
text
).
to
.
be
(
'${VAR_PREFIX}'
);
expect
(
variable
.
options
[
0
].
value
).
to
.
be
(
'${VAR_PREFIX}'
);
});
});
public/app/features/playlist/specs/playlist_edit_ctrl
_specs
.ts
→
public/app/features/playlist/specs/playlist_edit_ctrl
.jest
.ts
View file @
1626a66b
import
'../playlist_edit_ctrl'
;
import
'../playlist_edit_ctrl'
;
import
{
describe
,
beforeEach
,
it
,
expect
}
from
'test/lib/common'
;
import
{
PlaylistEditCtrl
}
from
'../playlist_edit_ctrl'
;
import
{
PlaylistEditCtrl
}
from
'../playlist_edit_ctrl'
;
describe
(
'PlaylistEditCtrl'
,
()
=>
{
describe
(
'PlaylistEditCtrl'
,
()
=>
{
...
@@ -20,13 +19,13 @@ describe('PlaylistEditCtrl', () => {
...
@@ -20,13 +19,13 @@ describe('PlaylistEditCtrl', () => {
describe
(
'searchresult returns 2 dashboards, '
,
()
=>
{
describe
(
'searchresult returns 2 dashboards, '
,
()
=>
{
it
(
'found dashboard should be 2'
,
()
=>
{
it
(
'found dashboard should be 2'
,
()
=>
{
expect
(
ctx
.
dashboardresult
.
length
).
to
.
b
e
(
2
);
expect
(
ctx
.
dashboardresult
.
length
).
to
B
e
(
2
);
});
});
it
(
'filtred result should be 2'
,
()
=>
{
it
(
'filtred result should be 2'
,
()
=>
{
ctx
.
filterFoundPlaylistItems
();
ctx
.
filterFoundPlaylistItems
();
expect
(
ctx
.
filteredDashboards
.
length
).
to
.
b
e
(
2
);
expect
(
ctx
.
filteredDashboards
.
length
).
to
B
e
(
2
);
expect
(
ctx
.
filteredTags
.
length
).
to
.
b
e
(
2
);
expect
(
ctx
.
filteredTags
.
length
).
to
B
e
(
2
);
});
});
describe
(
'adds one dashboard to playlist, '
,
()
=>
{
describe
(
'adds one dashboard to playlist, '
,
()
=>
{
...
@@ -37,16 +36,16 @@ describe('PlaylistEditCtrl', () => {
...
@@ -37,16 +36,16 @@ describe('PlaylistEditCtrl', () => {
});
});
it
(
'playlistitems should be increased by one'
,
()
=>
{
it
(
'playlistitems should be increased by one'
,
()
=>
{
expect
(
ctx
.
playlistItems
.
length
).
to
.
b
e
(
2
);
expect
(
ctx
.
playlistItems
.
length
).
to
B
e
(
2
);
});
});
it
(
'filtred playlistitems should be reduced by one'
,
()
=>
{
it
(
'filtred playlistitems should be reduced by one'
,
()
=>
{
expect
(
ctx
.
filteredDashboards
.
length
).
to
.
b
e
(
1
);
expect
(
ctx
.
filteredDashboards
.
length
).
to
B
e
(
1
);
expect
(
ctx
.
filteredTags
.
length
).
to
.
b
e
(
1
);
expect
(
ctx
.
filteredTags
.
length
).
to
B
e
(
1
);
});
});
it
(
'found dashboard should be 2'
,
()
=>
{
it
(
'found dashboard should be 2'
,
()
=>
{
expect
(
ctx
.
dashboardresult
.
length
).
to
.
b
e
(
2
);
expect
(
ctx
.
dashboardresult
.
length
).
to
B
e
(
2
);
});
});
describe
(
'removes one dashboard from playlist, '
,
()
=>
{
describe
(
'removes one dashboard from playlist, '
,
()
=>
{
...
@@ -57,14 +56,14 @@ describe('PlaylistEditCtrl', () => {
...
@@ -57,14 +56,14 @@ describe('PlaylistEditCtrl', () => {
});
});
it
(
'playlistitems should be increased by one'
,
()
=>
{
it
(
'playlistitems should be increased by one'
,
()
=>
{
expect
(
ctx
.
playlistItems
.
length
).
to
.
b
e
(
0
);
expect
(
ctx
.
playlistItems
.
length
).
to
B
e
(
0
);
});
});
it
(
'found dashboard should be 2'
,
()
=>
{
it
(
'found dashboard should be 2'
,
()
=>
{
expect
(
ctx
.
dashboardresult
.
length
).
to
.
b
e
(
2
);
expect
(
ctx
.
dashboardresult
.
length
).
to
B
e
(
2
);
expect
(
ctx
.
filteredDashboards
.
length
).
to
.
b
e
(
2
);
expect
(
ctx
.
filteredDashboards
.
length
).
to
B
e
(
2
);
expect
(
ctx
.
filteredTags
.
length
).
to
.
b
e
(
2
);
expect
(
ctx
.
filteredTags
.
length
).
to
B
e
(
2
);
expect
(
ctx
.
tagresult
.
length
).
to
.
b
e
(
2
);
expect
(
ctx
.
tagresult
.
length
).
to
B
e
(
2
);
});
});
});
});
});
});
...
...
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