Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve "Adding bookmark without bookmark counter raises an error" #3215

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/javascript/blacklight/checkbox_submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class CheckboxSubmit {
this.labelTarget.removeAttribute('disabled')
this.checkboxTarget.removeAttribute('disabled')
this.updateStateFor(!this.checked)
document.querySelector('[data-role=bookmark-counter]').innerHTML = json.bookmarks.count
if (this.bookmarkCounter()) this.bookmarkCounter().innerHTML = json.bookmarks.count
}).catch((error) => {
this.handleError(error)
})
Expand All @@ -63,6 +63,10 @@ export default class CheckboxSubmit {
return this.form.querySelector('[data-checkboxsubmit-target="span"]')
}

bookmarkCounter() {
return document.querySelector('[data-role="bookmark-counter"]')
}

handleError() {
alert("Unable to save the bookmark at this time.")
}
Expand Down
13 changes: 13 additions & 0 deletions spec/features/bookmarks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
end
end

describe "when bookmark counter is not rendered" do
before do
allow(CatalogController).to receive(:render_bookmarks_control?).and_return(false)
end

it 'adds bookmark without raising an alert', :js do
visit solr_document_path('2007020969')
check 'Bookmark'
visit bookmarks_path
expect(page).to have_css('input[type="checkbox"][checked]')
end
end

it "clears bookmarks" do
visit solr_document_path('2007020969')
click_on 'Bookmark'
Expand Down
Loading