Skip to content
Snippets Groups Projects
Commit 71a66626 authored by Ere Maijala's avatar Ere Maijala Committed by Demian Katz
Browse files

Fix broken bottom select all checkbox bug (#886)

- Use checkbox-select-all’s form attribute if it exists and the closest form only if it doesn’t. Make sure to update checked state of any other select-all checkbox when one changes state.
parent 60d39a65
No related merge requests found
...@@ -138,14 +138,17 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase ...@@ -138,14 +138,17 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase
/** /**
* Add the current page of results to the cart. * Add the current page of results to the cart.
* *
* @param Element $page Page element * @param Element $page Page element
* @param Element $updateCart Add to cart button * @param Element $updateCart Add to cart button
* @param string $selectAllId ID of select all checkbox
* *
* @return void * @return void
*/ */
protected function addCurrentPageToCart(Element $page, Element $updateCart) protected function addCurrentPageToCart(Element $page, Element $updateCart,
$selectAllId = '#addFormCheckboxSelectAll'
)
{ {
$selectAll = $page->find('css', '#addFormCheckboxSelectAll'); $selectAll = $page->find('css', $selectAllId);
$selectAll->check(); $selectAll->check();
$updateCart->click(); $updateCart->click();
} }
...@@ -169,10 +172,14 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase ...@@ -169,10 +172,14 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase
* into the cart, then opening the lightbox so that additional actions may * into the cart, then opening the lightbox so that additional actions may
* be attempted. * be attempted.
* *
* @param array $extraConfigs Extra config settings
* @param string $selectAllId ID of select all checkbox
*
* @return Element * @return Element
*/ */
protected function setUpGenericCartTest($extraConfigs = []) protected function setUpGenericCartTest($extraConfigs = [],
{ $selectAllId = '#addFormCheckboxSelectAll'
) {
// Activate the cart: // Activate the cart:
$extraConfigs['config']['Site'] = ['showBookBag' => true]; $extraConfigs['config']['Site'] = ['showBookBag' => true];
$this->changeConfigs($extraConfigs); $this->changeConfigs($extraConfigs);
...@@ -183,7 +190,7 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase ...@@ -183,7 +190,7 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase
$updateCart = $this->findCss($page, '#updateCart'); $updateCart = $this->findCss($page, '#updateCart');
// Now actually select something: // Now actually select something:
$this->addCurrentPageToCart($page, $updateCart); $this->addCurrentPageToCart($page, $updateCart, $selectAllId);
$this->assertEquals('2', $this->findCss($page, '#cartItems strong')->getText()); $this->assertEquals('2', $this->findCss($page, '#cartItems strong')->getText());
// Open the cart and empty it: // Open the cart and empty it:
...@@ -427,6 +434,16 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase ...@@ -427,6 +434,16 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase
$this->assertEquals('0', $this->findCss($page, '#cartItems strong')->getText()); $this->assertEquals('0', $this->findCss($page, '#cartItems strong')->getText());
} }
/**
* Test that we can put items in the cart using the bottom checkbox.
*
* @return void
*/
public function testFillCartUsingBottomCheckbox()
{
$this->setUpGenericCartTest([], '#bottom_addFormCheckboxSelectAll');
}
/** /**
* Test that we can put items in the cart and then remove them outside of * Test that we can put items in the cart and then remove them outside of
* the lightbox. * the lightbox.
......
...@@ -351,15 +351,14 @@ $(document).ready(function commonDocReady() { ...@@ -351,15 +351,14 @@ $(document).ready(function commonDocReady() {
// Checkbox select all // Checkbox select all
$('.checkbox-select-all').change(function selectAllCheckboxes() { $('.checkbox-select-all').change(function selectAllCheckboxes() {
var $form = $(this).closest('form'); var $form = this.form ? $(this.form) : $(this).closest('form');
$form.find('.checkbox-select-item').prop('checked', this.checked); $form.find('.checkbox-select-item').prop('checked', this.checked);
$('[form="' + $form.attr('id') + '"]').prop('checked', this.checked); $('[form="' + $form.attr('id') + '"]').prop('checked', this.checked);
$form.find('.checkbox-select-all').prop('checked', this.checked);
$('.checkbox-select-all[form="' + $form.attr('id') + '"]').prop('checked', this.checked);
}); });
$('.checkbox-select-item').change(function selectAllDisable() { $('.checkbox-select-item').change(function selectAllDisable() {
var $form = $(this).closest('form'); var $form = this.form ? $(this.form) : $(this).closest('form');
if ($form.length === 0 && this.form) {
$form = $(this.form);
}
if ($form.length === 0) { if ($form.length === 0) {
return; return;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment