Skip to content

Commit

Permalink
Merge pull request #612 from antip00/master
Browse files Browse the repository at this point in the history
Adding tests for query options.
  • Loading branch information
Slach authored Aug 15, 2024
2 parents fa312d6 + 0c94250 commit ab4ccd8
Show file tree
Hide file tree
Showing 7 changed files with 409 additions and 25 deletions.
1 change: 1 addition & 0 deletions tests/testflows/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def regression(self, before, after):
Feature(run=load("testflows.tests.automated.sql_editor", "feature"))
Feature(run=load("testflows.tests.automated.data_source_setup", "feature"))
Feature(run=load("testflows.tests.automated.e2e", "feature"))
Feature(run=load("testflows.tests.automated.query_settings", "feature"))


if main():
Expand Down
18 changes: 13 additions & 5 deletions tests/testflows/requirements/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
* 29.4 [RQ.SRS.Plugin.QueryOptions.Interval](#rqsrspluginqueryoptionsinterval)
* 29.5 [RQ.SRS.Plugin.QueryOptions.RelativeTime](#rqsrspluginqueryoptionsrelativetime)
* 29.6 [RQ.SRS.Plugin.QueryOptions.TimeShift](#rqsrspluginqueryoptionstimeshift)
* 29.7 [RQ.SRS.Plugin.QueryOptions.HideTimeInfo](#rqsrspluginqueryoptionshidetimeinfo)
* 30 [Raw SQL Editor](#raw-sql-editor)
* 30.1 [RQ.SRS.Plugin.RawSQLEditorInterface](#rqsrspluginrawsqleditorinterface)
* 30.2 [RQ.SRS.Plugin.RawSQLEditorInterface.SQLEditor](#rqsrspluginrawsqleditorinterfacesqleditor)
Expand Down Expand Up @@ -480,11 +481,12 @@ version: 1.0

The [Plugin] SHALL support the following options for the query:

* `Max data points` - text field that defines the maximum data points per series
* `Min interval` - text field that defines a lower limit for the interval
* `Interval` - invariable text field. It is the evaluated interval that is sent to the data source and is used in $__interval and $__interval_ms
* `Relative time` - text field that overrides the relative time range for individual panel
* `Time shift` - text field that overrides the time range for individual panel by shifting its start and end relative to the time picker.
* `Max data points`
* `Min interval`
* `Interval`
* `Relative time`
* `Time shift`
* `Hide time info`

![query options](https://github.com/antip00/clickhouse-grafana/blob/master/tests/testflows/requirements/images/query%20options.png)

Expand Down Expand Up @@ -517,6 +519,12 @@ The [Plugin] SHALL support specifying time shift using `Time shift` text field.
This relative time SHALL override the time range for individual panel
by shifting its start and end relative to the time picker.

### RQ.SRS.Plugin.QueryOptions.HideTimeInfo
version: 1.0

The [Plugin] SHALL support `Hide time info` toggle.
This toggle SHALL hide time info regarding relative time and time shift in panel title if turned on.

## Raw SQL Editor

### RQ.SRS.Plugin.RawSQLEditorInterface
Expand Down
48 changes: 38 additions & 10 deletions tests/testflows/requirements/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,12 @@
description=(
'The [Plugin] SHALL support the following options for the query:\n'
'\n'
'* `Max data points` - text field that defines the maximum data points per series\n'
'* `Min interval` - text field that defines a lower limit for the interval\n'
'* `Interval` - invariable text field. It is the evaluated interval that is sent to the data source and is used in $__interval and $__interval_ms\n'
'* `Relative time` - text field that overrides the relative time range for individual panel\n'
'* `Time shift` - text field that overrides the time range for individual panel by shifting its start and end relative to the time picker.\n'
'* `Max data points`\n'
'* `Min interval`\n'
'* `Interval`\n'
'* `Relative time`\n'
'* `Time shift`\n'
'* `Hide time info`\n'
'\n'
'![query options](https://github.com/antip00/clickhouse-grafana/blob/master/tests/testflows/requirements/images/query%20options.png)\n'
'\n'
Expand Down Expand Up @@ -755,6 +756,23 @@
num='29.6'
)

RQ_SRS_Plugin_QueryOptions_HideTimeInfo = Requirement(
name='RQ.SRS.Plugin.QueryOptions.HideTimeInfo',
version='1.0',
priority=None,
group=None,
type=None,
uid=None,
description=(
'The [Plugin] SHALL support `Hide time info` toggle. \n'
'This toggle SHALL hide time info regarding relative time and time shift in panel title if turned on. \n'
'\n'
),
link=None,
level=2,
num='29.7'
)

RQ_SRS_Plugin_RawSQLEditorInterface = Requirement(
name='RQ.SRS.Plugin.RawSQLEditorInterface',
version='1.0',
Expand Down Expand Up @@ -1895,6 +1913,7 @@
Heading(name='RQ.SRS.Plugin.QueryOptions.Interval', level=2, num='29.4'),
Heading(name='RQ.SRS.Plugin.QueryOptions.RelativeTime', level=2, num='29.5'),
Heading(name='RQ.SRS.Plugin.QueryOptions.TimeShift', level=2, num='29.6'),
Heading(name='RQ.SRS.Plugin.QueryOptions.HideTimeInfo', level=2, num='29.7'),
Heading(name='Raw SQL Editor', level=1, num='30'),
Heading(name='RQ.SRS.Plugin.RawSQLEditorInterface', level=2, num='30.1'),
Heading(name='RQ.SRS.Plugin.RawSQLEditorInterface.SQLEditor', level=2, num='30.2'),
Expand Down Expand Up @@ -2010,6 +2029,7 @@
RQ_SRS_Plugin_QueryOptions_Interval,
RQ_SRS_Plugin_QueryOptions_RelativeTime,
RQ_SRS_Plugin_QueryOptions_TimeShift,
RQ_SRS_Plugin_QueryOptions_HideTimeInfo,
RQ_SRS_Plugin_RawSQLEditorInterface,
RQ_SRS_Plugin_RawSQLEditorInterface_SQLEditor,
RQ_SRS_Plugin_RawSQLEditorInterface_AddMetadata,
Expand Down Expand Up @@ -2145,6 +2165,7 @@
* 29.4 [RQ.SRS.Plugin.QueryOptions.Interval](#rqsrspluginqueryoptionsinterval)
* 29.5 [RQ.SRS.Plugin.QueryOptions.RelativeTime](#rqsrspluginqueryoptionsrelativetime)
* 29.6 [RQ.SRS.Plugin.QueryOptions.TimeShift](#rqsrspluginqueryoptionstimeshift)
* 29.7 [RQ.SRS.Plugin.QueryOptions.HideTimeInfo](#rqsrspluginqueryoptionshidetimeinfo)
* 30 [Raw SQL Editor](#raw-sql-editor)
* 30.1 [RQ.SRS.Plugin.RawSQLEditorInterface](#rqsrspluginrawsqleditorinterface)
* 30.2 [RQ.SRS.Plugin.RawSQLEditorInterface.SQLEditor](#rqsrspluginrawsqleditorinterfacesqleditor)
Expand Down Expand Up @@ -2549,11 +2570,12 @@
The [Plugin] SHALL support the following options for the query:
* `Max data points` - text field that defines the maximum data points per series
* `Min interval` - text field that defines a lower limit for the interval
* `Interval` - invariable text field. It is the evaluated interval that is sent to the data source and is used in $__interval and $__interval_ms
* `Relative time` - text field that overrides the relative time range for individual panel
* `Time shift` - text field that overrides the time range for individual panel by shifting its start and end relative to the time picker.
* `Max data points`
* `Min interval`
* `Interval`
* `Relative time`
* `Time shift`
* `Hide time info`
![query options](https://github.com/antip00/clickhouse-grafana/blob/master/tests/testflows/requirements/images/query%20options.png)
Expand Down Expand Up @@ -2586,6 +2608,12 @@
This relative time SHALL override the time range for individual panel
by shifting its start and end relative to the time picker.
### RQ.SRS.Plugin.QueryOptions.HideTimeInfo
version: 1.0
The [Plugin] SHALL support `Hide time info` toggle.
This toggle SHALL hide time info regarding relative time and time shift in panel title if turned on.
## Raw SQL Editor
### RQ.SRS.Plugin.RawSQLEditorInterface
Expand Down
26 changes: 19 additions & 7 deletions tests/testflows/steps/panel/query_options/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,54 @@ class Locators:
@property
def query_options_dropdown(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH, f'//div[@aria-label="Expand query row" or @aria-label="Collapse query row"]')
return driver.find_element(SelectBy.XPATH, f'//button[@aria-label="Expand query row" or @aria-label="Collapse query row"]')

@property
def max_data_points_textfield(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[@class="gf-form" and .//text()="Max data points"]/label[@class="gf-form-label width-6""]')
f'//*[@class="gf-form" and .//text()="Max data points"]//input')

@property
def interval_field(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[@class="gf-form" and .//text()="Interval"]/div[@data-testid="input-wrapper"]')
f'//*[@class="gf-form" and .//text()="Interval"]/label[@class="gf-form-label width-6"]')

@property
def min_interval_textfield(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH, f'//*[@class="gf-form" and .//text()="Min interval"]/div[@data-testid="input-wrapper"]')
return driver.find_element(SelectBy.XPATH, f'//*[@class="gf-form" and .//text()="Min interval"]//input')

@property
def relative_time_textfield(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[@class="gf-form" and .//text()="Relative time"]/div[@data-testid="input-wrapper"]')
f'//*[@class="gf-form" and .//text()="Relative time"]//input')

@property
def time_shift_textfield(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[@class="gf-form" and .//text()="Time shift"]/div[@data-testid="input-wrapper"]')
f'//*[@class="gf-form" and .//text()="Time shift"]//input')

@property
def hide_time_info_toggle(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[@class="gf-form-inline align-items-center" and .//text()="Hide time info"]/input')
f'//*[@class="gf-form-inline align-items-center" and .//text()="Hide time info"]//label[@aria-label="Toggle switch"]')

@property
def relative_time_info(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[@data-testid="title-items-container"]//*[contains(@class, "panel-header-item")]')

@property
def timeshift_info(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[@data-testid="title-items-container"]//*[contains(@class, "panel-header-item")]')


locators = Locators()
46 changes: 44 additions & 2 deletions tests/testflows/steps/panel/query_options/view.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from testflows.core import *
from testflows.asserts import error

import steps.ui as ui
from steps.delay import delay
from steps.panel.query_options.locators import locators

from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By as SelectBy

import steps.ui as ui


@TestStep(When)
def click_query_options_dropdown(self):
Expand All @@ -20,27 +21,40 @@ def click_query_options_dropdown(self):
def enter_max_data_points(self, max_data_points):
"""Enter max data points."""

locators.max_data_points_textfield.clear()
locators.max_data_points_textfield.send_keys(max_data_points)
locators.max_data_points_textfield.send_keys(Keys.ENTER)


@TestStep(When)
def enter_min_interval(self, min_interval):
"""Enter min interval."""

locators.min_interval_textfield.clear()
locators.min_interval_textfield.send_keys(min_interval)
locators.min_interval_textfield.send_keys(Keys.ENTER)


@TestStep(When)
def enter_relative_time(self, relative_time):
"""Enter relative time."""

locators.relative_time_textfield.clear()
locators.relative_time_textfield.send_keys(Keys.BACK_SPACE)
locators.relative_time_textfield.send_keys(Keys.BACK_SPACE)
locators.relative_time_textfield.send_keys(relative_time)
locators.relative_time_textfield.send_keys(Keys.ENTER)


@TestStep(When)
def enter_time_shift(self, time_shift):
"""Enter time shift time."""

locators.time_shift_textfield.clear()
locators.time_shift_textfield.send_keys(Keys.BACK_SPACE)
locators.time_shift_textfield.send_keys(Keys.BACK_SPACE)
locators.time_shift_textfield.send_keys(time_shift)
locators.time_shift_textfield.send_keys(Keys.ENTER)


@TestStep(When)
Expand Down Expand Up @@ -111,3 +125,31 @@ def get_time_shift_default(self):
"""Get Time shift default."""

return locators.time_shift_textfield.get_attribute('placeholder')


@TestStep(Then)
def check_relative_time_info_exists(self):
"""Check that relative time info exists."""
with By(f"checking relative time info text is displayed"):
try:
ui.wait_for_element_to_be_present(
select_type=SelectBy.XPATH,
element=f'//*[@data-testid="title-items-container"]//*[contains(@class, "panel-header-item")]'
)
return True
except:
return False


@TestStep(Then)
def check_time_shift_info_exists(self):
"""Check that time shift info exists."""
with By(f"checking shift info text is displayed"):
try:
ui.wait_for_element_to_be_present(
select_type=SelectBy.XPATH,
element=f'//*[@data-testid="title-items-container"]//*[contains(@class, "panel-header-item")]'
)
return True
except:
return False
Loading

0 comments on commit ab4ccd8

Please sign in to comment.