Skip to content

Commit b78f4bf

Browse files
committed
Add searchpane tests
1 parent efdba33 commit b78f4bf

File tree

3 files changed

+209
-12
lines changed

3 files changed

+209
-12
lines changed

sde_collections/tests/frontend/test_homepage_features.py

Lines changed: 192 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
# docker-compose -f local.yml run --rm django pytest -s sde_collections/tests/frontend/test_collections.py
1+
# docker-compose -f local.yml run --rm django pytest -s sde_collections/tests/frontend/test_homepage_features.py
22

33
from selenium.webdriver.common.by import By
44
from selenium.webdriver.support import expected_conditions as EC
55

6-
from ..factories import CollectionFactory
6+
from ..factories import (
7+
CollectionFactory,
8+
CuratedUrlFactory,
9+
DeltaUrlFactory,
10+
UserFactory,
11+
)
712
from .base import BaseTestCase
813

914

@@ -26,7 +31,6 @@ def test_collections_display(self):
2631
# Navigate to collections page
2732
self.driver.get(f"{self.live_server_url}/")
2833

29-
# Wait for specific table to load using ID
3034
table = self.wait.until(EC.presence_of_element_located((By.ID, "collection_table")))
3135
assert "table-striped dataTable" in table.get_attribute("class")
3236

@@ -52,6 +56,190 @@ def test_universal_search(self):
5256
assert self.collections[1].name not in table_text, "Collection #2 should not be present"
5357
assert self.collections[2].name not in table_text, "Collection #3 should not be present"
5458

