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
c0f9c06f
Commit
c0f9c06f
authored
Jun 29, 2018
by
Tobias Skarhed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Karma to Jest: completer
parent
35efb7c2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
36 deletions
+34
-36
public/app/plugins/datasource/prometheus/specs/completer.jest.ts
+34
-36
No files found.
public/app/plugins/datasource/prometheus/specs/completer
_specs
.ts
→
public/app/plugins/datasource/prometheus/specs/completer
.jest
.ts
View file @
c0f9c06f
import
{
describe
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
import
helpers
from
'test/specs/helpers'
;
//
import { describe, it, sinon, expect } from 'test/lib/common';
//
import helpers from 'test/specs/helpers';
import
{
PromCompleter
}
from
'../completer'
;
import
{
PrometheusDatasource
}
from
'../datasource'
;
import
{
BackendSrv
}
from
'app/core/services/backend_srv'
;
jest
.
mock
(
'../datasource'
);
jest
.
mock
(
'app/core/services/backend_srv'
);
describe
(
'Prometheus editor completer'
,
function
()
{
var
ctx
=
new
helpers
.
ServiceTestContext
();
beforeEach
(
ctx
.
providePhase
([
'templateSrv'
]));
//beforeEach(ctx.providePhase(['templateSrv']));
function
getSessionStub
(
data
)
{
return
{
getTokenAt
:
sinon
.
stub
().
returns
(
data
.
currentToken
),
getTokens
:
sinon
.
stub
().
returns
(
data
.
tokens
),
getLine
:
sinon
.
stub
().
returns
(
data
.
line
),
getTokenAt
:
jest
.
fn
(()
=>
(
data
.
currentToken
)
),
getTokens
:
jest
.
fn
(()
=>
(
data
.
tokens
)
),
getLine
:
jest
.
fn
(()
=>
(
data
.
line
)
),
};
}
let
editor
=
{};
let
datasourceStub
=
<
PrometheusDatasource
>
{
performInstantQuery
:
sinon
.
stub
()
.
withArgs
({
expr
:
'{__name__="node_cpu"'
})
.
returns
(
Promise
.
resolve
({
data
:
{
let
backendSrv
=
<
BackendSrv
>
{}
let
datasourceStub
=
new
PrometheusDatasource
({},{},
backendSrv
,{},{});
datasourceStub
.
performInstantQuery
=
jest
.
fn
(()
=>
Promise
.
resolve
({
data
:
{
result
:
[
{
metric
:
{
job
:
'node'
,
instance
:
'localhost:9100'
,
data
:
{
result
:
[
{
metric
:
{
job
:
'node'
,
instance
:
'localhost:9100'
,
},
},
}
,
]
,
]
,
}
,
},
},
})
),
performSuggestQuery
:
sinon
.
stub
()
.
withArgs
(
'node'
,
true
)
.
returns
(
Promise
.
resolve
([
'node_cpu'
])),
};
})
);
datasourceStub
.
performSuggestQuery
=
jest
.
fn
(()
=>
Promise
.
resolve
([
'node_cpu'
]));
let
templateSrv
=
{
variables
:
[
...
...
@@ -62,9 +60,9 @@ describe('Prometheus editor completer', function() {
});
return
completer
.
getCompletions
(
editor
,
session
,
{
row
:
0
,
column
:
10
},
'['
,
(
s
,
res
)
=>
{
expect
(
res
[
0
].
caption
).
to
.
eq
l
(
'$__interval'
);
expect
(
res
[
0
].
value
).
to
.
eq
l
(
'[$__interval'
);
expect
(
res
[
0
].
meta
).
to
.
eq
l
(
'range vector'
);
expect
(
res
[
0
].
caption
).
to
Equa
l
(
'$__interval'
);
expect
(
res
[
0
].
value
).
to
Equa
l
(
'[$__interval'
);
expect
(
res
[
0
].
meta
).
to
Equa
l
(
'range vector'
);
});
});
});
...
...
@@ -93,7 +91,7 @@ describe('Prometheus editor completer', function() {
});
return
completer
.
getCompletions
(
editor
,
session
,
{
row
:
0
,
column
:
10
},
'j'
,
(
s
,
res
)
=>
{
expect
(
res
[
0
].
meta
).
to
.
eq
l
(
'label name'
);
expect
(
res
[
0
].
meta
).
to
Equa
l
(
'label name'
);
});
});
});
...
...
@@ -125,7 +123,7 @@ describe('Prometheus editor completer', function() {
});
return
completer
.
getCompletions
(
editor
,
session
,
{
row
:
0
,
column
:
23
},
'j'
,
(
s
,
res
)
=>
{
expect
(
res
[
0
].
meta
).
to
.
eq
l
(
'label name'
);
expect
(
res
[
0
].
meta
).
to
Equa
l
(
'label name'
);
});
});
});
...
...
@@ -156,7 +154,7 @@ describe('Prometheus editor completer', function() {
});
return
completer
.
getCompletions
(
editor
,
session
,
{
row
:
0
,
column
:
15
},
'n'
,
(
s
,
res
)
=>
{
expect
(
res
[
0
].
meta
).
to
.
eq
l
(
'label value'
);
expect
(
res
[
0
].
meta
).
to
Equa
l
(
'label value'
);
});
});
});
...
...
@@ -192,7 +190,7 @@ describe('Prometheus editor completer', function() {
});
return
completer
.
getCompletions
(
editor
,
session
,
{
row
:
0
,
column
:
23
},
'm'
,
(
s
,
res
)
=>
{
expect
(
res
[
0
].
meta
).
to
.
eq
l
(
'label name'
);
expect
(
res
[
0
].
meta
).
to
Equa
l
(
'label name'
);
});
});
});
...
...
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