Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
76c69ef9
Commit
76c69ef9
authored
6 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Add series name test case to LineAreaBarRenderer-bar.unit.spec.js
parent
044755a8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/test/metabase/visualizations/components/LineAreaBarRenderer-bar.unit.spec.js
+151
-82
151 additions, 82 deletions
...lizations/components/LineAreaBarRenderer-bar.unit.spec.js
with
151 additions
and
82 deletions
frontend/test/metabase/visualizations/components/LineAreaBarRenderer-bar.unit.spec.js
+
151
−
82
View file @
76c69ef9
...
...
@@ -13,10 +13,50 @@ const DEFAULT_SETTINGS = {
"
graph.x_axis.axis_enabled
"
:
true
,
"
graph.y_axis.axis_enabled
"
:
true
,
"
graph.colors
"
:
[
"
#00FF00
"
,
"
#FF0000
"
],
series
:
()
=>
({
display
:
"
bar
"
})
,
column
:
()
=>
({
date_style
:
"
MMMM D, YYYY
"
})
,
series
:
()
=>
DEFAULT_SERIES_SETTINGS
,
column
:
()
=>
DEFAULT_COLUMN_SETTINGS
,
};
const
DEFAULT_SERIES_SETTINGS
=
{
display
:
"
bar
"
,
};
const
DEFAULT_COLUMN_SETTINGS
=
{
date_style
:
"
MMMM D, YYYY
"
,
};
function
MainSeries
(
chartType
,
settings
=
{})
{
return
{
card
:
{
display
:
chartType
,
visualization_settings
:
{
...
DEFAULT_SETTINGS
,
...
settings
,
},
},
data
:
{
cols
:
[
StringColumn
({
display_name
:
"
Category
"
,
source
:
"
breakout
"
}),
NumberColumn
({
display_name
:
"
Sum
"
,
source
:
"
aggregation
"
}),
],
rows
:
[[
"
A
"
,
1
]],
},
};
}
function
ExtraSeries
()
{
return
{
card
:
{},
data
:
{
cols
:
[
StringColumn
({
display_name
:
"
Category
"
,
source
:
"
breakout
"
}),
NumberColumn
({
display_name
:
"
Count
"
,
source
:
"
aggregation
"
}),
],
rows
:
[[
"
A
"
,
2
]],
},
};
}
describe
(
"
LineAreaBarRenderer-bar
"
,
()
=>
{
let
element
;
const
qsa
=
selector
=>
[...
element
.
querySelectorAll
(
selector
)];
...
...
@@ -33,86 +73,115 @@ describe("LineAreaBarRenderer-bar", () => {
document
.
body
.
removeChild
(
document
.
getElementById
(
"
fixture
"
));
});
[
"
area
"
,
"
bar
"
].
forEach
(
chartType
=>
[
"
stacked
"
,
"
normalized
"
].
forEach
(
stack_type
=>
// FIXME: failing on CI
it
(
`should render a
${
stack_type
||
""
}
${
chartType
}
chart with 2 series`
,
()
=>
{
const
onHoverChange
=
jest
.
fn
();
renderLineAreaBar
(
element
,
[
{
card
:
{
display
:
chartType
,
visualization_settings
:
{
...
DEFAULT_SETTINGS
,
"
stackable.stack_type
"
:
stack_type
,
},
},
data
:
{
cols
:
[
StringColumn
({
display_name
:
"
Category
"
,
source
:
"
breakout
"
,
}),
NumberColumn
({
display_name
:
"
Sum
"
,
source
:
"
aggregation
"
,
}),
],
rows
:
[[
"
A
"
,
1
]],
},
},
{
card
:
{},
data
:
{
cols
:
[
StringColumn
({
display_name
:
"
Category
"
,
source
:
"
breakout
"
,
}),
NumberColumn
({
display_name
:
"
Count
"
,
source
:
"
aggregation
"
,
}),
],
rows
:
[[
"
A
"
,
2
]],
},
},
],
{
onHoverChange
,
},
);
// hover over each bar
dispatchUIEvent
(
qsa
(
"
.bar, .dot
"
)[
0
],
"
mousemove
"
);
dispatchUIEvent
(
qsa
(
"
.bar, .dot
"
)[
1
],
"
mousemove
"
);
const
{
calls
}
=
onHoverChange
.
mock
;
if
(
stack_type
===
"
normalized
"
)
{
expect
(
getDataKeyValues
(
calls
[
0
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
% Sum
"
,
value
:
"
33%
"
},
]);
expect
(
getDataKeyValues
(
calls
[
1
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
% Count
"
,
value
:
"
67%
"
},
]);
}
else
{
expect
(
getDataKeyValues
(
calls
[
0
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
Sum
"
,
value
:
1
},
]);
expect
(
getDataKeyValues
(
calls
[
1
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
Count
"
,
value
:
2
},
]);
}
}),
),
);
it
(
`should render an bar chart with 1 series`
,
()
=>
{
const
onHoverChange
=
jest
.
fn
();
renderLineAreaBar
(
element
,
[
MainSeries
(
"
bar
"
)],
{
onHoverChange
,
});
// hover over each bar
dispatchUIEvent
(
qsa
(
"
.bar, .dot
"
)[
0
],
"
mousemove
"
);
const
{
calls
}
=
onHoverChange
.
mock
;
expect
(
getDataKeyValues
(
calls
[
0
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
Sum
"
,
value
:
1
},
]);
});
it
(
`should render an bar chart with 2 series`
,
()
=>
{
const
onHoverChange
=
jest
.
fn
();
renderLineAreaBar
(
element
,
[
MainSeries
(
"
bar
"
),
ExtraSeries
()],
{
onHoverChange
,
});
// hover over each bar
dispatchUIEvent
(
qsa
(
"
.bar, .dot
"
)[
0
],
"
mousemove
"
);
dispatchUIEvent
(
qsa
(
"
.bar, .dot
"
)[
1
],
"
mousemove
"
);
const
{
calls
}
=
onHoverChange
.
mock
;
expect
(
getDataKeyValues
(
calls
[
0
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
Sum
"
,
value
:
1
},
]);
expect
(
getDataKeyValues
(
calls
[
1
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
Count
"
,
value
:
2
},
]);
});
it
(
`should render an bar stacked chart with 2 series`
,
()
=>
{
const
onHoverChange
=
jest
.
fn
();
renderLineAreaBar
(
element
,
[
MainSeries
(
"
bar
"
,
{
"
stackable.stack_type
"
:
"
stacked
"
}),
ExtraSeries
()],
{
onHoverChange
,
},
);
// hover over each bar
dispatchUIEvent
(
qsa
(
"
.bar, .dot
"
)[
0
],
"
mousemove
"
);
dispatchUIEvent
(
qsa
(
"
.bar, .dot
"
)[
1
],
"
mousemove
"
);
const
{
calls
}
=
onHoverChange
.
mock
;
expect
(
getDataKeyValues
(
calls
[
0
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
Sum
"
,
value
:
1
},
]);
expect
(
getDataKeyValues
(
calls
[
1
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
Count
"
,
value
:
2
},
]);
});
it
(
`should render an bar normalized chart with 2 series`
,
()
=>
{
const
onHoverChange
=
jest
.
fn
();
renderLineAreaBar
(
element
,
[
MainSeries
(
"
bar
"
,
{
"
stackable.stack_type
"
:
"
normalized
"
}),
ExtraSeries
(),
],
{
onHoverChange
},
);
// hover over each bar
dispatchUIEvent
(
qsa
(
"
.bar, .dot
"
)[
0
],
"
mousemove
"
);
dispatchUIEvent
(
qsa
(
"
.bar, .dot
"
)[
1
],
"
mousemove
"
);
const
{
calls
}
=
onHoverChange
.
mock
;
expect
(
getDataKeyValues
(
calls
[
0
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
% Sum
"
,
value
:
"
33%
"
},
]);
expect
(
getDataKeyValues
(
calls
[
1
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
% Count
"
,
value
:
"
67%
"
},
]);
});
it
(
"
should replace the aggregation name with the series name
"
,
()
=>
{
const
onHoverChange
=
jest
.
fn
();
renderLineAreaBar
(
element
,
[
MainSeries
(
"
bar
"
,
{
series
:
()
=>
({
...
DEFAULT_SERIES_SETTINGS
,
title
:
"
Foo
"
}),
}),
],
{
onHoverChange
},
);
// hover over each bar
dispatchUIEvent
(
qsa
(
"
.bar, .dot
"
)[
0
],
"
mousemove
"
);
const
{
calls
}
=
onHoverChange
.
mock
;
expect
(
getDataKeyValues
(
calls
[
0
][
0
])).
toEqual
([
{
key
:
"
Category
"
,
value
:
"
A
"
},
{
key
:
"
Foo
"
,
value
:
1
},
]);
});
});
function
getDataKeyValues
(
hover
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment