test_metric_indicator.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. import inspect
  12. from importlib import util
  13. import pytest
  14. if util.find_spec("playwright"):
  15. from playwright._impl._page import Page
  16. from taipy.gui import Gui
  17. @pytest.mark.extension
  18. def test_has_default_value(page: Page, gui: Gui, helpers):
  19. page_md = """
  20. <|100|metric|>
  21. """
  22. gui._set_frame(inspect.currentframe())
  23. gui.add_page(name="test", page=page_md)
  24. helpers.run_e2e(gui)
  25. page.goto("./test")
  26. page.wait_for_selector(".plot-container")
  27. events_list = page.locator("//*[@class='js-plotly-plot']//*[name()='svg'][2]//*[local-name()='text']")
  28. gauge_value = events_list.nth(0).text_content()
  29. assert gauge_value == "100"
  30. @pytest.mark.extension
  31. def test_show_increase_delta_value(page: Page, gui: Gui, helpers):
  32. page_md = """
  33. <|100|metric|delta=20|type=linear|>
  34. """
  35. gui._set_frame(inspect.currentframe())
  36. gui.add_page(name="test", page=page_md)
  37. helpers.run_e2e(gui)
  38. page.goto("./test")
  39. page.wait_for_selector(".plot-container")
  40. events_list = page.locator("//*[@class='js-plotly-plot']//*[name()='svg'][2]//*[local-name()='text']")
  41. delta_value = events_list.nth(1).text_content()
  42. assert delta_value == "▲20"
  43. @pytest.mark.extension
  44. def test_show_decrease_delta_value(page: Page, gui: Gui, helpers):
  45. page_md = """
  46. <|100|metric|delta=-20|type=linear|>
  47. """
  48. gui._set_frame(inspect.currentframe())
  49. gui.add_page(name="test", page=page_md)
  50. helpers.run_e2e(gui)
  51. page.goto("./test")
  52. page.wait_for_selector(".plot-container")
  53. events_list = page.locator("//*[@class='js-plotly-plot']//*[name()='svg'][2]//*[local-name()='text']")
  54. delta_value = events_list.nth(1).text_content()
  55. assert delta_value == "▼−20"
  56. @pytest.mark.extension
  57. def test_show_linear_chart(page: Page, gui: Gui, helpers):
  58. page_md = """
  59. <|100|metric|delta=-20|type=linear|>
  60. """
  61. gui._set_frame(inspect.currentframe())
  62. gui.add_page(name="test", page=page_md)
  63. helpers.run_e2e(gui)
  64. page.goto("./test")
  65. page.wait_for_selector(".plot-container")
  66. chart = page.locator("//*[@class='js-plotly-plot']//*[name()='svg'][2]//*[@class='bullet']")
  67. assert chart.is_visible()
  68. @pytest.mark.extension
  69. def test_show_circular_chart_as_default_type(page: Page, gui: Gui, helpers):
  70. page_md = """
  71. <|100|metric|>
  72. """
  73. gui._set_frame(inspect.currentframe())
  74. gui.add_page(name="test", page=page_md)
  75. helpers.run_e2e(gui)
  76. page.goto("./test")
  77. page.wait_for_selector(".plot-container")
  78. chart = page.locator("//*[@class='js-plotly-plot']//*[name()='svg'][2]//*[@class='angular']")
  79. assert chart.is_visible()