Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesCGDS committed Feb 16, 2024
1 parent 531e65c commit 8159b95
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/assets/javascripts/live_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
if (this.$resultsWrapper) {
this.$resultsWrapper.setAttribute('data-search-query', this.currentKeywords())
var sortedBy = this.$resultsWrapper.querySelector('.js-order-results')
if (sortedBy) {
// Check that the sortedBy element exists and contains option elements
if (sortedBy && sortedBy.options.length > 0) {
this.$resultsWrapper.setAttribute('data-ecommerce-variant', sortedBy.options[sortedBy.selectedIndex].text)
}
}
Expand All @@ -147,7 +148,8 @@
if (this.$resultsWrapper) {
this.$resultsWrapper.setAttribute('data-ga4-search-query', this.currentKeywords())
var sortedBy = this.$resultsWrapper.querySelector('.js-order-results')
if (sortedBy) {
// Check that the sortedBy element exists and contains option elements
if (sortedBy && sortedBy.options.length > 0) {
this.$resultsWrapper.setAttribute('data-ga4-ecommerce-variant', sortedBy.options[sortedBy.selectedIndex].text)
}
}
Expand Down
2 changes: 1 addition & 1 deletion spec/javascripts/live_search_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ describe('liveSearch', function () {
liveSearch.state = { search: 'state' }

expect($('#order option').length).toBe(2)
$('#order').remove()
$('option').remove()
expect($('#order option').length).toBe(0)
// We receive new data, which adds the sort options to the DOM.
liveSearch.updateSortOptions(responseWithSortOptions, $.param(liveSearch.state))
Expand Down

0 comments on commit 8159b95

Please sign in to comment.