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
7d2646f6
Commit
7d2646f6
authored
Sep 28, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: moved influxdb specs to plugins folder
parent
1a8bc1dd
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
457 additions
and
448 deletions
+457
-448
public/app/plugins/datasource/influxdb/datasource.js
+3
-3
public/app/plugins/datasource/influxdb/influx_series.js
+0
-0
public/app/plugins/datasource/influxdb/query_builder.js
+0
-0
public/app/plugins/datasource/influxdb/query_ctrl.js
+1
-1
public/app/plugins/datasource/influxdb/specs/influx_series_specs.ts
+136
-126
public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts
+141
-142
public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts
+176
-176
No files found.
public/app/plugins/datasource/influxdb/datasource.js
View file @
7d2646f6
...
@@ -2,10 +2,10 @@ define([
...
@@ -2,10 +2,10 @@ define([
'angular'
,
'angular'
,
'lodash'
,
'lodash'
,
'app/core/utils/datemath'
,
'app/core/utils/datemath'
,
'./influx
S
eries'
,
'./influx
_s
eries'
,
'./query
B
uilder'
,
'./query
_b
uilder'
,
'./directives'
,
'./directives'
,
'./query
C
trl'
,
'./query
_c
trl'
,
],
],
function
(
angular
,
_
,
dateMath
,
InfluxSeries
,
InfluxQueryBuilder
)
{
function
(
angular
,
_
,
dateMath
,
InfluxSeries
,
InfluxQueryBuilder
)
{
'use strict'
;
'use strict'
;
...
...
public/app/plugins/datasource/influxdb/influx
S
eries.js
→
public/app/plugins/datasource/influxdb/influx
_s
eries.js
View file @
7d2646f6
File moved
public/app/plugins/datasource/influxdb/query
B
uilder.js
→
public/app/plugins/datasource/influxdb/query
_b
uilder.js
View file @
7d2646f6
File moved
public/app/plugins/datasource/influxdb/query
C
trl.js
→
public/app/plugins/datasource/influxdb/query
_c
trl.js
View file @
7d2646f6
define
([
define
([
'angular'
,
'angular'
,
'lodash'
,
'lodash'
,
'./query
B
uilder'
,
'./query
_b
uilder'
,
],
],
function
(
angular
,
_
,
InfluxQueryBuilder
)
{
function
(
angular
,
_
,
InfluxQueryBuilder
)
{
'use strict'
;
'use strict'
;
...
...
public/
test/specs/influxSeries-specs.j
s
→
public/
app/plugins/datasource/influxdb/specs/influx_series_specs.t
s
View file @
7d2646f6
define
([
///<amd-dependency path="app/plugins/datasource/influxdb/influx_series" name="InfluxSeries"/>
'app/plugins/datasource/influxdb/influxSeries'
],
function
(
InfluxSeries
)
{
'use strict'
;
describe
(
'when generating timeseries from influxdb response'
,
function
()
{
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
describe
(
'given multiple fields for series'
,
function
()
{
declare
var
InfluxSeries
:
any
;
var
options
=
{
series
:
[
describe
(
'when generating timeseries from influxdb response'
,
function
()
{
describe
(
'given multiple fields for series'
,
function
()
{
var
options
=
{
alias
:
''
,
series
:
[
{
{
name
:
'cpu'
,
name
:
'cpu'
,
tags
:
{
app
:
'test'
,
server
:
'server1'
},
tags
:
{
app
:
'test'
,
server
:
'server1'
},
columns
:
[
'time'
,
'mean'
,
'max'
,
'min'
],
columns
:
[
'time'
,
'mean'
,
'max'
,
'min'
],
values
:
[[
1431946625000
,
10
,
11
,
9
],
[
1431946626000
,
20
,
21
,
19
]]
values
:
[[
1431946625000
,
10
,
11
,
9
],
[
1431946626000
,
20
,
21
,
19
]]
}
}
]};
]
describe
(
'and no alias'
,
function
()
{
};
it
(
'should generate multiple datapoints for each column'
,
function
()
{
describe
(
'and no alias'
,
function
()
{
var
series
=
new
InfluxSeries
(
options
);
it
(
'should generate multiple datapoints for each column'
,
function
()
{
var
result
=
series
.
getTimeSeries
();
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
.
length
).
to
.
be
(
3
);
expect
(
result
[
0
].
target
).
to
.
be
(
'cpu.mean {app: test, server: server1}'
);
expect
(
result
.
length
).
to
.
be
(
3
);
expect
(
result
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10
);
expect
(
result
[
0
].
target
).
to
.
be
(
'cpu.mean {app: test, server: server1}'
);
expect
(
result
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
1431946625000
);
expect
(
result
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10
);
expect
(
result
[
0
].
datapoints
[
1
][
0
]).
to
.
be
(
20
);
expect
(
result
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
1431946625000
);
expect
(
result
[
0
].
datapoints
[
1
][
1
]).
to
.
be
(
1431946626000
);
expect
(
result
[
0
].
datapoints
[
1
][
0
]).
to
.
be
(
20
);
expect
(
result
[
0
].
datapoints
[
1
][
1
]).
to
.
be
(
1431946626000
);
expect
(
result
[
1
].
target
).
to
.
be
(
'cpu.max {app: test, server: server1}'
);
expect
(
result
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
11
);
expect
(
result
[
1
].
target
).
to
.
be
(
'cpu.max {app: test, server: server1}'
);
expect
(
result
[
1
].
datapoints
[
0
][
1
]).
to
.
be
(
1431946625000
);
expect
(
result
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
11
);
expect
(
result
[
1
].
datapoints
[
1
][
0
]).
to
.
be
(
21
);
expect
(
result
[
1
].
datapoints
[
0
][
1
]).
to
.
be
(
1431946625000
);
expect
(
result
[
1
].
datapoints
[
1
][
1
]).
to
.
be
(
1431946626000
);
expect
(
result
[
1
].
datapoints
[
1
][
0
]).
to
.
be
(
21
);
expect
(
result
[
1
].
datapoints
[
1
][
1
]).
to
.
be
(
1431946626000
);
expect
(
result
[
2
].
target
).
to
.
be
(
'cpu.min {app: test, server: server1}'
);
expect
(
result
[
2
].
datapoints
[
0
][
0
]).
to
.
be
(
9
);
expect
(
result
[
2
].
target
).
to
.
be
(
'cpu.min {app: test, server: server1}'
);
expect
(
result
[
2
].
datapoints
[
0
][
1
]).
to
.
be
(
1431946625000
);
expect
(
result
[
2
].
datapoints
[
0
][
0
]).
to
.
be
(
9
);
expect
(
result
[
2
].
datapoints
[
1
][
0
]).
to
.
be
(
19
);
expect
(
result
[
2
].
datapoints
[
0
][
1
]).
to
.
be
(
1431946625000
);
expect
(
result
[
2
].
datapoints
[
1
][
1
]).
to
.
be
(
1431946626000
);
expect
(
result
[
2
].
datapoints
[
1
][
0
]).
to
.
be
(
19
);
expect
(
result
[
2
].
datapoints
[
1
][
1
]).
to
.
be
(
1431946626000
);
});
});
describe
(
'and simple alias'
,
function
()
{
it
(
'should use alias'
,
function
()
{
options
.
alias
=
'new series'
;
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
be
(
'new series'
);
expect
(
result
[
1
].
target
).
to
.
be
(
'new series'
);
expect
(
result
[
2
].
target
).
to
.
be
(
'new series'
);
});
});
});
});
describe
(
'and alias patterns'
,
function
()
{
describe
(
'and simple alias'
,
function
()
{
it
(
'should replace patterns'
,
function
()
{
it
(
'should use alias'
,
function
()
{
options
.
alias
=
'alias: $m -> $tag_server ([[measurement]])'
;
options
.
alias
=
'new series'
;
var
series
=
new
InfluxSeries
(
options
);
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
be
(
'alias: cpu -> server1 (cpu)'
);
expect
(
result
[
1
].
target
).
to
.
be
(
'alias: cpu -> server1 (cpu)'
);
expect
(
result
[
2
].
target
).
to
.
be
(
'alias: cpu -> server1 (cpu)'
);
});
expect
(
result
[
0
].
target
).
to
.
be
(
'new series'
);
expect
(
result
[
1
].
target
).
to
.
be
(
'new series'
);
expect
(
result
[
2
].
target
).
to
.
be
(
'new series'
);
});
});
});
describe
(
'given measurement with default fieldname'
,
function
()
{
var
options
=
{
series
:
[
{
name
:
'cpu'
,
tags
:
{
app
:
'test'
,
server
:
'server1'
},
columns
:
[
'time'
,
'value'
],
values
:
[[
"2015-05-18T10:57:05Z"
,
10
],
[
"2015-05-18T10:57:06Z"
,
12
]]
},
{
name
:
'cpu'
,
tags
:
{
app
:
'test2'
,
server
:
'server2'
},
columns
:
[
'time'
,
'value'
],
values
:
[[
"2015-05-18T10:57:05Z"
,
15
],
[
"2015-05-18T10:57:06Z"
,
16
]]
}
]};
describe
(
'and no alias'
,
function
()
{
});
it
(
'should generate label with no field'
,
function
()
{
describe
(
'and alias patterns'
,
function
()
{
var
series
=
new
InfluxSeries
(
options
);
it
(
'should replace patterns'
,
function
()
{
var
result
=
series
.
getTimeSeries
();
options
.
alias
=
'alias: $m -> $tag_server ([[measurement]])'
;
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
be
(
'cpu {app: test, server: server1}
'
);
expect
(
result
[
0
].
target
).
to
.
be
(
'alias: cpu -> server1 (cpu)
'
);
expect
(
result
[
1
].
target
).
to
.
be
(
'cpu {app: test2, server: server2}
'
);
expect
(
result
[
1
].
target
).
to
.
be
(
'alias: cpu -> server1 (cpu)
'
);
}
);
expect
(
result
[
2
].
target
).
to
.
be
(
'alias: cpu -> server1 (cpu)'
);
});
});
});
});
describe
(
'given two series'
,
function
()
{
});
var
options
=
{
series
:
[
describe
(
'given measurement with default fieldname'
,
function
()
{
var
options
=
{
series
:
[
{
name
:
'cpu'
,
tags
:
{
app
:
'test'
,
server
:
'server1'
},
columns
:
[
'time'
,
'value'
],
values
:
[[
"2015-05-18T10:57:05Z"
,
10
],
[
"2015-05-18T10:57:06Z"
,
12
]]
},
{
name
:
'cpu'
,
tags
:
{
app
:
'test2'
,
server
:
'server2'
},
columns
:
[
'time'
,
'value'
],
values
:
[[
"2015-05-18T10:57:05Z"
,
15
],
[
"2015-05-18T10:57:06Z"
,
16
]]
}
]};
describe
(
'and no alias'
,
function
()
{
it
(
'should generate label with no field'
,
function
()
{
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
be
(
'cpu {app: test, server: server1}'
);
expect
(
result
[
1
].
target
).
to
.
be
(
'cpu {app: test2, server: server2}'
);
});
});
});
describe
(
'given two series'
,
function
()
{
var
options
=
{
alias
:
''
,
series
:
[
{
{
name
:
'cpu'
,
name
:
'cpu'
,
tags
:
{
app
:
'test'
,
server
:
'server1'
},
tags
:
{
app
:
'test'
,
server
:
'server1'
},
...
@@ -109,72 +115,76 @@ define([
...
@@ -109,72 +115,76 @@ define([
columns
:
[
'time'
,
'mean'
],
columns
:
[
'time'
,
'mean'
],
values
:
[[
1431946625000
,
15
],
[
1431946626000
,
16
]]
values
:
[[
1431946625000
,
15
],
[
1431946626000
,
16
]]
}
}
]
};
]
};
describe
(
'and no alias'
,
function
()
{
describe
(
'and no alias'
,
function
()
{
it
(
'should generate two time series'
,
function
()
{
var
series
=
new
InfluxSeries
(
options
);
it
(
'should generate two time series'
,
function
()
{
var
result
=
series
.
getTimeSeries
(
);
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
.
length
).
to
.
be
(
2
);
expect
(
result
[
0
].
target
).
to
.
be
(
'cpu.mean {app: test, server: server1}'
);
expect
(
result
.
length
).
to
.
be
(
2
);
expect
(
result
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10
);
expect
(
result
[
0
].
target
).
to
.
be
(
'cpu.mean {app: test, server: server1}'
);
expect
(
result
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
143194662500
0
);
expect
(
result
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
1
0
);
expect
(
result
[
0
].
datapoints
[
1
][
0
]).
to
.
be
(
12
);
expect
(
result
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
1431946625000
);
expect
(
result
[
0
].
datapoints
[
1
][
1
]).
to
.
be
(
1431946626000
);
expect
(
result
[
0
].
datapoints
[
1
][
0
]).
to
.
be
(
12
);
expect
(
result
[
0
].
datapoints
[
1
][
1
]).
to
.
be
(
1431946626000
);
expect
(
result
[
1
].
target
).
to
.
be
(
'cpu.mean {app: test2, server: server2}'
);
expect
(
result
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
15
);
expect
(
result
[
1
].
target
).
to
.
be
(
'cpu.mean {app: test2, server: server2}'
);
expect
(
result
[
1
].
datapoints
[
0
][
1
]).
to
.
be
(
1431946625000
);
expect
(
result
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
15
);
expect
(
result
[
1
].
datapoints
[
1
][
0
]).
to
.
be
(
16
);
expect
(
result
[
1
].
datapoints
[
0
][
1
]).
to
.
be
(
1431946625000
);
expect
(
result
[
1
].
datapoints
[
1
][
1
]).
to
.
be
(
1431946626000
);
expect
(
result
[
1
].
datapoints
[
1
][
0
]).
to
.
be
(
16
);
}
);
expect
(
result
[
1
].
datapoints
[
1
][
1
]).
to
.
be
(
1431946626000
);
});
});
});
describe
(
'and simple alias'
,
function
()
{
describe
(
'and simple alias'
,
function
()
{
it
(
'should use alias'
,
function
()
{
it
(
'should use alias'
,
function
()
{
options
.
alias
=
'new series'
;
options
.
alias
=
'new series'
;
var
series
=
new
InfluxSeries
(
options
);
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
be
(
'new series'
);
});
expect
(
result
[
0
].
target
).
to
.
be
(
'new series'
);
});
});
describe
(
'and alias patterns'
,
function
()
{
});
it
(
'should replace patterns'
,
function
()
{
options
.
alias
=
'alias: $m -> $tag_server ([[measurement]])'
;
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
be
(
'alias: cpu -> server1 (cpu)'
);
describe
(
'and alias patterns'
,
function
()
{
expect
(
result
[
1
].
target
).
to
.
be
(
'alias: cpu -> server2 (cpu)'
);
it
(
'should replace patterns'
,
function
()
{
});
options
.
alias
=
'alias: $m -> $tag_server ([[measurement]])'
;
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
be
(
'alias: cpu -> server1 (cpu)'
);
expect
(
result
[
1
].
target
).
to
.
be
(
'alias: cpu -> server2 (cpu)'
);
});
});
});
});
describe
(
'given measurement with dots'
,
function
()
{
});
var
options
=
{
series
:
[
describe
(
'given measurement with dots'
,
function
()
{
var
options
=
{
alias
:
''
,
series
:
[
{
{
name
:
'app.prod.server1.count'
,
name
:
'app.prod.server1.count'
,
tags
:
{},
tags
:
{},
columns
:
[
'time'
,
'mean'
],
columns
:
[
'time'
,
'mean'
],
values
:
[[
1431946625000
,
10
],
[
1431946626000
,
12
]]
values
:
[[
1431946625000
,
10
],
[
1431946626000
,
12
]]
}
}
]};
]
};
it
(
'should replace patterns'
,
function
()
{
it
(
'should replace patterns'
,
function
()
{
options
.
alias
=
'alias: $1 -> [[3]]'
;
options
.
alias
=
'alias: $1 -> [[3]]'
;
var
series
=
new
InfluxSeries
(
options
);
var
series
=
new
InfluxSeries
(
options
);
var
result
=
series
.
getTimeSeries
();
var
result
=
series
.
getTimeSeries
();
expect
(
result
[
0
].
target
).
to
.
be
(
'alias: prod -> count'
);
expect
(
result
[
0
].
target
).
to
.
be
(
'alias: prod -> count'
);
});
});
});
});
});
});
});
public/
test/specs/influx09-querybuilder-specs.j
s
→
public/
app/plugins/datasource/influxdb/specs/query_builder_specs.t
s
View file @
7d2646f6
define
([
///<amd-dependency path="app/plugins/datasource/influxdb/query_builder" name="InfluxQueryBuilder"/>
'app/plugins/datasource/influxdb/queryBuilder'
//
],
function
(
InfluxQueryBuilder
)
{
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
'use strict'
;
describe
(
'InfluxQueryBuilder'
,
function
()
{
declare
var
InfluxQueryBuilder
:
any
;
describe
(
'series with mesurement only'
,
function
()
{
describe
(
'InfluxQueryBuilder'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}]
});
var
query
=
builder
.
build
();
describe
(
'series with mesurement only'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE $timeFilter GROUP BY time($interval)'
);
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}]
});
});
});
describe
(
'series with math expr and as expr'
,
function
()
{
var
query
=
builder
.
build
();
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
fields
:
[{
name
:
'test'
,
func
:
'max'
,
mathExpr
:
'*2'
,
asExpr
:
'new_name'
}],
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE $timeFilter GROUP BY time($interval)'
);
});
});
expect
(
query
).
to
.
be
(
'SELECT max("test")*2 AS "new_name" FROM "cpu" WHERE $timeFilter GROUP BY time($interval)'
);
describe
(
'series with math expr and as expr'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
fields
:
[{
name
:
'test'
,
func
:
'max'
,
mathExpr
:
'*2'
,
asExpr
:
'new_name'
}],
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}]
});
});
});
describe
(
'series with single tag only'
,
function
()
{
var
query
=
builder
.
build
();
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT max("test")*2 AS "new_name" FROM "cpu" WHERE $timeFilter GROUP BY time($interval)'
);
});
});
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "hostname" =
\'
server1
\'
AND $timeFilter'
describe
(
'series with single tag only'
,
function
()
{
+
' GROUP BY time($interval)'
);
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
}]
});
});
it
(
'should switch regex operator with tag value is regex'
,
function
()
{
var
query
=
builder
.
build
();
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[{
key
:
'app'
,
value
:
'/e.*/'
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "hostname" =
\'
server1
\'
AND $timeFilter'
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "app" =~ /e.*/ AND $timeFilter GROUP BY time($interval)'
);
+
' GROUP BY time($interval)'
);
});
});
});
describe
(
'series with multiple fields'
,
function
()
{
it
(
'should switch regex operator with tag value is regex'
,
function
()
{
it
(
'should generate correct query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[],
tags
:
[{
key
:
'app'
,
value
:
'/e.*/'
}]
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
fields
:
[{
name
:
'tx_in'
,
func
:
'sum'
},
{
name
:
'tx_out'
,
func
:
'mean'
}]
});
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT sum("tx_in") AS "tx_in", mean("tx_out") AS "tx_out" '
+
'FROM "cpu" WHERE $timeFilter GROUP BY time($interval)'
);
});
});
});
describe
(
'series with multiple tags only'
,
function
()
{
var
query
=
builder
.
build
();
it
(
'should generate correct query'
,
function
()
{
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "app" =~ /e.*/ AND $timeFilter GROUP BY time($interval)'
);
var
builder
=
new
InfluxQueryBuilder
({
});
measurement
:
'cpu'
,
});
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
},
{
key
:
'app'
,
value
:
'email'
,
condition
:
"AND"
}]
});
var
query
=
builder
.
build
();
describe
(
'series with multiple fields'
,
function
()
{
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "hostname" =
\'
server1
\'
AND "app" =
\'
email
\'
AND '
+
it
(
'should generate correct query'
,
function
()
{
'$timeFilter GROUP BY time($interval)'
);
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[],
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
fields
:
[{
name
:
'tx_in'
,
func
:
'sum'
},
{
name
:
'tx_out'
,
func
:
'mean'
}]
});
});
});
describe
(
'series with tags OR condition'
,
function
()
{
var
query
=
builder
.
build
();
it
(
'should generate correct query'
,
function
()
{
expect
(
query
).
to
.
be
(
'SELECT sum("tx_in") AS "tx_in", mean("tx_out") AS "tx_out" '
+
var
builder
=
new
InfluxQueryBuilder
({
'FROM "cpu" WHERE $timeFilter GROUP BY time($interval)'
);
measurement
:
'cpu'
,
});
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
});
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
},
{
key
:
'hostname'
,
value
:
'server2'
,
condition
:
"OR"
}]
});
var
query
=
builder
.
build
();
describe
(
'series with multiple tags only'
,
function
()
{
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "hostname" =
\'
server1
\'
OR "hostname" =
\'
server2
\'
AND '
+
it
(
'should generate correct query'
,
function
()
{
'$timeFilter GROUP BY time($interval)'
);
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
},
{
key
:
'app'
,
value
:
'email'
,
condition
:
"AND"
}]
});
});
});
describe
(
'series with groupByTag'
,
function
()
{
var
query
=
builder
.
build
();
it
(
'should generate correct query'
,
function
()
{
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "hostname" =
\'
server1
\'
AND "app" =
\'
email
\'
AND '
+
var
builder
=
new
InfluxQueryBuilder
({
'$timeFilter GROUP BY time($interval)'
);
measurement
:
'cpu'
,
});
tags
:
[],
});
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
},
{
type
:
'tag'
,
key
:
'host'
}],
});
var
query
=
builder
.
build
();
describe
(
'series with tags OR condition'
,
function
()
{
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE $timeFilter '
+
it
(
'should generate correct query'
,
function
()
{
'GROUP BY time($interval), "host"'
);
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
}],
tags
:
[{
key
:
'hostname'
,
value
:
'server1'
},
{
key
:
'hostname'
,
value
:
'server2'
,
condition
:
"OR"
}]
});
});
});
describe
(
'when building explore queries'
,
function
()
{
var
query
=
builder
.
build
();
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE "hostname" =
\'
server1
\'
OR "hostname" =
\'
server2
\'
AND '
+
'$timeFilter GROUP BY time($interval)'
);
});
});
it
(
'should only have measurement condition in tag keys query given query with measurement'
,
function
()
{
describe
(
'series with groupByTag'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[]
});
it
(
'should generate correct query'
,
function
()
{
var
query
=
builder
.
buildExploreQuery
(
'TAG_KEYS'
);
var
builder
=
new
InfluxQueryBuilder
({
expect
(
query
).
to
.
be
(
'SHOW TAG KEYS FROM "cpu"'
);
measurement
:
'cpu'
,
tags
:
[],
groupBy
:
[{
type
:
'time'
,
interval
:
'auto'
},
{
type
:
'tag'
,
key
:
'host'
}],
});
});
it
(
'should handle regex measurement in tag keys query'
,
function
()
{
var
query
=
builder
.
build
();
var
builder
=
new
InfluxQueryBuilder
({
expect
(
query
).
to
.
be
(
'SELECT mean("value") AS "value" FROM "cpu" WHERE $timeFilter '
+
measurement
:
'/.*/'
,
'GROUP BY time($interval), "host"'
);
tags
:
[]
});
});
});
var
query
=
builder
.
buildExploreQuery
(
'TAG_KEYS'
);
expect
(
query
).
to
.
be
(
'SHOW TAG KEYS FROM /.*/'
);
});
it
(
'should have no conditions in tags keys query given query with no measurement or tag'
,
function
()
{
describe
(
'when building explore queries'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[]
});
var
query
=
builder
.
buildExploreQuery
(
'TAG_KEYS'
);
expect
(
query
).
to
.
be
(
'SHOW TAG KEYS'
);
});
it
(
'should have where condition in tag keys query with tags
'
,
function
()
{
it
(
'should only have measurement condition in tag keys query given query with measurement
'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[{
key
:
'host'
,
value
:
'se1'
}
]
});
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[
]
});
var
query
=
builder
.
buildExploreQuery
(
'TAG_KEYS'
);
var
query
=
builder
.
buildExploreQuery
(
'TAG_KEYS'
);
expect
(
query
).
to
.
be
(
"SHOW TAG KEYS WHERE
\"
host
\"
= 'se1'"
);
expect
(
query
).
to
.
be
(
'SHOW TAG KEYS FROM "cpu"'
);
});
});
it
(
'should have no conditions in measurement query for query with no tags
'
,
function
()
{
it
(
'should handle regex measurement in tag keys query
'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[]
});
var
builder
=
new
InfluxQueryBuilder
({
var
query
=
builder
.
buildExploreQuery
(
'MEASUREMENTS'
);
measurement
:
'/.*/'
,
expect
(
query
).
to
.
be
(
'SHOW MEASUREMENTS'
);
tags
:
[]
});
});
var
query
=
builder
.
buildExploreQuery
(
'TAG_KEYS'
);
expect
(
query
).
to
.
be
(
'SHOW TAG KEYS FROM /.*/'
);
});
it
(
'should have where condition in measurement query for query with tags
'
,
function
()
{
it
(
'should have no conditions in tags keys query given query with no measurement or tag
'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[{
key
:
'app'
,
value
:
'email'
}]
});
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[]
});
var
query
=
builder
.
buildExploreQuery
(
'MEASUREMENT
S'
);
var
query
=
builder
.
buildExploreQuery
(
'TAG_KEY
S'
);
expect
(
query
).
to
.
be
(
"SHOW MEASUREMENTS WHERE
\"
app
\"
= 'email'"
);
expect
(
query
).
to
.
be
(
'SHOW TAG KEYS'
);
});
});
it
(
'should have where tag name IN filter in tag values query for query with one tag
'
,
function
()
{
it
(
'should have where condition in tag keys query with tags
'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[{
key
:
'app'
,
value
:
'asdsadsad'
}]
});
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[{
key
:
'host'
,
value
:
'se1'
}]
});
var
query
=
builder
.
buildExploreQuery
(
'TAG_VALUES'
,
'app
'
);
var
query
=
builder
.
buildExploreQuery
(
'TAG_KEYS
'
);
expect
(
query
).
to
.
be
(
'SHOW TAG VALUES WITH KEY = "app"'
);
expect
(
query
).
to
.
be
(
"SHOW TAG KEYS WHERE
\"
host
\"
= 'se1'"
);
});
});
it
(
'should have measurement tag condition and tag name IN filter in tag values query
'
,
function
()
{
it
(
'should have no conditions in measurement query for query with no tags
'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[{
key
:
'app'
,
value
:
'email'
},
{
key
:
'host'
,
value
:
'server1'
}]
});
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[]
});
var
query
=
builder
.
buildExploreQuery
(
'TAG_VALUES'
,
'app
'
);
var
query
=
builder
.
buildExploreQuery
(
'MEASUREMENTS
'
);
expect
(
query
).
to
.
be
(
'SHOW TAG VALUES FROM "cpu" WITH KEY = "app" WHERE "host" =
\'
server1
\'
'
);
expect
(
query
).
to
.
be
(
'SHOW MEASUREMENTS
'
);
});
});
it
(
'should switch to regex operator in tag condition
'
,
function
()
{
it
(
'should have where condition in measurement query for query with tags
'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[{
key
:
'host'
,
value
:
'/server.*/
'
}]});
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[{
key
:
'app'
,
value
:
'email
'
}]});
var
query
=
builder
.
buildExploreQuery
(
'TAG_VALUES'
,
'app
'
);
var
query
=
builder
.
buildExploreQuery
(
'MEASUREMENTS
'
);
expect
(
query
).
to
.
be
(
'SHOW TAG VALUES FROM "cpu" WITH KEY = "app" WHERE "host" =~ /server.*/'
);
expect
(
query
).
to
.
be
(
"SHOW MEASUREMENTS WHERE
\"
app
\"
= 'email'"
);
});
});
it
(
'should build show field query'
,
function
()
{
it
(
'should have where tag name IN filter in tag values query for query with one tag'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[{
key
:
'app'
,
value
:
'email'
}]});
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
''
,
tags
:
[{
key
:
'app'
,
value
:
'asdsadsad'
}]});
var
query
=
builder
.
buildExploreQuery
(
'FIELDS'
);
var
query
=
builder
.
buildExploreQuery
(
'TAG_VALUES'
,
'app'
);
expect
(
query
).
to
.
be
(
'SHOW FIELD KEYS FROM "cpu"'
);
expect
(
query
).
to
.
be
(
'SHOW TAG VALUES WITH KEY = "app"'
);
});
});
it
(
'should have measurement tag condition and tag name IN filter in tag values query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[{
key
:
'app'
,
value
:
'email'
},
{
key
:
'host'
,
value
:
'server1'
}]});
var
query
=
builder
.
buildExploreQuery
(
'TAG_VALUES'
,
'app'
);
expect
(
query
).
to
.
be
(
'SHOW TAG VALUES FROM "cpu" WITH KEY = "app" WHERE "host" =
\'
server1
\'
'
);
});
it
(
'should switch to regex operator in tag condition'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[{
key
:
'host'
,
value
:
'/server.*/'
}]});
var
query
=
builder
.
buildExploreQuery
(
'TAG_VALUES'
,
'app'
);
expect
(
query
).
to
.
be
(
'SHOW TAG VALUES FROM "cpu" WITH KEY = "app" WHERE "host" =~ /server.*/'
);
});
it
(
'should build show field query'
,
function
()
{
var
builder
=
new
InfluxQueryBuilder
({
measurement
:
'cpu'
,
tags
:
[{
key
:
'app'
,
value
:
'email'
}]});
var
query
=
builder
.
buildExploreQuery
(
'FIELDS'
);
expect
(
query
).
to
.
be
(
'SHOW FIELD KEYS FROM "cpu"'
);
});
});
});
});
...
...
public/
test/specs/influxdbQueryCtrl-specs.j
s
→
public/
app/plugins/datasource/influxdb/specs/query_ctrl_specs.t
s
View file @
7d2646f6
define
([
///<amd-dependency path="app/plugins/datasource/influxdb/query_ctrl"/>
'./helpers'
,
///<amd-dependency path="app/services/uiSegmentSrv" />
'app/plugins/datasource/influxdb/queryCtrl'
,
///<amd-dependency path="test/specs/helpers" name="helpers" />
'app/services/uiSegmentSrv'
],
function
(
helpers
)
{
'use strict'
;
describe
(
'InfluxDBQueryCtrl'
,
function
()
{
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
var
ctx
=
new
helpers
.
ControllerTestContext
();
beforeEach
(
module
(
'grafana.controllers'
));
declare
var
helpers
:
any
;
beforeEach
(
module
(
'grafana.services'
));
beforeEach
(
ctx
.
providePhase
());
beforeEach
(
ctx
.
createControllerPhase
(
'InfluxQueryCtrl'
));
describe
(
'InfluxDBQueryCtrl'
,
function
()
{
var
ctx
=
new
helpers
.
ControllerTestContext
();
beforeEach
(
angularMocks
.
module
(
'grafana.controllers'
));
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
ctx
.
providePhase
());
beforeEach
(
ctx
.
createControllerPhase
(
'InfluxQueryCtrl'
));
beforeEach
(
function
()
{
ctx
.
scope
.
target
=
{};
ctx
.
scope
.
$parent
=
{
get_data
:
sinon
.
spy
()
};
ctx
.
scope
.
datasource
=
ctx
.
datasource
;
ctx
.
scope
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([]));
});
describe
(
'init'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
});
it
(
'should init tagSegments'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
1
);
});
it
(
'should init measurementSegment'
,
function
()
{
expect
(
ctx
.
scope
.
measurementSegment
.
value
).
to
.
be
(
'select measurement'
);
});
});
describe
(
'when first tag segment is updated'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
});
it
(
'should update tag key'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
[
0
].
key
).
to
.
be
(
'asd'
);
expect
(
ctx
.
scope
.
tagSegments
[
0
].
type
).
to
.
be
(
'key'
);
});
it
(
'should add tagSegments'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
3
);
});
});
describe
(
'when last tag value segment is updated'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
});
it
(
'should update tag value'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
[
0
].
value
).
to
.
be
(
'server1'
);
});
it
(
'should set tag operator'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
[
0
].
operator
).
to
.
be
(
'='
);
});
it
(
'should add plus button for another filter'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
[
3
].
fake
).
to
.
be
(
true
);
});
});
describe
(
'when last tag value segment is updated to regex'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
target
=
{};
ctx
.
scope
.
init
();
ctx
.
scope
.
$parent
=
{
get_data
:
sinon
.
spy
()
};
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'/server.*/'
,
type
:
'value'
},
2
);
});
ctx
.
scope
.
datasource
=
ctx
.
datasource
;
it
(
'should update operator'
,
function
()
{
ctx
.
scope
.
datasource
.
metricFindQuery
=
sinon
.
stub
().
returns
(
ctx
.
$q
.
when
([]));
expect
(
ctx
.
scope
.
tagSegments
[
1
].
value
).
to
.
be
(
'=~'
);
expect
(
ctx
.
scope
.
target
.
tags
[
0
].
operator
).
to
.
be
(
'=~'
);
});
});
});
describe
(
'init'
,
function
()
{
describe
(
'when second tag key is added'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
init
();
});
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
it
(
'should init tagSegments'
,
function
()
{
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'key2'
,
type
:
'plus-button'
},
3
);
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
1
);
});
});
it
(
'should init measurementSegment'
,
function
()
{
expect
(
ctx
.
scope
.
measurementSegment
.
value
).
to
.
be
(
'select measurement'
);
});
});
describe
(
'when first tag segment is updated'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
});
it
(
'should update tag key'
,
function
()
{
it
(
'should update tag key'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
[
0
].
key
).
to
.
be
(
'asd'
);
expect
(
ctx
.
scope
.
target
.
tags
[
1
].
key
).
to
.
be
(
'key2'
);
expect
(
ctx
.
scope
.
tagSegments
[
0
].
type
).
to
.
be
(
'key'
);
});
it
(
'should add tagSegments'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
3
);
});
});
describe
(
'when last tag value segment is updated'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
});
it
(
'should update tag value'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
[
0
].
value
).
to
.
be
(
'server1'
);
});
it
(
'should set tag operator'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
[
0
].
operator
).
to
.
be
(
'='
);
});
it
(
'should add plus button for another filter'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
[
3
].
fake
).
to
.
be
(
true
);
});
});
describe
(
'when last tag value segment is updated to regex'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'/server.*/'
,
type
:
'value'
},
2
);
});
it
(
'should update operator'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
[
1
].
value
).
to
.
be
(
'=~'
);
expect
(
ctx
.
scope
.
target
.
tags
[
0
].
operator
).
to
.
be
(
'=~'
);
});
});
describe
(
'when second tag key is added'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'key2'
,
type
:
'plus-button'
},
3
);
});
it
(
'should update tag key'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
[
1
].
key
).
to
.
be
(
'key2'
);
});
it
(
'should add AND segment'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
[
3
].
value
).
to
.
be
(
'AND'
);
});
});
describe
(
'when condition is changed'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'key2'
,
type
:
'plus-button'
},
3
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'OR'
,
type
:
'condition'
},
3
);
});
it
(
'should update tag condition'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
[
1
].
condition
).
to
.
be
(
'OR'
);
});
it
(
'should update AND segment'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
[
3
].
value
).
to
.
be
(
'OR'
);
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
7
);
});
});
describe
(
'when deleting first tag filter after value is selected'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
(
ctx
.
scope
.
removeTagFilterSegment
,
0
);
});
it
(
'should remove tags'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
.
length
).
to
.
be
(
0
);
});
it
(
'should remove all segment after 2 and replace with plus button'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
1
);
expect
(
ctx
.
scope
.
tagSegments
[
0
].
type
).
to
.
be
(
'plus-button'
);
});
});
describe
(
'when deleting second tag value before second tag value is complete'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'key2'
,
type
:
'plus-button'
},
3
);
ctx
.
scope
.
tagSegmentUpdated
(
ctx
.
scope
.
removeTagFilterSegment
,
4
);
});
it
(
'should remove all segment after 2 and replace with plus button'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
4
);
expect
(
ctx
.
scope
.
tagSegments
[
3
].
type
).
to
.
be
(
'plus-button'
);
});
});
describe
(
'when deleting second tag value before second tag value is complete'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'key2'
,
type
:
'plus-button'
},
3
);
ctx
.
scope
.
tagSegmentUpdated
(
ctx
.
scope
.
removeTagFilterSegment
,
4
);
});
it
(
'should remove all segment after 2 and replace with plus button'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
4
);
expect
(
ctx
.
scope
.
tagSegments
[
3
].
type
).
to
.
be
(
'plus-button'
);
});
});
describe
(
'when deleting second tag value after second tag filter is complete'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'key2'
,
type
:
'plus-button'
},
3
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'value'
,
type
:
'value'
},
6
);
ctx
.
scope
.
tagSegmentUpdated
(
ctx
.
scope
.
removeTagFilterSegment
,
4
);
});
it
(
'should remove all segment after 2 and replace with plus button'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
4
);
expect
(
ctx
.
scope
.
tagSegments
[
3
].
type
).
to
.
be
(
'plus-button'
);
});
});
});
it
(
'should add AND segment'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
[
3
].
value
).
to
.
be
(
'AND'
);
});
});
});
describe
(
'when condition is changed'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'key2'
,
type
:
'plus-button'
},
3
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'OR'
,
type
:
'condition'
},
3
);
});
it
(
'should update tag condition'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
[
1
].
condition
).
to
.
be
(
'OR'
);
});
it
(
'should update AND segment'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
[
3
].
value
).
to
.
be
(
'OR'
);
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
7
);
});
});
describe
(
'when deleting first tag filter after value is selected'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
(
ctx
.
scope
.
removeTagFilterSegment
,
0
);
});
it
(
'should remove tags'
,
function
()
{
expect
(
ctx
.
scope
.
target
.
tags
.
length
).
to
.
be
(
0
);
});
it
(
'should remove all segment after 2 and replace with plus button'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
1
);
expect
(
ctx
.
scope
.
tagSegments
[
0
].
type
).
to
.
be
(
'plus-button'
);
});
});
describe
(
'when deleting second tag value before second tag value is complete'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'key2'
,
type
:
'plus-button'
},
3
);
ctx
.
scope
.
tagSegmentUpdated
(
ctx
.
scope
.
removeTagFilterSegment
,
4
);
});
it
(
'should remove all segment after 2 and replace with plus button'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
4
);
expect
(
ctx
.
scope
.
tagSegments
[
3
].
type
).
to
.
be
(
'plus-button'
);
});
});
describe
(
'when deleting second tag value before second tag value is complete'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'key2'
,
type
:
'plus-button'
},
3
);
ctx
.
scope
.
tagSegmentUpdated
(
ctx
.
scope
.
removeTagFilterSegment
,
4
);
});
it
(
'should remove all segment after 2 and replace with plus button'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
4
);
expect
(
ctx
.
scope
.
tagSegments
[
3
].
type
).
to
.
be
(
'plus-button'
);
});
});
describe
(
'when deleting second tag value after second tag filter is complete'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
scope
.
init
();
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'asd'
,
type
:
'plus-button'
},
0
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'server1'
,
type
:
'value'
},
2
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'key2'
,
type
:
'plus-button'
},
3
);
ctx
.
scope
.
tagSegmentUpdated
({
value
:
'value'
,
type
:
'value'
},
6
);
ctx
.
scope
.
tagSegmentUpdated
(
ctx
.
scope
.
removeTagFilterSegment
,
4
);
});
it
(
'should remove all segment after 2 and replace with plus button'
,
function
()
{
expect
(
ctx
.
scope
.
tagSegments
.
length
).
to
.
be
(
4
);
expect
(
ctx
.
scope
.
tagSegments
[
3
].
type
).
to
.
be
(
'plus-button'
);
});
});
});
});
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