Skip to content

Commit

Permalink
Fix selection of ILL or storage request to update button state. (#2147)
Browse files Browse the repository at this point in the history
- Includes tests covering impacted functionality.

Co-authored-by: Demian Katz <[email protected]>
  • Loading branch information
EreMaijala and demiankatz authored Sep 24, 2021
1 parent 6b7d4ab commit 097e206
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,59 @@ protected function clickButtonGroupLink(Element $page, string $text): void
}

/**
* Test canceling a request.
* Test canceling a request with the "cancel selected" button.
*
* @param Element $page Page element.
* @param string $type Request type being tested.
*
* @return void
*/
protected function cancelProcedure(Element $page, string $type): void
protected function cancelSelectedProcedure(Element $page, string $type): void
{
// First make sure item is there before cancel is pushed:
$this->assertEquals(
'Journal of rational emotive therapy :'
. ' the journal of the Institute for Rational-Emotive Therapy.',
$this->findCss($page, 'a.title')->getText()
);

// Test that control is disabled upon empty selection
$this->clickCss($page, '#cancelSelected');
$this->assertNull($page->find('css', '.btn-group.open'));

// Test "cancel all" button -- first make sure item is there before
// cancel is pushed:
// Test that control becomes active if we click a checkbox (but don't
// actually cancel anything yet).
$this->clickCss($page, "#checkbox_testsample1");
$this->clickCss($page, '#cancelSelected');
$this->clickButtonGroupLink($page, 'No');
$this->assertEquals(
'Journal of rational emotive therapy :'
. ' the journal of the Institute for Rational-Emotive Therapy.',
$this->findCss($page, 'a.title')->getText()
);

// Now cancel for real:
$this->clickCss($page, '#cancelSelected');
$this->clickButtonGroupLink($page, 'Yes');
$this->snooze();
$this->assertEquals(
'1 request(s) were successfully canceled',
$this->findCss($page, '.alert.alert-success')->getText()
);
$this->assertNull($page->find('css', 'a.title'));
}

/**
* Test canceling a request with the "cancel all" button.
*
* @param Element $page Page element.
* @param string $type Request type being tested.
*
* @return void
*/
protected function cancelAllProcedure(Element $page, string $type): void
{
// First make sure item is there before cancel is pushed:
$this->assertEquals(
'Journal of rational emotive therapy :'
. ' the journal of the Institute for Rational-Emotive Therapy.',
Expand Down Expand Up @@ -371,13 +409,11 @@ public function testIllRequest(): void
}

/**
* Test canceling an ILL request.
* Set up a cancel ILL request test.
*
* @depends testProfile
*
* @return void
* @return Element
*/
public function testCancelIllRequest(): void
protected function setUpCancelIllTest(): Element
{
// Turn on "cancel ILL requests" in addition to normal defaults:
$config = $this->getConfigIniOverrides();
Expand All @@ -393,9 +429,33 @@ public function testCancelIllRequest(): void
$page = $this->gotoRecordById();
$this->snooze();
$this->illRequestProcedure($page);
return $page;
}

// Test canceling the request:
$this->cancelProcedure($page, 'interlibrary loan requests');
/**
* Test canceling an ILL request with "cancel all."
*
* @depends testProfile
*
* @return void
*/
public function testCancelAllIllRequest(): void
{
$page = $this->setUpCancelIllTest();
$this->cancelAllProcedure($page, 'interlibrary loan requests');
}

/**
* Test canceling an ILL request with "cancel selected."
*
* @depends testProfile
*
* @return void
*/
public function testCancelSelectedIllRequest(): void
{
$page = $this->setUpCancelIllTest();
$this->cancelSelectedProcedure($page, 'interlibrary loan requests');
}

/**
Expand Down Expand Up @@ -425,13 +485,11 @@ public function testStorageRetrievalRequest(): void
}

/**
* Test canceling storage retrieval requests.
*
* @depends testProfile
* Set up a cancel storage retrieval request test.
*
* @return void
* @return Element
*/
public function testCancelStorageRetrievalRequest(): void
protected function setUpCancelStorageRetrievalTest(): Element
{
// Turn on "cancel storage requests" in addition to normal defaults:
$config = $this->getConfigIniOverrides();
Expand All @@ -447,9 +505,33 @@ public function testCancelStorageRetrievalRequest(): void
$page = $this->gotoRecordById();
$this->snooze();
$this->storageRetrievalRequestProcedure($page);
return $page;
}

/**
* Test canceling storage retrieval requests with "cancel all."
*
* @depends testProfile
*
* @return void
*/
public function testCancelAllStorageRetrievalRequest(): void
{
$page = $this->setUpCancelStorageRetrievalTest();
$this->cancelAllProcedure($page, 'storage retrieval requests');
}

// Test canceling the request:
$this->cancelProcedure($page, 'storage retrieval requests');
/**
* Test canceling storage retrieval requests with "cancel selected."
*
* @depends testProfile
*
* @return void
*/
public function testCancelSelectedStorageRetrievalRequest(): void
{
$page = $this->setUpCancelStorageRetrievalTest();
$this->cancelSelectedProcedure($page, 'storage retrieval requests');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions themes/bootstrap3/js/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $(document).ready(function setupRequests() {
});

var checkCheckboxes = function CheckCheckboxes() {
var checked = $('#update_holds .result .checkbox input[type=checkbox]:checked');
var checked = $('form[name="updateForm"] .result .checkbox input[type=checkbox]:checked');
if (checked.length > 0) {
$('#update_selected').removeAttr('disabled');
$('#cancelSelected').removeAttr('disabled');
Expand All @@ -31,7 +31,7 @@ $(document).ready(function setupRequests() {
$('#cancelSelected').attr('disabled', 'disabled');
}
};
$('#update_holds .result .checkbox input[type=checkbox]').on('change', checkCheckboxes);
$('form[name="updateForm"] .result .checkbox input[type=checkbox]').on('change', checkCheckboxes);
$('#update_selected').removeClass('hidden');
checkCheckboxes();
});
2 changes: 1 addition & 1 deletion themes/bootstrap3/templates/myresearch/illrequests.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<?php if (!empty($this->recordList)): ?>
<?php if ($this->cancelForm): ?>
<form name="cancelForm" class="inline" method="post" id="cancelILLRequest" data-clear-account-cache="illRequests">
<form name="updateForm" class="inline" method="post" id="cancelILLRequest" data-clear-account-cache="illRequests">
<input type="hidden" id="submitType" name="cancelSelected" value="1"/>
<input type="hidden" id="cancelConfirm" name="confirm" value="0"/>
<div class="btn-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<?php if (!empty($this->recordList)): ?>
<?php if ($this->cancelForm): ?>
<form name="cancelForm" class="inline" method="post" id="cancelStorageRetrievalRequest" data-clear-account-cache="storageRetrievalRequests">
<form name="updateForm" class="inline" method="post" id="cancelStorageRetrievalRequest" data-clear-account-cache="storageRetrievalRequests">
<input type="hidden" id="submitType" name="cancelSelected" value="1"/>
<input type="hidden" id="cancelConfirm" name="confirm" value="0"/>
<div class="btn-group">
Expand Down

0 comments on commit 097e206

Please sign in to comment.