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
2
2
3
3
from selenium .webdriver .common .by import By
4
4
from selenium .webdriver .support import expected_conditions as EC
5
5
6
- from ..factories import CollectionFactory
6
+ from ..factories import (
7
+ CollectionFactory ,
8
+ CuratedUrlFactory ,
9
+ DeltaUrlFactory ,
10
+ UserFactory ,
11
+ )
7
12
from .base import BaseTestCase
8
13
9
14
@@ -26,7 +31,6 @@ def test_collections_display(self):
26
31
# Navigate to collections page
27
32
self .driver .get (f"{ self .live_server_url } /" )
28
33
29
- # Wait for specific table to load using ID
30
34
table = self .wait .until (EC .presence_of_element_located ((By .ID , "collection_table" )))
31
35
assert "table-striped dataTable" in table .get_attribute ("class" )
32
36
@@ -52,6 +56,190 @@ def test_universal_search(self):
52
56
assert self .collections [1 ].name not in table_text , "Collection #2 should not be present"
53
57
assert self .collections [2 ].name not in table_text , "Collection #3 should not be present"
54
58
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
+
55
239
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 ()
57
245
super ().tearDown ()
0 commit comments