Skip to content

Commit

Permalink
Test: Fix functional test for deletion of collections and documents
Browse files Browse the repository at this point in the history
Update functional tests for journalist to expect a modal with the cancel
and delete button and actions based on it rather than the previous
confirmation alert.
  • Loading branch information
SaptakS committed Jan 31, 2018
1 parent 1849529 commit 436c3bb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 27 deletions.
12 changes: 8 additions & 4 deletions securedrop/journalist_templates/col.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
<p>
<div id="select-container"></div>
<button type="submit" name="action" value="download" class="small"><i class="fa fa-download"></i> {{ gettext('Download Selected') }}</button>
<a href="#delete-selected-confirmation-modal" class="btn small danger"><i class="fa fa-trash-o"></i> {{ gettext('Delete Selected') }}</a>
<a href="#delete-selected-confirmation-modal" id="delete-selected-link" class="btn small danger">
<i class="fa fa-trash-o"></i> {{ gettext('Delete Selected') }}
</a>
</p>

<ul id="submissions" class="plain submissions">
Expand Down Expand Up @@ -69,7 +71,7 @@
<a href="#close" title="Close" class="close">X</a>
<h2>{{ gettext('Delete Confirmation') }}</h2>
<p>{{ gettext('Are you sure you want to delete the selected documents?') }}</p>
<a href="#close" title="Cancel" class="btn sd-button">Cancel</a>
<a href="#close" id="cancel-selected-deletions" title="Cancel" class="btn sd-button">Cancel</a>
<button type="submit" name="action" value="confirm_delete" id="delete-selected" class="sd-button danger">Delete</button>
</div>
</div>
Expand Down Expand Up @@ -113,7 +115,9 @@ <h3><i class="fa fa-reply"></i> {{ gettext('Reply') }}</h3>
<input name="csrf_token" type="hidden" value="{{ csrf_token() }}">
<input type="hidden" name="filesystem_id" value="{{ filesystem_id }}">
<input type="hidden" name="col_name" value="{{ source.journalist_designation }}">
<a href="#delete-collection-confirmation-modal" class="btn sd-button danger"><i class="fa fa-trash-o"></i> {{ gettext('DELETE COLLECTION') }}</a>
<a href="#delete-collection-confirmation-modal" id="delete-collection-link" class="btn sd-button danger">
<i class="fa fa-trash-o"></i> {{ gettext('DELETE COLLECTION') }}
</a>

<!-- Confirmation modal for entire collection deletion -->
<div id="delete-collection-confirmation-modal" class="modal-dialog">
Expand All @@ -122,7 +126,7 @@ <h3><i class="fa fa-reply"></i> {{ gettext('Reply') }}</h3>
<a href="#close" title="Close" class="close">X</a>
<h2>{{ gettext('Delete Confirmation') }}</h2>
<p>{{ gettext('Are you sure you want to delete this collection?') }}</p>
<a href="#close" title="Cancel" class="btn sd-button">Cancel</a>
<a href="#close" id="cancel-collection-deletions" title="Cancel" class="btn sd-button">Cancel</a>
<button type="submit" id="delete-collection-button" name="action" value="delete" class="sd-button danger">Delete</button>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions securedrop/journalist_templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1><span class="headline">{{ gettext('Sources') }}</span></h1>
<button type="submit" name="action" value="download-all" class="small"><i class="fa fa-download"></i> {{ gettext('Download') }}</button>
<button type="submit" name="action" value="star" class="small"><i class="fa fa-star"></i> {{ gettext('Star') }}</button>
<button type="submit" name="action" value="un-star" class="small"><i class="fa fa-star-half-full"></i> {{ gettext('Un-star') }}</button>
<a href="#delete-confirmation-modal" class="btn small danger">
<a href="#delete-confirmation-modal" id="delete-collections-link" class="btn small danger">
<i class="fa fa-trash-o"></i> {{ gettext('Delete') }}
</a>
</p>
Expand Down Expand Up @@ -46,7 +46,7 @@ <h1><span class="headline">{{ gettext('Sources') }}</span></h1>
<a href="#close" title="Close" class="close">X</a>
<h2>{{ gettext('Delete Confirmation') }}</h2>
<p>{{ gettext('Are you sure you want to delete the selected collections?') }}</p>
<a href="#close" title="Cancel" class="btn sd-button">Cancel</a>
<a href="#close" id="cancel-collections-deletions" title="Cancel" class="btn sd-button">Cancel</a>
<button type="submit" id="delete-collections" name="action" value="delete" class="sd-button danger">Delete</button>
</div>
</div>
Expand Down
72 changes: 51 additions & 21 deletions securedrop/tests/functional/journalist_navigation_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,43 +75,73 @@ def _journalist_visits_col(self):
def _journalist_selects_first_doc(self):
self.driver.find_elements_by_name('doc_names_selected')[0].click()