59+
60+
class TestSearchPaneFeatures(BaseTestCase):
61+
"""Test search pane features on homepage"""
62+
63+
def setUp(self):
64+
super().setUp()
65+
self.user, self.password = self.create_test_user(is_staff=True)
66+
self.second_test_user = UserFactory()
67+
self.third_test_user = UserFactory()
68+
69+
# Create collections with diverse attributes
70+
self.collections = [
71+
CollectionFactory(curated_by=self.user, division=1, workflow_status=3, connector=1, reindexing_status=1),
72+
CollectionFactory(
73+
curated_by=self.second_test_user, division=3, workflow_status=1, connector=1, reindexing_status=2
74+
),
75+
CollectionFactory(
76+
curated_by=self.third_test_user, division=4, workflow_status=3, connector=2, reindexing_status=4
77+
),
78+
]
79+
80+
# Factory sometimes struggle to generate unique URLs by itself, so applying this technique
81+
self.delta_urls = []
82+
self.curated_urls = []
83+
for i, collection in enumerate(self.collections):
84+
num_urls = 10**i # 1, 10, 100, ...
85+
self.delta_urls.extend(
86+
[
87+
DeltaUrlFactory(collection=collection, url=f"https://example-{collection.id}-{j}.com")
88+
for j in range(num_urls)
89+
]
90+
)
91+
self.curated_urls.extend(
92+
[
93+
CuratedUrlFactory(collection=collection, url=f"https://example-{collection.id}-{j}.com")
94+
for j in range(num_urls)
95+
]
96+
)
97+
98+
self.login(self.user.username, self.password)
99+
self.driver.get(f"{self.live_server_url}/")
100+
self.COLUMNS = self.driver.execute_script("return COLUMNS;")
101+
102+
def test_division_searchpane(self):
103+
"""Test division search pane filtering"""
104+
105+
# Find and click Astrophysics option
106+
astrophysics_option = self.wait.until(
107+
EC.element_to_be_clickable((By.CSS_SELECTOR, "span.dtsp-name[title='Astrophysics']"))
108+
)
109+
astrophysics_option.click()
110+
111+
# Get all rows from the filtered table
112+
rows = self.driver.find_elements(By.CSS_SELECTOR, "#collection_table tbody tr")
113+
assert len(rows) > 0, "No rows found after filtering"
114+
115+
# Verify each row shows Astrophysics division
116+
for row in rows:
117+
division_cell = row.find_elements(By.TAG_NAME, "td")[self.COLUMNS["DIVISION"]]
118+
assert division_cell.text.lower() == "astrophysics", f"Expected Astrophysics but found {division_cell.text}"
119+
120+
def test_delta_urls_searchpane(self):
121+
"""Test Delta URLs search pane filtering"""
122+
123+
# Find the Delta URLs pane using its index and then find the "1 solo URL" option within it
124+
search_panes = self.driver.find_elements(By.CSS_SELECTOR, "div.dtsp-searchPane")
125+
delta_urls_pane = search_panes[self.COLUMNS["DELTA_URLS"]]
126+
delta_url_option = delta_urls_pane.find_element(By.CSS_SELECTOR, "span.dtsp-name[title='1 solo URL']")
127+
delta_url_option.click()
128+
129+
# Get all rows from the filtered table
130+
rows = self.driver.find_elements(By.CSS_SELECTOR, "#collection_table tbody tr")
131+
assert len(rows) > 0, "No rows found after filtering"
132+
133+
# Verify each row shows "1" in Delta URLs column
134+
for row in rows:
135+
delta_urls_cell = row.find_elements(By.TAG_NAME, "td")[self.COLUMNS["DELTA_URLS"]]
136+
assert delta_urls_cell.text == "1", f"Expected '1' but found {delta_urls_cell.text}"
137+
138+
def test_curated_urls_searchpane(self):
139+
"""Test Curated URLs search pane filtering"""
140+
141+
# Find the Curated URLs pane using its index and then find the "1 to 100 URLs" option within it
142+
search_panes = self.driver.find_elements(By.CSS_SELECTOR, "div.dtsp-searchPane")
143+
curated_urls_pane = search_panes[self.COLUMNS["CURATED_URLS"]]
144+
curated_url_option = curated_urls_pane.find_element(By.CSS_SELECTOR, "span.dtsp-name[title='1 to 100 URLs']")
145+
curated_url_option.click()
146+
147+
# Get all rows from the filtered table
148+
rows = self.driver.find_elements(By.CSS_SELECTOR, "#collection_table tbody tr")
149+
assert len(rows) > 0, "No rows found after filtering"
150+
151+
# Verify each row shows a number between 1 and 100 in Curated URLs column
152+
for row in rows:
153+
curated_urls_cell = row.find_elements(By.TAG_NAME, "td")[self.COLUMNS["CURATED_URLS"]]
154+
url_count = int(curated_urls_cell.text)
155+
assert 1 < url_count <= 100, f"Expected number between 1 and 100 but found {url_count}"
156+
157+
def test_workflow_status_searchpane(self):
158+
"""Test Workflow Status search pane filtering"""
159+
160+
# Find and click the option with "Engineering in Progress" button
161+
workflow_status_option = self.wait.until(
162+
EC.element_to_be_clickable(
163+
(By.XPATH, "//div[@class='dtsp-nameCont']//button[text()='Engineering in Progress']")
164+
)
165+
)
166+
workflow_status_option.click()
167+
168+
# Get all rows from the filtered table
169+
rows = self.driver.find_elements(By.CSS_SELECTOR, "#collection_table tbody tr")
170+
assert len(rows) > 0, "No rows found after filtering"
171+
172+
# Verify each row shows "ENGINEERING IN PROGRESS" in Workflow Status column
173+
for row in rows:
174+
workflow_status_cell = row.find_elements(By.TAG_NAME, "td")[self.COLUMNS["WORKFLOW_STATUS"]]
175+
assert (
176+
workflow_status_cell.text.lower() == "engineering in progress"
177+
), f"Expected 'ENGINEERING IN PROGRESS' but found {workflow_status_cell.text}"
178+
179+
def test_curator_searchpane(self):
180+
"""Test Curator search pane filtering"""
181+
182+
# Find and click the option with "test_user" button
183+
curator_option = self.wait.until(
184+
EC.element_to_be_clickable((By.XPATH, "//div[@class='dtsp-nameCont']//button[text()='test_user']"))
185+
)
186+
curator_option.click()
187+
188+
# Get all rows from the filtered table
189+
rows = self.driver.find_elements(By.CSS_SELECTOR, "#collection_table tbody tr")
190+
assert len(rows) > 0, "No rows found after filtering"
191+
192+
# Verify each row shows "test_user" in Curator column
193+
for row in rows:
194+
curator_cell = row.find_elements(By.TAG_NAME, "td")[self.COLUMNS["CURATOR"]]
195+
assert curator_cell.text.lower() == "test_user", f"Expected 'test_user' but found {curator_cell.text}"
196+
197+
def test_connector_type_searchpane(self):
198+
"""Test Connector Type search pane filtering"""
199+
200+
# Find and click "crawler2" option
201+
crawler2_option = self.wait.until(
202+
EC.element_to_be_clickable((By.CSS_SELECTOR, "span.dtsp-name[title='crawler2']"))
203+
)
204+
crawler2_option.click()
205+
206+
# Get all rows from the filtered table
207+
rows = self.driver.find_elements(By.CSS_SELECTOR, "#collection_table tbody tr")
208+
assert len(rows) > 0, "No rows found after filtering"
209+
210+
# Verify each row shows "crawler2" connector type
211+
for row in rows:
212+
connector_type_cell = row.find_elements(By.TAG_NAME, "td")[self.COLUMNS["CONNECTOR_TYPE"]]
213+
assert (
214+
connector_type_cell.text.lower() == "crawler2"
215+
), f"Expected 'crawler2' but found {connector_type_cell.text}"
216+
217+
def test_reindexing_status_searchpane(self):
218+
"""Test Reindexing Status search pane filtering"""
219+
220+
# Find and click the option with "Re-Indexing Not Needed" button
221+
reindexing_option = self.wait.until(
222+
EC.element_to_be_clickable(
223+
(By.XPATH, "//div[@class='dtsp-nameCont']//button[text()='Re-Indexing Not Needed']")
224+
)
225+
)
226+
reindexing_option.click()
227+
228+
# Get all rows from the filtered table
229+
rows = self.driver.find_elements(By.CSS_SELECTOR, "#collection_table tbody tr")
230+
assert len(rows) > 0, "No rows found after filtering"
231+
232+
# Verify each row shows "RE-INDEXING NOT NEEDED" in Reindexing Status column
233+
for row in rows:
234+
reindexing_status_cell = row.find_elements(By.TAG_NAME, "td")[self.COLUMNS["REINDEXING_STATUS"]]
235+
assert (
236+
reindexing_status_cell.text.lower() == "re-indexing not needed"
237+
), f"Expected 'RE-INDEXING NOT NEEDED' but found {reindexing_status_cell.text}"
238+
55239
def tearDown(self):
56-
"""Clean up test data."""
240+
"""Clear all filters after each test"""
241+
242+
clear_all_button = self.driver.find_element(By.CSS_SELECTOR, "button.dtsp-clearAll")
243+
if "disabled" not in clear_all_button.get_attribute("class"):
244+
clear_all_button.click()
57245
super().tearDown()

