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
b58a7642
Commit
b58a7642
authored
Jul 24, 2018
by
Tobias Skarhed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Karma to Jest
parent
25c82335
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
140 additions
and
121 deletions
+140
-121
public/app/plugins/datasource/graphite/specs/query_ctrl.jest.ts
+140
-121
No files found.
public/app/plugins/datasource/graphite/specs/query_ctrl.jest.ts
View file @
b58a7642
import
'app/core/services/segment_srv'
;
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
{
uiSegmentSrv
}
from
'app/core/services/segment_srv'
;
//
import { describe, beforeEach, it, sinon, expect, angularMocks } from 'test/lib/common';
import
gfunc
from
'../gfunc'
;
import
helpers
from
'test/specs/helpers'
;
//
import helpers from 'test/specs/helpers';
import
{
GraphiteQueryCtrl
}
from
'../query_ctrl'
;
describe
(
'GraphiteQueryCtrl'
,
function
()
{
let
datasource
=
{
describe
(
'GraphiteQueryCtrl'
,
()
=>
{
let
ctx
=
<
any
>
{
datasource
:
{
metricFindQuery
:
jest
.
fn
(()
=>
Promise
.
resolve
([])),
getFuncDefs
:
jest
.
fn
(()
=>
Promise
.
resolve
(
gfunc
.
getFuncDefs
(
'1.0'
))),
getFuncDef
:
gfunc
.
getFuncDef
,
waitForFuncDefsLoaded
:
jest
.
fn
(()
=>
Promise
.
resolve
(
null
)),
createFuncInstance
:
gfunc
.
createFuncInstance
,
},
target
:
{
target
:
'aliasByNode(scaleToSeconds(test.prod.*,1),2)'
},
panelCtrl
:
{
refresh
:
jest
.
fn
(),
},
};
let
ctx
=
{
ctx
.
panelCtrl
.
panel
=
{
targets
:
[
ctx
.
target
],
};
// beforeEach(angularMocks.module('grafana.core'));
...
...
@@ -60,156 +65,170 @@ describe('GraphiteQueryCtrl', function() {
// })
// );
describe
(
'init'
,
function
()
{
it
(
'should validate metric key exists'
,
function
()
{
expect
(
ctx
.
datasource
.
metricFindQuery
.
getCall
(
0
).
args
[
0
]).
to
.
be
(
'test.prod.*'
);
beforeEach
(()
=>
{
GraphiteQueryCtrl
.
prototype
.
target
=
ctx
.
target
;
GraphiteQueryCtrl
.
prototype
.
datasource
=
ctx
.
datasource
;
GraphiteQueryCtrl
.
prototype
.
panelCtrl
=
ctx
.
panelCtrl
;
ctx
.
ctrl
=
new
GraphiteQueryCtrl
(
{},
{},
new
uiSegmentSrv
({
trustAsHtml
:
html
=>
html
},
{
highlightVariablesAsHtml
:
()
=>
{}
}),
{},
{}
);
});
describe
(
'init'
,
()
=>
{
it
(
'should validate metric key exists'
,
()
=>
{
expect
(
ctx
.
datasource
.
metricFindQuery
.
mock
.
calls
[
0
][
0
]).
toBe
(
'test.prod.*'
);
});
it
(
'should delete last segment if no metrics are found'
,
function
()
{
expect
(
ctx
.
ctrl
.
segments
[
2
].
value
).
to
.
b
e
(
'select metric'
);
it
(
'should delete last segment if no metrics are found'
,
()
=>
{
expect
(
ctx
.
ctrl
.
segments
[
2
].
value
).
to
B
e
(
'select metric'
);
});
it
(
'should parse expression and build function model'
,
function
()
{
expect
(
ctx
.
ctrl
.
queryModel
.
functions
.
length
).
to
.
b
e
(
2
);
it
(
'should parse expression and build function model'
,
()
=>
{
expect
(
ctx
.
ctrl
.
queryModel
.
functions
.
length
).
to
B
e
(
2
);
});
});
describe
(
'when adding function'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when adding function'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
'test.prod.*.count'
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([{
expandable
:
false
}])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([{
expandable
:
false
}]
);
ctx
.
ctrl
.
parseTarget
();
ctx
.
ctrl
.
addFunction
(
gfunc
.
getFuncDef
(
'aliasByNode'
));
});
it
(
'should add function with correct node number'
,
function
()
{
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
[
0
]).
to
.
b
e
(
2
);
it
(
'should add function with correct node number'
,
()
=>
{
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
[
0
]).
to
B
e
(
2
);
});
it
(
'should update target'
,
function
()
{
expect
(
ctx
.
ctrl
.
target
.
target
).
to
.
b
e
(
'aliasByNode(test.prod.*.count, 2)'
);
it
(
'should update target'
,
()
=>
{
expect
(
ctx
.
ctrl
.
target
.
target
).
to
B
e
(
'aliasByNode(test.prod.*.count, 2)'
);
});
it
(
'should call refresh'
,
function
()
{
expect
(
ctx
.
panelCtrl
.
refresh
.
called
).
to
.
be
(
true
);
it
(
'should call refresh'
,
()
=>
{
expect
(
ctx
.
panelCtrl
.
refresh
).
toHaveBeenCalled
(
);
});
});
describe
(
'when adding function before any metric segment'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when adding function before any metric segment'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
''
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
.
returns
(
ctx
.
$q
.
when
([{
expandable
:
true
}])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([{
expandable
:
true
}]
);
ctx
.
ctrl
.
parseTarget
();
ctx
.
ctrl
.
addFunction
(
gfunc
.
getFuncDef
(
'asPercent'
));
});
it
(
'should add function and remove select metric link'
,
function
()
{
expect
(
ctx
.
ctrl
.
segments
.
length
).
to
.
b
e
(
0
);
it
(
'should add function and remove select metric link'
,
()
=>
{
expect
(
ctx
.
ctrl
.
segments
.
length
).
to
B
e
(
0
);
});
});
describe
(
'when initializing target without metric expression and only function'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when initializing target without metric expression and only function'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
'asPercent(#A, #B)'
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
.
returns
(
ctx
.
$q
.
when
([])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([]
);
ctx
.
ctrl
.
parseTarget
();
ctx
.
scope
.
$digest
();
});
it
(
'should not add select metric segment'
,
function
()
{
expect
(
ctx
.
ctrl
.
segments
.
length
).
to
.
b
e
(
1
);
it
(
'should not add select metric segment'
,
()
=>
{
expect
(
ctx
.
ctrl
.
segments
.
length
).
to
B
e
(
1
);
});
it
(
'should add second series ref as param'
,
function
()
{
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
.
length
).
to
.
b
e
(
1
);
it
(
'should add second series ref as param'
,
()
=>
{
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
.
length
).
to
B
e
(
1
);
});
});
describe
(
'when initializing a target with single param func using variable'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when initializing a target with single param func using variable'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
'movingAverage(prod.count, $var)'
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
.
returns
(
ctx
.
$q
.
when
([])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([]
);
ctx
.
ctrl
.
parseTarget
();
});
it
(
'should add 2 segments'
,
function
()
{
expect
(
ctx
.
ctrl
.
segments
.
length
).
to
.
b
e
(
2
);
it
(
'should add 2 segments'
,
()
=>
{
expect
(
ctx
.
ctrl
.
segments
.
length
).
to
B
e
(
2
);
});
it
(
'should add function param'
,
function
()
{
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
.
length
).
to
.
b
e
(
1
);
it
(
'should add function param'
,
()
=>
{
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
.
length
).
to
B
e
(
1
);
});
});
describe
(
'when initializing target without metric expression and function with series-ref'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when initializing target without metric expression and function with series-ref'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
'asPercent(metric.node.count, #A)'
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
.
returns
(
ctx
.
$q
.
when
([])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([]
);
ctx
.
ctrl
.
parseTarget
();
});
it
(
'should add segments'
,
function
()
{
expect
(
ctx
.
ctrl
.
segments
.
length
).
to
.
b
e
(
3
);
it
(
'should add segments'
,
()
=>
{
expect
(
ctx
.
ctrl
.
segments
.
length
).
to
B
e
(
3
);
});
it
(
'should have correct func params'
,
function
()
{
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
.
length
).
to
.
b
e
(
1
);
it
(
'should have correct func params'
,
()
=>
{
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
.
length
).
to
B
e
(
1
);
});
});
describe
(
'when getting altSegments and metricFindQuery returns empty array'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when getting altSegments and metricFindQuery returns empty array'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
'test.count'
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
.
returns
(
ctx
.
$q
.
when
([])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([]
);
ctx
.
ctrl
.
parseTarget
();
ctx
.
ctrl
.
getAltSegments
(
1
).
then
(
function
(
results
)
{
ctx
.
altSegments
=
results
;
});
ctx
.
scope
.
$digest
();
});
it
(
'should have no segments'
,
function
()
{
expect
(
ctx
.
altSegments
.
length
).
to
.
b
e
(
0
);
it
(
'should have no segments'
,
()
=>
{
expect
(
ctx
.
altSegments
.
length
).
to
B
e
(
0
);
});
});
describe
(
'targetChanged'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([{
expandable
:
false
}]));
describe
(
'targetChanged'
,
()
=>
{
beforeEach
(()
=>
{
ctx
.
ctrl
.
target
.
target
=
'aliasByNode(scaleToSeconds(test.prod.*, 1), 2)'
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([{
expandable
:
false
}]);
ctx
.
ctrl
.
parseTarget
();
ctx
.
ctrl
.
target
.
target
=
''
;
ctx
.
ctrl
.
targetChanged
();
});
it
(
'should rebu
ld target after expression model'
,
function
()
{
expect
(
ctx
.
ctrl
.
target
.
target
).
to
.
b
e
(
'aliasByNode(scaleToSeconds(test.prod.*, 1), 2)'
);
it
(
'should rebu
ild target after expression model'
,
()
=>
{
expect
(
ctx
.
ctrl
.
target
.
target
).
to
B
e
(
'aliasByNode(scaleToSeconds(test.prod.*, 1), 2)'
);
});
it
(
'should call panelCtrl.refresh'
,
function
()
{
expect
(
ctx
.
panelCtrl
.
refresh
.
called
).
to
.
be
(
true
);
it
(
'should call panelCtrl.refresh'
,
()
=>
{
expect
(
ctx
.
panelCtrl
.
refresh
).
toHaveBeenCalled
(
);
});
});
describe
(
'when updating targets with nested query'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when updating targets with nested query'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
'scaleToSeconds(#A, 60)'
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([{
expandable
:
false
}])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([{
expandable
:
false
}]
);
ctx
.
ctrl
.
parseTarget
();
});
it
(
'should add function params'
,
function
()
{
expect
(
ctx
.
ctrl
.
queryModel
.
segments
.
length
).
to
.
b
e
(
1
);
expect
(
ctx
.
ctrl
.
queryModel
.
segments
[
0
].
value
).
to
.
b
e
(
'#A'
);
it
(
'should add function params'
,
()
=>
{
expect
(
ctx
.
ctrl
.
queryModel
.
segments
.
length
).
to
B
e
(
1
);
expect
(
ctx
.
ctrl
.
queryModel
.
segments
[
0
].
value
).
to
B
e
(
'#A'
);
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
.
length
).
to
.
b
e
(
1
);
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
[
0
]).
to
.
b
e
(
60
);
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
.
length
).
to
B
e
(
1
);
expect
(
ctx
.
ctrl
.
queryModel
.
functions
[
0
].
params
[
0
]).
to
B
e
(
60
);
});
it
(
'target should remain the same'
,
function
()
{
expect
(
ctx
.
ctrl
.
target
.
target
).
to
.
b
e
(
'scaleToSeconds(#A, 60)'
);
it
(
'target should remain the same'
,
()
=>
{
expect
(
ctx
.
ctrl
.
target
.
target
).
to
B
e
(
'scaleToSeconds(#A, 60)'
);
});
it
(
'targetFull should include nested queries'
,
function
()
{
it
(
'targetFull should include nested queries'
,
()
=>
{
ctx
.
ctrl
.
panelCtrl
.
panel
.
targets
=
[
{
target
:
'nested.query.count'
,
...
...
@@ -219,17 +238,17 @@ describe('GraphiteQueryCtrl', function() {
ctx
.
ctrl
.
updateModelTarget
();
expect
(
ctx
.
ctrl
.
target
.
target
).
to
.
b
e
(
'scaleToSeconds(#A, 60)'
);
expect
(
ctx
.
ctrl
.
target
.
target
).
to
B
e
(
'scaleToSeconds(#A, 60)'
);
expect
(
ctx
.
ctrl
.
target
.
targetFull
).
to
.
b
e
(
'scaleToSeconds(nested.query.count, 60)'
);
expect
(
ctx
.
ctrl
.
target
.
targetFull
).
to
B
e
(
'scaleToSeconds(nested.query.count, 60)'
);
});
});
describe
(
'when updating target used in other query'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when updating target used in other query'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
'metrics.a.count'
;
ctx
.
ctrl
.
target
.
refId
=
'A'
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([{
expandable
:
false
}])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([{
expandable
:
false
}]
);
ctx
.
ctrl
.
parseTarget
();
ctx
.
ctrl
.
panelCtrl
.
panel
.
targets
=
[
ctx
.
ctrl
.
target
,
{
target
:
'sumSeries(#A)'
,
refId
:
'B'
}];
...
...
@@ -237,113 +256,113 @@ describe('GraphiteQueryCtrl', function() {
ctx
.
ctrl
.
updateModelTarget
();
});
it
(
'targetFull of other query should update'
,
function
()
{
expect
(
ctx
.
ctrl
.
panel
.
targets
[
1
].
targetFull
).
to
.
b
e
(
'sumSeries(metrics.a.count)'
);
it
(
'targetFull of other query should update'
,
()
=>
{
expect
(
ctx
.
ctrl
.
panel
.
targets
[
1
].
targetFull
).
to
B
e
(
'sumSeries(metrics.a.count)'
);
});
});
describe
(
'when adding seriesByTag function'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when adding seriesByTag function'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
''
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([{
expandable
:
false
}])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([{
expandable
:
false
}]
);
ctx
.
ctrl
.
parseTarget
();
ctx
.
ctrl
.
addFunction
(
gfunc
.
getFuncDef
(
'seriesByTag'
));
});
it
(
'should update functions'
,
function
()
{
expect
(
ctx
.
ctrl
.
queryModel
.
getSeriesByTagFuncIndex
()).
to
.
b
e
(
0
);
it
(
'should update functions'
,
()
=>
{
expect
(
ctx
.
ctrl
.
queryModel
.
getSeriesByTagFuncIndex
()).
to
B
e
(
0
);
});
it
(
'should update seriesByTagUsed flag'
,
function
()
{
expect
(
ctx
.
ctrl
.
queryModel
.
seriesByTagUsed
).
to
.
b
e
(
true
);
it
(
'should update seriesByTagUsed flag'
,
()
=>
{
expect
(
ctx
.
ctrl
.
queryModel
.
seriesByTagUsed
).
to
B
e
(
true
);
});
it
(
'should update target'
,
function
()
{
expect
(
ctx
.
ctrl
.
target
.
target
).
to
.
b
e
(
'seriesByTag()'
);
it
(
'should update target'
,
()
=>
{
expect
(
ctx
.
ctrl
.
target
.
target
).
to
B
e
(
'seriesByTag()'
);
});
it
(
'should call refresh'
,
function
()
{
expect
(
ctx
.
panelCtrl
.
refresh
.
called
).
to
.
be
(
true
);
it
(
'should call refresh'
,
()
=>
{
expect
(
ctx
.
panelCtrl
.
refresh
).
toHaveBeenCalled
(
);
});
});
describe
(
'when parsing seriesByTag function'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when parsing seriesByTag function'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
"seriesByTag('tag1=value1', 'tag2!=~value2')"
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([{
expandable
:
false
}])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([{
expandable
:
false
}]
);
ctx
.
ctrl
.
parseTarget
();
});
it
(
'should add tags'
,
function
()
{
it
(
'should add tags'
,
()
=>
{
const
expected
=
[
{
key
:
'tag1'
,
operator
:
'='
,
value
:
'value1'
},
{
key
:
'tag2'
,
operator
:
'!=~'
,
value
:
'value2'
},
];
expect
(
ctx
.
ctrl
.
queryModel
.
tags
).
to
.
eq
l
(
expected
);
expect
(
ctx
.
ctrl
.
queryModel
.
tags
).
to
Equa
l
(
expected
);
});
it
(
'should add plus button'
,
function
()
{
expect
(
ctx
.
ctrl
.
addTagSegments
.
length
).
to
.
b
e
(
1
);
it
(
'should add plus button'
,
()
=>
{
expect
(
ctx
.
ctrl
.
addTagSegments
.
length
).
to
B
e
(
1
);
});
});
describe
(
'when tag added'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when tag added'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
'seriesByTag()'
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([{
expandable
:
false
}])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([{
expandable
:
false
}]
);
ctx
.
ctrl
.
parseTarget
();
ctx
.
ctrl
.
addNewTag
({
value
:
'tag1'
});
});
it
(
'should update tags with default value'
,
function
()
{
it
(
'should update tags with default value'
,
()
=>
{
const
expected
=
[{
key
:
'tag1'
,
operator
:
'='
,
value
:
''
}];
expect
(
ctx
.
ctrl
.
queryModel
.
tags
).
to
.
eq
l
(
expected
);
expect
(
ctx
.
ctrl
.
queryModel
.
tags
).
to
Equa
l
(
expected
);
});
it
(
'should update target'
,
function
()
{
it
(
'should update target'
,
()
=>
{
const
expected
=
"seriesByTag('tag1=')"
;
expect
(
ctx
.
ctrl
.
target
.
target
).
to
.
eq
l
(
expected
);
expect
(
ctx
.
ctrl
.
target
.
target
).
to
Equa
l
(
expected
);
});
});
describe
(
'when tag changed'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when tag changed'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
"seriesByTag('tag1=value1', 'tag2!=~value2')"
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([{
expandable
:
false
}])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([{
expandable
:
false
}]
);
ctx
.
ctrl
.
parseTarget
();
ctx
.
ctrl
.
tagChanged
({
key
:
'tag1'
,
operator
:
'='
,
value
:
'new_value'
},
0
);
});
it
(
'should update tags'
,
function
()
{
it
(
'should update tags'
,
()
=>
{
const
expected
=
[
{
key
:
'tag1'
,
operator
:
'='
,
value
:
'new_value'
},
{
key
:
'tag2'
,
operator
:
'!=~'
,
value
:
'value2'
},
];
expect
(
ctx
.
ctrl
.
queryModel
.
tags
).
to
.
eq
l
(
expected
);
expect
(
ctx
.
ctrl
.
queryModel
.
tags
).
to
Equa
l
(
expected
);
});
it
(
'should update target'
,
function
()
{
it
(
'should update target'
,
()
=>
{
const
expected
=
"seriesByTag('tag1=new_value', 'tag2!=~value2')"
;
expect
(
ctx
.
ctrl
.
target
.
target
).
to
.
eq
l
(
expected
);
expect
(
ctx
.
ctrl
.
target
.
target
).
to
Equa
l
(
expected
);
});
});
describe
(
'when tag removed'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'when tag removed'
,
()
=>
{
beforeEach
(
()
=>
{
ctx
.
ctrl
.
target
.
target
=
"seriesByTag('tag1=value1', 'tag2!=~value2')"
;
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([{
expandable
:
false
}])
);
ctx
.
ctrl
.
datasource
.
metricFindQuery
=
()
=>
Promise
.
resolve
([{
expandable
:
false
}]
);
ctx
.
ctrl
.
parseTarget
();
ctx
.
ctrl
.
removeTag
(
0
);
});
it
(
'should update tags'
,
function
()
{
it
(
'should update tags'
,
()
=>
{
const
expected
=
[{
key
:
'tag2'
,
operator
:
'!=~'
,
value
:
'value2'
}];
expect
(
ctx
.
ctrl
.
queryModel
.
tags
).
to
.
eq
l
(
expected
);
expect
(
ctx
.
ctrl
.
queryModel
.
tags
).
to
Equa
l
(
expected
);
});
it
(
'should update target'
,
function
()
{
it
(
'should update target'
,
()
=>
{
const
expected
=
"seriesByTag('tag2!=~value2')"
;
expect
(
ctx
.
ctrl
.
target
.
target
).
to
.
eq
l
(
expected
);
expect
(
ctx
.
ctrl
.
target
.
target
).
to
Equa
l
(
expected
);
});
});
});
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