Skip to content

Commit

Permalink
feat: add file component (#438)
Browse files Browse the repository at this point in the history
This PR adds support of File component.
UCC doc ref:
https://splunk.github.io/addonfactory-ucc-generator/entity/components/#file
  • Loading branch information
dvarasani-crest authored Sep 19, 2024
1 parent 49b85e3 commit efd575b
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 2 deletions.
94 changes: 94 additions & 0 deletions pytest_splunk_addon_ui_smartx/components/controls/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#
# Copyright 2024 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from ..base_component import Selector
from .base_control import BaseControl
from selenium.common.exceptions import TimeoutException


class File(BaseControl):
"""
Entity-Component: File
"""

def __init__(self, browser, container) -> None:
"""
:param browser: The selenium webdriver
:param container: The locator of the container where the control is located in.
"""
super().__init__(browser, container)
self.elements.update(
{
"input": Selector(select=container.select + " input"),
"support_message": Selector(
select=container.select
+ ' [data-test="file"] [data-test="file-supports"]'
),
"error_text": Selector(
select=container.select + ' [data-test="file"] [data-test="help"]'
),
"selected": Selector(
select=container.select + ' [data-test="item"] [data-test="label"]'
),
"cancel_selected": Selector(
select=container.select + ' [data-test="remove"]'
),
}
)

def set_value(self, value: str) -> None:
"""
set value of the File input
"""
self.wait_for("input")
self.input.send_keys(value)

def get_value(self) -> str:
"""
get the name of the selected file
:return: Str The name of the selected file
"""
try:
return self.selected.get_attribute("innerText").strip()
except TimeoutException:
pass
return ""

def get_support_message(self) -> str:
"""
get the file support message
:return: Str file support message
"""
return self.support_message.get_attribute("innerText").strip()

def get_error_text(self) -> str:
"""
get the file validation error text
:return: Str error message of the file validation
"""
try:
return self.error_text.get_attribute("innerText").strip()
except TimeoutException:
pass
return ""

def cancel_selected_value(self) -> bool:
"""
Cancels the currently selected value in the File component
:return: Bool whether canceling the selected item was successful, else raises an error
"""
self.wait_to_be_clickable("cancel_selected")
self.cancel_selected.click()
return True
20 changes: 20 additions & 0 deletions tests/testdata/Splunk_TA_UCCExample/globalConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@
"help": "Enter a unique name for this account.",
"required": true
},
{
"type": "file",
"label": "Example File",
"help": "Upload example file",
"field": "example_file",
"options": {
"fileSupportMessage": "Example Support message",
"supportedFileTypes": ["conf", "txt"],
"maxFileSize": 1,
"useBase64Encoding": false
},
"validators": [
{
"type": "regex",
"pattern": "^Example*"
}
],
"encrypted": true,
"required": true
},
{
"type": "singleSelect",
"label": "Example Environment",
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/Example_UccLib/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pytest_splunk_addon_ui_smartx.components.controls.multi_select import MultiSelect
from pytest_splunk_addon_ui_smartx.components.controls.checkbox import Checkbox
from pytest_splunk_addon_ui_smartx.components.controls.textbox import TextBox
from pytest_splunk_addon_ui_smartx.components.controls.file import File
from pytest_splunk_addon_ui_smartx.components.controls.learn_more import LearnMore
from pytest_splunk_addon_ui_smartx.components.controls.toggle import Toggle
from pytest_splunk_addon_ui_smartx.components.controls.message import Message
Expand Down Expand Up @@ -40,6 +41,10 @@ def __init__(self, browser, container):
self.name = TextBox(
browser, Selector(select='[data-test="control-group"][data-name="name"]')
)
self.file = File(
browser,
Selector(select='[data-test="control-group"][data-name="example_file"]'),
)
self.environment = SingleSelect(
browser,
Selector(select='[data-test="control-group"][data-name="custom_endpoint"]'),
Expand Down
1 change: 1 addition & 0 deletions tests/ui/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def add_account(ucc_smartx_rest_helper):
"redirect_url": "",
"endpoint": "",
"example_help_link": "",
"example_file": "Example file content",
}
yield account.backend_conf.post_stanza(url, kwargs)
account.backend_conf.delete_all_stanzas()
Loading

0 comments on commit efd575b

Please sign in to comment.