def test_select_source_and_download_unread(
            self, _sd_servers_v2_with_missing_file, firefox_web_driver):
        # Given an SD server with a submission whose file was deleted from disk
        # And a journalist logged into the journalist interface
        journ_app_nav = JournalistAppNavigator(
            journalist_app_base_url=_sd_servers_v2_with_missing_file.
            journalist_app_base_url,
            web_driver=firefox_web_driver,
        )
        journ_app_nav.journalist_logs_in(
            username=_sd_servers_v2_with_missing_file.journalist_username,
            password=_sd_servers_v2_with_missing_file.journalist_password,
            otp_secret=_sd_servers_v2_with_missing_file.journalist_otp_secret,
        )

        # When the journalist selects the source then clicks the "Download Unread" button
        checkboxes = journ_app_nav.driver.find_elements_by_name(
            "cols_selected")
        assert len(checkboxes) == 1
        checkboxes[0].click()
        journ_app_nav.driver.find_element_by_xpath(
            "//button[@value='download-unread']").click()

        # Then they see the expected error message
        self._journalist_sees_missing_file_error_message(journ_app_nav)
        journ_app_nav.is_on_journalist_homepage()
    def test_download_source_unread(self, _sd_servers_v2_with_missing_file,
                                    firefox_web_driver):
        # Given an SD server with a submission whose file was deleted from disk
        # And a journalist logged into the journalist interface
        journ_app_nav = JournalistAppNavigator(
            journalist_app_base_url=_sd_servers_v2_with_missing_file.
            journalist_app_base_url,
            web_driver=firefox_web_driver,
        )
        journ_app_nav.journalist_logs_in(
            username=_sd_servers_v2_with_missing_file.journalist_username,
            password=_sd_servers_v2_with_missing_file.journalist_password,
            otp_secret=_sd_servers_v2_with_missing_file.journalist_otp_secret,
        )

        # When the journalist clicks on the source's "n unread" button
        journ_app_nav.driver.find_element_by_css_selector(
            "table#collections tr.source > td.unread a").click()

        # Then they see the expected error message
        self._journalist_sees_missing_file_error_message(journ_app_nav)
        journ_app_nav.is_on_journalist_homepage()
    def test_journalist_uses_col_delete_collection_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 the journalist went to the individual source's page
        journ_app_nav.journalist_visits_col()

        # And the source has at least one submission
        initial_submissions_count = journ_app_nav.count_submissions_on_current_page(
        )
        assert initial_submissions_count > 0

        # When the journalist clicks the delete collection button...
        self._journalist_clicks_delete_collection_link(journ_app_nav)
        # ...but then cancels the deletion
        journ_app_nav.nav_helper.safe_click_by_id(
            "cancel-collection-deletions")

        # Then they see the same number of submissions as before
        submissions_after_canceling_count = journ_app_nav.count_submissions_on_current_page(
        )
        assert submissions_after_canceling_count == initial_submissions_count

        # When the journalist clicks the delete collection button...
        self._journalist_clicks_delete_collection_link(journ_app_nav)
        # ... and then confirms the deletion
        journ_app_nav.nav_helper.safe_click_by_id("delete-collection-button")

        # Then the journalist was redirected to the home page
        assert journ_app_nav.is_on_journalist_homepage()