def _journalist_clicks_delete_selected_javascript(self):
self.driver.find_element_by_id('delete-selected').click()
self._alert_wait()
def _journalist_clicks_delete_collections_cancel_on_modal(self):
self.driver.find_element_by_id('cancel-collections-deletions').click()

def _journalist_clicks_delete_selected_cancel_on_modal(self):
self.driver.find_element_by_id('cancel-selected-deletions').click()

def _journalist_clicks_delete_collections_javascript(self):
def _journalist_clicks_delete_collection_cancel_on_modal(self):
self.driver.find_element_by_id('cancel-collection-deletions').click()

def _journalist_clicks_delete_collections_on_modal(self):
self.driver.find_element_by_id('delete-collections').click()
self._alert_wait()

def _journalist_clicks_delete_collection_javascript(self):
def _journalist_clicks_delete_selected_on_modal(self):
self.driver.find_element_by_id('delete-selected').click()

def _journalist_clicks_delete_collection_on_modal(self):
self.driver.find_element_by_id('delete-collection-button').click()
self._alert_wait()

def _journalist_sees_delete_collections_confirmation_javascript(self):
assert self.driver.find_element_by_id(
'delete-confirmation-modal').is_displayed()

def _journalist_sees_delete_selected_confirmation_javascript(self):
assert self.driver.find_element_by_id(
'delete-selected-confirmation-modal').is_displayed()

def _journalist_sees_delete_collection_confirmation_javascript(self):
assert self.driver.find_element_by_id(
'delete-collection-confirmation-modal').is_displayed()

def _journalist_clicks_delete_selected_link(self):
self.driver.find_element_by_id('delete-selected-link').click()
self._journalist_sees_delete_selected_confirmation_javascript()

def _journalist_clicks_delete_collections_link(self):
self.driver.find_element_by_id('delete-collections-link').click()
self._journalist_sees_delete_collections_confirmation_javascript()

def _journalist_clicks_delete_collection_link(self):
self.driver.find_element_by_id('delete-collection-link').click()
self._journalist_sees_delete_collection_confirmation_javascript()

def _journalist_uses_delete_selected_button_javascript(self):
self._journalist_selects_first_doc()
self._journalist_clicks_delete_selected_javascript()
self._alert_dismiss()
self._journalist_clicks_delete_selected_link()
self._journalist_clicks_delete_selected_cancel_on_modal()

selected_count = len(self.driver.find_elements_by_name(
'doc_names_selected'))
assert selected_count > 0

self._journalist_clicks_delete_selected_javascript()
self._alert_accept()
self._journalist_clicks_delete_selected_link()
self._journalist_clicks_delete_selected_on_modal()
assert selected_count > len(self.driver.find_elements_by_name(
'doc_names_selected'))

def _journalist_uses_delete_collection_button_javascript(self):
self._journalist_clicks_delete_collection_javascript()
self._alert_dismiss()
self._journalist_clicks_delete_collection_link()
self._journalist_clicks_delete_collection_cancel_on_modal()

# After deletion the button will redirect us. Let's ensure we still
# see the delete collection button.
assert self.driver.find_element_by_id(
'delete-collection-button').is_displayed()
'delete-collection-link').is_displayed()

self._journalist_clicks_delete_collection_javascript()
self._alert_accept()
self._journalist_clicks_delete_collection_link()
self._journalist_clicks_delete_collection_on_modal()

# Now we should be redirected to the index.
if not hasattr(self, 'accept-languages'):
Expand All @@ -120,15 +150,15 @@ def _journalist_uses_delete_collection_button_javascript(self):
def _journalist_uses_delete_collections_button_javascript(self):
self.driver.find_element_by_id('select_all').click()

self._journalist_clicks_delete_collections_javascript()
self._alert_dismiss()
self._journalist_clicks_delete_collections_link()
self._journalist_clicks_delete_collections_cancel_on_modal()

self.driver.find_element_by_id('select_all').click()
sources = self.driver.find_elements_by_class_name("code-name")
assert len(sources) > 0

self._journalist_clicks_delete_collections_javascript()
self._alert_accept()
self._journalist_clicks_delete_collections_link()
self._journalist_clicks_delete_collections_on_modal()

# We should be redirected to the index without those boxes selected.
sources = self.driver.find_elements_by_class_name("code-name")
Expand Down Expand Up @@ -685,7 +715,7 @@ def _journalist_delete_none(self):
def _journalist_delete_all_javascript(self):
self.driver.find_element_by_id('select_all').click()
self.driver.find_element_by_id('delete-selected').click()
self._alert_wait()
# self._alert_wait()

def _journalist_delete_one(self):
self.driver.find_elements_by_name('doc_names_selected')[0].click()
Expand Down

0 comments on commit 436c3bb

Please sign in to comment.