Skip to content

Commit

Permalink
Merge pull request #73 from digitronik/ndhandre/charts_pf6
Browse files Browse the repository at this point in the history
PF6: charts
  • Loading branch information
digitronik authored Feb 11, 2025
2 parents a055c2d + aba2d1c commit 062dc62
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 32 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: wt.pf5 tests
name: tests

on:
push:
Expand All @@ -10,13 +10,14 @@ on:

jobs:
test:
name: 🐍 Tests (python-${{ matrix.python-version }}, ${{ matrix.browser }})
name: wt-${{ matrix.pf-version }} (🐍-${{ matrix.python-version }}, ${{ matrix.browser }})
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
browser: [chrome, firefox]
python-version: ["3.11", "3.12", "3.13"]
python-version: ["3.12", "3.13"]
pf-version: ["v5", "v6"]
steps:
- name: Pull selenium-standalone
run: podman pull selenium/standalone-${{ matrix.browser }}:4.9
Expand All @@ -30,11 +31,12 @@ jobs:
pip install .[dev]
- name: Test with pytest
run: |
pytest -v -n 5 --browser-name=${{ matrix.browser }} --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.xml
flags: unittests
name: ${{ github.run_id }}-py-${{ matrix.python-version }}-${{ matrix.browser }}
pytest -sqvvv -n 2 --browser-name=${{ matrix.browser }} --pf-version=${{ matrix.pf-version }} testing/charts
# pytest -v -n 5 --browser-name=${{ matrix.browser }} --cov=./ --cov-report=xml
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v4
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# file: coverage.xml
# flags: unittests
# name: ${{ github.run_id }}-py-${{ matrix.python-version }}-${{ matrix.browser }}
12 changes: 11 additions & 1 deletion src/widgetastic_patternfly5/charts/line_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,17 @@ def read(self, offset=(0, -100)):
self.browser.elements(self.TOOLTIP_LABLES, parent=tooltip_el),
self.browser.elements(self.TOOLTIP_VALUES, parent=tooltip_el),
):
label_data[self.browser.text(label_el)] = self.browser.text(value_el)
# Get the label text and handle empty labels
label_txt = self.browser.text(label_el)
if label_txt == "":
label_txt = "Unknown"

# Update label_data with the value
value_txt = self.browser.text(value_el)
if label_txt in label_data:
label_data[label_txt] = f"{label_data[label_txt]}, {value_txt}"
else:
label_data[label_txt] = value_txt

_data[x_axis_label] = label_data

Expand Down
7 changes: 4 additions & 3 deletions testing/charts/test_alert_timeline_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from widgetastic_patternfly5.charts.alerts_timeline_chart import AlertsTimelineChart

TESTING_PAGE_URL = "https://v5-archive.patternfly.org/charts/bar-chart"
TESTING_PAGE_COMPONENT = "charts/bar-chart/react/alerts-timeline"


TEST_DATE_FORMAT = "%Y-%m-%dT%H:%M:%S"
LABEL_DATE_FORMAT = "%b %-d %H:%M:%S"
Expand Down Expand Up @@ -201,7 +202,7 @@
def view(browser):
class TestView(View):
ROOT = ".//div[@id='ws-react-c-bar-chart-alerts-timeline']"
chart = AlertsTimelineChart(locator=".//div[@class='pf-v5-c-chart']")
chart = AlertsTimelineChart(locator=".//div[contains(@class, '-c-chart')]")

return TestView(browser)

Expand All @@ -225,7 +226,7 @@ def test_alert_timeline(view):
# get data point and check values
danger_legend = view.chart.get_legend("Danger")
assert danger_legend.label == "Danger"
assert danger_legend.color == "rgb(201, 25, 11)"
assert danger_legend.color in ["rgb(201, 25, 11)", "rgb(177, 56, 11)"] # [pf5, pf6]

# read graph
chart_read = view.chart.read()
Expand Down
12 changes: 6 additions & 6 deletions testing/charts/test_boxplot_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

from widgetastic_patternfly5 import BoxPlotChart

TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/charts/box-plot-chart"
TESTING_PAGE_COMPONENT = "charts/box-plot-chart/react/embedded-legend"

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"},
"2015": {"Limit": "12", "Cats": "no data"},
"2016": {"Limit": "12", "Cats": "Min: 2, Max: 10", "Unknown": "Median: 5.5, Q1: 2.75, Q3: 8.5"},
"2017": {"Limit": "12", "Cats": "Min: 2, Max: 8", "Unknown": "Median: 5.5, Q1: 4.25, Q3: 6.5"},
"2018": {"Limit": "12", "Cats": "Min: 1, Max: 9", "Unknown": "Median: 2.5, Q1: 1.75, Q3: 4.5"},
}


@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']")
chart = BoxPlotChart(locator=".//div[contains(@class, '-c-chart')]")

return TestView(browser)

Expand Down
6 changes: 3 additions & 3 deletions testing/charts/test_bullet_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from widgetastic_patternfly5 import BulletChart
from widgetastic_patternfly5.charts.bullet_chart import DataPoint

TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/charts/bullet-chart"
TESTING_PAGE_COMPONENT = "charts/bullet-chart"

