Skip to content

Commit c39a718

Browse files
committed
Update integration tests for enable_folder_selection API
- Rename test_upfd001 to test_upfd001_folder_upload_with_enable_folder_selection - Add test_upfd002_multiple_files_without_folder_selection to verify multiple=True without folder selection - Add test_upfd003_single_file_upload for single file upload validation - Update tests to use enable_folder_selection prop instead of relying on multiple=True
1 parent 8947b1f commit c39a718

File tree

1 file changed

+68
-10
lines changed

1 file changed

+68
-10
lines changed

components/dash-core-components/tests/integration/upload/test_folder_upload.py

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from dash import Dash, Input, Output, dcc, html
22

33

4-
def test_upfd001_folder_upload_with_multiple(dash_dcc):
4+
def test_upfd001_folder_upload_with_enable_folder_selection(dash_dcc):
55
"""
6-
Test that folder upload is enabled when multiple=True.
6+
Test that folder upload is enabled when enable_folder_selection=True.
77
88
Note: Full end-to-end testing of folder upload functionality is limited
99
by Selenium's capabilities. This test verifies the component renders
10-
correctly with multiple=True which enables folder support.
10+
correctly with enable_folder_selection=True which enables folder support.
1111
"""
1212
app = Dash(__name__)
1313

@@ -17,7 +17,7 @@ def test_upfd001_folder_upload_with_multiple(dash_dcc):
1717
dcc.Upload(
1818
id="upload-folder",
1919
children=html.Div(
20-
["Drag and Drop or ", html.A("Select Files or Folders")]
20+
["Drag and Drop or ", html.A("Select Folder")]
2121
),
2222
style={
2323
"width": "100%",
@@ -28,7 +28,8 @@ def test_upfd001_folder_upload_with_multiple(dash_dcc):
2828
"borderRadius": "5px",
2929
"textAlign": "center",
3030
},
31-
multiple=True, # Enables folder upload
31+
multiple=True,
32+
enable_folder_selection=True, # Enables folder selection
3233
accept=".txt,.csv", # Test accept filtering
3334
),
3435
html.Div(id="output"),
@@ -52,21 +53,77 @@ def update_output(contents_list):
5253
# Verify the upload component and input are present
5354
dash_dcc.wait_for_element("#upload-folder")
5455

55-
# Verify the input has folder selection attributes when multiple=True
56+
# Verify the input has folder selection attributes when enable_folder_selection=True
5657
upload_input = dash_dcc.wait_for_element("#upload-folder input[type=file]")
5758
webkitdir_attr = upload_input.get_attribute("webkitdirectory")
5859

5960
assert webkitdir_attr == "true", (
60-
f"webkitdirectory attribute should be 'true' when multiple=True, "
61+
f"webkitdirectory attribute should be 'true' when enable_folder_selection=True, "
6162
f"but got '{webkitdir_attr}'"
6263
)
6364

6465
assert dash_dcc.get_logs() == [], "browser console should contain no error"
6566

6667

67-
def test_upfd002_folder_upload_disabled_with_single(dash_dcc):
68+
def test_upfd002_multiple_files_without_folder_selection(dash_dcc):
6869
"""
69-
Test that folder upload is NOT enabled when multiple=False.
70+
Test that multiple file upload does NOT enable folder selection
71+
when enable_folder_selection=False (default).
72+
"""
73+
app = Dash(__name__)
74+
75+
app.layout = html.Div(
76+
[
77+
html.Div("Multiple Files Test", id="title"),
78+
dcc.Upload(
79+
id="upload-multiple",
80+
children=html.Div(["Drag and Drop or ", html.A("Select Multiple Files")]),
81+
style={
82+
"width": "100%",
83+
"height": "60px",
84+
"lineHeight": "60px",
85+
"borderWidth": "1px",
86+
"borderStyle": "dashed",
87+
"borderRadius": "5px",
88+
"textAlign": "center",
89+
},
90+
multiple=True, # Allows multiple files
91+
enable_folder_selection=False, # But NOT folder selection
92+
accept=".txt,.csv", # Accept should work with file picker
93+
),
94+
html.Div(id="output", children="Upload ready"),
95+
]
96+
)
97+
98+
dash_dcc.start_server(app)
99+
100+
# Wait for the component to render
101+
dash_dcc.wait_for_text_to_equal("#title", "Multiple Files Test")
102+
dash_dcc.wait_for_text_to_equal("#output", "Upload ready")
103+
104+
# Verify the input does NOT have folder selection attributes
105+
upload_input = dash_dcc.wait_for_element("#upload-multiple input[type=file]")
106+
webkitdir_attr = upload_input.get_attribute("webkitdirectory")
107+
108+
# webkitdirectory should not be set when enable_folder_selection=False
109+
assert webkitdir_attr in [None, "", "false"], (
110+
f"webkitdirectory attribute should not be 'true' when enable_folder_selection=False, "
111+
f"but got '{webkitdir_attr}'"
112+
)
113+
114+
# Verify multiple attribute is set
115+
multiple_attr = upload_input.get_attribute("multiple")
116+
assert multiple_attr == "true", (
117+
f"multiple attribute should be 'true' when multiple=True, "
118+
f"but got '{multiple_attr}'"
119+
)
120+
121+
assert dash_dcc.get_logs() == [], "browser console should contain no error"
122+
123+
124+
def test_upfd003_single_file_upload(dash_dcc):
125+
"""
126+
Test that single file upload does NOT enable folder selection.
70127
"""
71128
app = Dash(__name__)
72129

@@ -85,7 +142,8 @@ def test_upfd002_folder_upload_disabled_with_single(dash_dcc):
85142
"borderRadius": "5px",
86143
"textAlign": "center",
87144
},
88-
multiple=False, # Folder upload should be disabled
145+
multiple=False, # Single file only
146+
accept="application/pdf",
89147
),
90148
html.Div(id="output", children="Upload ready"),
91149
]

0 commit comments

Comments
 (0)