Skip to content

Commit

Permalink
fix: update tests to reflect changes to donation levels schema
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloiankoski committed Apr 23, 2024
1 parent a1d5ca6 commit ee7c9a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/FormMigration/Steps/DonationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function process()
return [
'value' => $this->roundAmount($donationLevel['_give_amount']),
'label' => $donationLevel['_give_text'],
'checked' => $donationLevel['_give_default'] === 'default' ?? false,
'checked' => isset($donationLevel['_give_default']) && $donationLevel['_give_default'] === 'default',
];
}, $donationLevels)
);
Expand Down
25 changes: 24 additions & 1 deletion tests/Feature/FormMigration/Steps/TestDonationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function testProcessShouldUpdateDonationAmountBlockAttributes(): void
}

/**
* @unreleased Updated test to include donation levels with descriptions
* @since 3.4.0
*/
public function testProcessShouldUpdateDonationAmountBlockAttributesWithDonationLevels(): void
Expand All @@ -67,7 +68,29 @@ public function testProcessShouldUpdateDonationAmountBlockAttributesWithDonation

$block = $payload->formV3->blocks->findByName('givewp/donation-amount');

$this->assertSame([10.00, 25.00, 50.00, 100.00], $block->getAttribute('levels'));
$expectedLevels = [
[
'value' => 10.00,
'label' => 'Small Gift',
'checked' => false,
],
[
'value' => 25.00,
'label' => 'Mid-size Gift',
'checked' => true,
],
[
'value' => 50.00,
'label' => 'Large Gift',
'checked' => false,
],
[
'value' => 100.00,
'label' => 'Big Gift',
'checked' => false,
],
];
$this->assertSame($expectedLevels, $block->getAttribute('levels'));
$this->assertTrue($block->getAttribute('customAmount'));
$this->assertSame((float)$meta['_give_custom_amount_range_minimum'], $block->getAttribute('customAmountMin'));
$this->assertSame((float)$meta['_give_custom_amount_range_maximum'], $block->getAttribute('customAmountMax'));
Expand Down

0 comments on commit ee7c9a0

Please sign in to comment.