sde_collections/tests/frontend/test_pattern_application.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# docker-compose -f local.yml run --rm django pytest -s sde_collections/tests/frontend/test_pattern_application.py
2+
13
from selenium.webdriver.common.by import By
24
from selenium.webdriver.support import expected_conditions as EC
35

sde_indexing_helper/static/js/collection_list.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,13 @@ let table = $("#collection_table").DataTable({
123123
},
124124
],
125125
columnDefs: [
126-
// hide the data columns
126+
// hide the data columns and search panes for these columns
127127
{
128128
targets: [COLUMNS.WORKFLOW_STATUS_RAW, COLUMNS.CURATOR_ID, COLUMNS.REINDEXING_STATUS_RAW],
129129
visible: false,
130+
searchPanes: {
131+
show: false,
132+
},
130133
},
131134
{ width: "200px", targets: COLUMNS.URL },
132135
{
@@ -175,6 +178,7 @@ let table = $("#collection_table").DataTable({
175178
},
176179
},
177180
],
181+
show: true,
178182
},
179183
targets: [COLUMNS.DELTA_URLS],
180184
type: "num-fmt",
@@ -225,19 +229,14 @@ let table = $("#collection_table").DataTable({
225229
},
226230
},
227231
],
232+
show: true,
228233
},
229234
targets: [COLUMNS.CURATED_URLS],
230235
type: "num-fmt",
231236
},
232-
// hide the data panes
233-
{
234-
searchPanes: {
235-
show: false,
236-
},
237-
targets: [COLUMNS.WORKFLOW_STATUS_RAW, COLUMNS.CURATOR_ID, COLUMNS.REINDEXING_STATUS_RAW],
238-
},
239237
{
240238
searchPanes: {
239+
show: true,
241240
dtOpts: {
242241
scrollY: "100%",
243242
},
@@ -246,12 +245,20 @@ let table = $("#collection_table").DataTable({
246245
},
247246
{
248247
searchPanes: {
248+
show: true,
249249
dtOpts: {
250250
scrollY: "100%",
251251
},
252252
},
253253
targets: [COLUMNS.CONNECTOR_TYPE],
254254
},
255+
// Explicitly enable required searchPanes – Selenium requires searchPanes to be explicitly enabled for proper functionality during testing.
256+
{
257+
searchPanes: {
258+
show: true,
259+
},
260+
targets: [COLUMNS.DIVISION, COLUMNS.DELTA_URLS, COLUMNS.CURATED_URLS, COLUMNS.WORKFLOW_STATUS, COLUMNS.CURATOR, COLUMNS.CONNECTOR_TYPE, COLUMNS.REINDEXING_STATUS ],
261+
},
255262
],
256263
});
257264

0 commit comments

Comments
 (0)