Legend = namedtuple("Legend", ["label", "value"])

Expand Down Expand Up @@ -85,12 +85,12 @@ def test_bullet_chart(chart_data):
warning_data = chart.get_data_point("Warning")
expected_value = 88 if chart_type == "dot" else 80
assert warning_data.value == expected_value
assert warning_data.color == "rgb(236, 122, 8)"
assert warning_data.color in ["rgb(236, 122, 8)", "rgb(245, 146, 27)"] # [pf5, pf6]
# get bar with wrong label
assert not chart.get_data_point("foo")
# get legend for check values
warning_legend = chart.get_legend("Warning")
assert warning_legend.value is None
assert warning_legend.color == "rgb(236, 122, 8)"
assert warning_legend.color in ["rgb(236, 122, 8)", "rgb(245, 146, 27)"] # [pf5, pf6]
# get legend with wrong label
assert not chart.get_legend("foo")
4 changes: 2 additions & 2 deletions testing/charts/test_donut_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

from widgetastic_patternfly5 import DonutChart

TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/charts/donut-chart"
TESTING_PAGE_COMPONENT = "charts/donut-chart/react/bottom-aligned-legend"


@pytest.fixture
def donut_chart(browser):
class TestView(View):
ROOT = ".//div[@id='ws-react-c-donut-chart-right-aligned-legend']"
ROOT = ".//div[@id='ws-react-c-donut-chart-bottom-aligned-legend']"
donut_chart = DonutChart(locator="./div")

return TestView(browser).donut_chart
Expand Down
6 changes: 3 additions & 3 deletions testing/charts/test_line_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from widgetastic_patternfly5 import LineChart

TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/charts/line-chart"
TESTING_PAGE_COMPONENT = "charts/line-chart/react/green-with-bottom-aligned-legend"

TEST_DATA = {
"2015": {"Cats": "1", "Dogs": "2", "Birds": "3", "Mice": "3"},
Expand All @@ -17,7 +17,7 @@
def view(browser):
class TestView(View):
ROOT = ".//div[@id='ws-react-c-line-chart-green-with-bottom-aligned-legend']"
chart = LineChart(locator=".//div[@class='pf-v5-c-chart']")
chart = LineChart(locator=".//div[contains(@class, '-c-chart')]")

return TestView(browser)

Expand All @@ -38,7 +38,7 @@ def test_line_chart(view):
# get data point and check values
birds_legend = view.chart.get_legend("Birds")
assert birds_legend.label == "Birds"
assert birds_legend.color == "rgb(35, 81, 30)"
assert birds_legend.color in ["rgb(35, 81, 30)", "rgb(32, 77, 0)"] # [pf5, pf6]

# read graph
assert view.chart.read() == TEST_DATA
2 changes: 1 addition & 1 deletion testing/charts/test_pie_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from widgetastic_patternfly5 import DataPoint, PieChart

TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/charts/pie-chart"
TESTING_PAGE_COMPONENT = "charts/pie-chart"

Legend = namedtuple("Legend", ["label", "value"])
DATA = {"Cats": 35, "Dogs": 55, "Birds": 10}
Expand Down
22 changes: 20 additions & 2 deletions testing/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import subprocess
from urllib.parse import urljoin
from urllib.request import urlopen

import pytest
Expand All @@ -8,6 +9,10 @@
from widgetastic.browser import Browser

OPTIONS = {"firefox": webdriver.FirefoxOptions(), "chrome": webdriver.ChromeOptions()}
TESTING_PAGES = {
"v6": "https://www.patternfly.org",
"v5": "https://v5-archive.patternfly.org",
}


def pytest_addoption(parser):
Expand All @@ -17,6 +22,12 @@ def pytest_addoption(parser):
choices=("firefox", "chrome"),
default="firefox",
)
parser.addoption(
"--pf-version",
help="Patternfly Version",
choices=("v6", "v5"),
default="v6",
)

parser.addoption("--force-host", default=None, help="force a selenium hostname")

Expand All @@ -26,6 +37,11 @@ def browser_name(pytestconfig):
return os.environ.get("BROWSER") or pytestconfig.getoption("--browser-name")


@pytest.fixture(scope="session")
def pf_version(pytestconfig):
return os.environ.get("PF-VERSION") or pytestconfig.getoption("--pf-version")


@pytest.fixture(scope="session")
def selenium_url(pytestconfig, browser_name, worker_id):
forced_host = pytestconfig.getoption("--force-host")
Expand Down Expand Up @@ -78,8 +94,10 @@ def selenium(browser_name, wait_for_selenium, selenium_url):


@pytest.fixture(scope="module")
def browser(selenium, request):
selenium.get(request.module.TESTING_PAGE_URL)
def browser(selenium, pf_version, request):
testing_page_url = urljoin(TESTING_PAGES.get(pf_version), request.module.TESTING_PAGE_COMPONENT)
selenium.get(testing_page_url)
print(f"Testing page: {testing_page_url}")
browser = Browser(selenium)
if browser.elements(".//button[@aria-label='Close banner']"):
browser.click(".//button[@aria-label='Close banner']")
Expand Down

0 comments on commit 062dc62

Please sign in to comment.