def test_journalist_uses_index_delete_files_button_modal(
            self, sd_servers_v2_with_submitted_file, firefox_web_driver):
        # Given an SD server with a file submitted by a source
        # And a journalist logged into the journalist interface
        journ_app_nav = JournalistAppNavigator(
            journalist_app_base_url=sd_servers_v2_with_submitted_file.
            journalist_app_base_url,
            web_driver=firefox_web_driver,
        )
        journ_app_nav.journalist_logs_in(
            username=sd_servers_v2_with_submitted_file.journalist_username,
            password=sd_servers_v2_with_submitted_file.journalist_password,
            otp_secret=sd_servers_v2_with_submitted_file.journalist_otp_secret,
        )

        # And at least one source previously used the app
        initial_sources_count = journ_app_nav.count_sources_on_index_page()
        assert initial_sources_count > 0

        # And the journalist selected all sources on the index page
        try:
            # If JavaScript is enabled, use the select_all button.
            journ_app_nav.driver.find_element_by_id("select_all")
            journ_app_nav.nav_helper.safe_click_by_id("select_all")
        except NoSuchElementException:
            journ_app_nav.nav_helper.safe_click_all_by_css_selector(
                'input[type="checkbox"][name="cols_selected"]')

        # When the journalist clicks the delete collection button...
        self._journalist_clicks_delete_collections_link(journ_app_nav)
        # ...and then clicks the delete files button on the first modal
        journ_app_nav.nav_helper.safe_click_by_id("delete-files-and-messages")

        # Then they are redirected to the index with the source present, files
        # and messages zeroed, and a success flash message present
        def one_source_no_files():
            assert journ_app_nav.count_sources_on_index_page() == 1
            flash_msg = journ_app_nav.driver.find_element_by_css_selector(
                ".flash")
            assert "The files and messages have been deleted" in flash_msg.text
            counts = journ_app_nav.driver.find_elements_by_css_selector(
                ".submission-count")
            assert "0 docs" in counts[0].text
            assert "0 messages" in counts[1].text

        journ_app_nav.nav_helper.wait_for(one_source_no_files)
    def test_journalist_uses_index_delete_collections_button_modal(
            self, sd_servers_v2_with_submitted_file, firefox_web_driver):
        # Given an SD server with a file submitted by a source
        # And a journalist logged into the journalist interface
        journ_app_nav = JournalistAppNavigator(
            journalist_app_base_url=sd_servers_v2_with_submitted_file.
            journalist_app_base_url,
            web_driver=firefox_web_driver,
        )
        journ_app_nav.journalist_logs_in(
            username=sd_servers_v2_with_submitted_file.journalist_username,
            password=sd_servers_v2_with_submitted_file.journalist_password,
            otp_secret=sd_servers_v2_with_submitted_file.journalist_otp_secret,
        )

        # And at least one source previously used the app
        initial_sources_count = journ_app_nav.count_sources_on_index_page()
        assert initial_sources_count > 0

        # And the journalist selected all sources on the index page
        try:
            # If JavaScript is enabled, use the select_all button.
            journ_app_nav.driver.find_element_by_id("select_all")
            journ_app_nav.nav_helper.safe_click_by_id("select_all")
        except NoSuchElementException:
            journ_app_nav.nav_helper.safe_click_all_by_css_selector(
                'input[type="checkbox"][name="cols_selected"]')

        # When the journalist clicks the delete collection button...
        self._journalist_clicks_delete_collections_link(journ_app_nav)
        # ...but then cancels the deletion
        self._journalist_clicks_delete_collections_cancel_on_first_modal(
            journ_app_nav)

        # Then they see the same number of sources as before
        assert initial_sources_count == journ_app_nav.count_sources_on_index_page(
        )

        # And when the journalist clicks the delete collection button again...
        self._journalist_clicks_delete_collections_link(journ_app_nav)
        # ...and then confirms the deletion...
        self._journalist_clicks_delete_collections_on_first_modal(
            journ_app_nav)
        # ... and cancels the deletion on the second modal/confirmation prompt
        journ_app_nav.nav_helper.safe_click_by_id(
            "cancel-collections-deletions")

        # Then they see the same number of sources as before
        assert initial_sources_count == journ_app_nav.count_sources_on_index_page(
        )

        # And when the journalist clicks the delete collection button again and confirms it
        self._journalist_clicks_delete_collections_link(journ_app_nav)
        self._journalist_clicks_delete_collections_on_first_modal(
            journ_app_nav)
        journ_app_nav.nav_helper.safe_click_by_id("delete-collections-confirm")

        # Then a message shows up to say that the collection was deleted
        def collection_deleted():
            flash_msg = journ_app_nav.driver.find_element_by_css_selector(
                ".flash")
            assert "The account and all data for the source have been deleted." in flash_msg.text

        journ_app_nav.nav_helper.wait_for(collection_deleted)

        # And the journalist gets redirected to the index with the source not present anymore
        def no_sources():
            assert journ_app_nav.count_sources_on_index_page() == 0

        journ_app_nav.nav_helper.wait_for(no_sources)