Skip to content

Commit

Permalink
disable create snapshot button when there is a pending snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
sissbruecker committed Apr 14, 2024
1 parent baea9a0 commit db5a06b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bookmarks/templates/bookmarks/details/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@

{% if details.is_editable %}
<div class="assets-actions">
<button type="submit" name="create_snapshot" class="btn btn-link">Create HTML snapshot</button>
<button type="submit" name="create_snapshot" class="btn btn-link"
{% if details.has_pending_assets %}disabled{% endif %}>Create HTML snapshot
</button>
</div>
{% endif %}
</div>
25 changes: 25 additions & 0 deletions bookmarks/tests/test_bookmark_details_modal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from unittest.mock import patch

from django.test import TestCase, override_settings
Expand Down Expand Up @@ -792,3 +793,27 @@ def test_create_snapshot(self):
self.assertEqual(response.status_code, 302)

self.assertEqual(bookmark.bookmarkasset_set.count(), 1)

@override_settings(LD_ENABLE_SNAPSHOTS=True)
def test_create_snapshot_is_disabled_when_having_pending_asset(self):
bookmark = self.setup_bookmark()
asset = self.setup_asset(bookmark, status=BookmarkAsset.STATUS_COMPLETE)

# no pending asset
soup = self.get_details(bookmark)
files_section = self.find_section(soup, "Files")
create_button = files_section.find(
"button", string=re.compile("Create HTML snapshot")
)
self.assertFalse(create_button.has_attr("disabled"))

# with pending asset
asset.status = BookmarkAsset.STATUS_PENDING
asset.save()

soup = self.get_details(bookmark)
files_section = self.find_section(soup, "Files")
create_button = files_section.find(
"button", string=re.compile("Create HTML snapshot")
)
self.assertTrue(create_button.has_attr("disabled"))

0 comments on commit db5a06b

Please sign in to comment.