-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from widgetastic.widget import ParametrizedLocator | ||
from widgetastic.widget import View | ||
|
||
from .legend import Legend | ||
from widgetastic_patternfly5.charts.line_chart import LineChart | ||
|
||
|
||
class BoxPlotChart(LineChart): | ||
"""Represents the Patternfly Line Chart. | ||
https://patternfly-react-main.surge.sh/charts/box-plot-chart#embedded-legend | ||
Args: | ||
id: If you want to look the input up by id, use this parameter, pass the id. | ||
locator: If you have specific locator else it will take pf-chart. | ||
""" | ||
|
||
ROOT = ParametrizedLocator("{@locator}") | ||
|
||
X_AXIS_LABELS = "(.//*[name()='g' and *[name()='line'] and *[name()='g']])[1]//*[name()='text']" | ||
Y_AXIS_LABELS = "(.//*[name()='g' and *[name()='line'] and *[name()='g']])[2]//*[name()='text']" | ||
|
||
TOOLTIP = ( | ||
".//*[name()='g' and .//*[name()='g' and " | ||
".//*[name()='text' and contains(@id, 'legend-labels')]]]" | ||
) | ||
|
||
TOOLTIP_X_AXIS_LABLE = ".//*[name()='text']" | ||
TOOLTIP_LABLES = ".//*[name()='g']/*[name()='text' and not(contains(@id, 'legend-label'))]" | ||
TOOLTIP_VALUES = ".//*[name()='g']/*[name()='text' and contains(@id, 'legend-label')]" | ||
|
||
_legends = View.nested(Legend) | ||
|
||
def __init__(self, parent=None, id=None, locator=None, logger=None): | ||
View.__init__(self, parent=parent, logger=logger) | ||
|
||
assert id or locator, "Provide id or locator." | ||
|
||
if id: | ||
self.locator = f".//div[@id='{id}']" | ||
else: | ||
self.locator = locator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
from widgetastic.widget import View | ||
|
||
from widgetastic_patternfly5 import BoxPlotChart | ||
|
||
TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/charts/box-plot-chart" | ||
|
||
TEST_DATA = { | ||
"2015": {"Cats": "q1: 1.75, q3: 3.5", "Limit": "12"}, | ||
"2016": {"Cats": "q1: 2.75, q3: 8.5", "Limit": "12"}, | ||
"2017": {"Cats": "q1: 4.25, q3: 6.5", "Limit": "12"}, | ||
"2018": {"Cats": "q1: 1.75, q3: 4.5", "Limit": "12"}, | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def view(browser): | ||
class TestView(View): | ||
ROOT = ".//div[@id='ws-react-c-box-plot-chart-embedded-legend']" | ||
chart = BoxPlotChart(locator=".//div[@class='pf-v5-c-chart']") | ||
|
||
return TestView(browser) | ||
|
||
|
||
def test_boxplot_chart(view): | ||
legend_names = view.chart.legend_names | ||
|
||
# check chart is displayed | ||
assert view.chart.is_displayed | ||
|
||
# validate chart data | ||
assert view.chart.read() == TEST_DATA | ||
|
||
expected_legend_names = list(TEST_DATA.values())[0].keys() | ||
|
||
# validate legend names | ||
assert set(legend_names) == set(expected_legend_names) | ||
|
||
# validate x-axis keys | ||
assert view.chart.labels_x_axis == list(TEST_DATA.keys()) | ||
|
||
# Validate Legends | ||
cats_legend = view.chart.get_legend("Cats") | ||
assert cats_legend.label == "Cats" |