Skip to content

Commit

Permalink
Add more test cases - Now 100 % line coverage!!
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed May 8, 2024
1 parent 2441d6a commit 01270d1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Forms/Components/MoneyInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MoneyInput extends TextInput
{
use HasMoneyAttributes;


protected function setUp(): void
{
parent::setUp();
Expand Down
2 changes: 2 additions & 0 deletions src/MoneyFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ public static function getFormattingRules($locale): MoneyFormattingRules
);
}

/*
public static function decimalToMoneyString($moneyString, $locale): string
{
return str_replace(',', '.', (string)$moneyString);
}
*/

private static function getNumberFormatter($locale, int $style): NumberFormatter
{
Expand Down
45 changes: 45 additions & 0 deletions tests/FormInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,51 @@ public function testNonNumericState(): void
$component->getState();
}

public function testCurrencySymbolPlacementAfter()
{
config(['filament-money-field.form_currency_symbol_placement' => 'after']);

$component = ComponentContainer::make(FormTestComponent::make())
->statePath('data')
->components([
MoneyInput::make('price'),
])->fill(['price' => 20]);

$field = $component->getComponent('data.price');
$this->assertEquals('$', $field->getSuffixLabel());
$this->assertNull($field->getPrefixLabel());
}

public function testCurrencySymbolPlacementBefore()
{
config(['filament-money-field.form_currency_symbol_placement' => 'before']);

$component = ComponentContainer::make(FormTestComponent::make())
->statePath('data')
->components([
MoneyInput::make('price'),
])->fill(['price' => 20]);

$field = $component->getComponent('data.price');
$this->assertEquals('$', $field->getPrefixLabel());
$this->assertNull($field->getSuffixLabel());
}

public function testInputMask()
{
config(['filament-money-field.use_input_mask' => true]);


$component = ComponentContainer::make(FormTestComponent::make())
->statePath('data')
->components([
MoneyInput::make('price'),
])->fill(['price' => 20]);

$this->assertStringContainsString('money($input', $component->getComponent('data.price')->getMask()->toHtml());
}


public function validationTester(Field $field, $value, ?callable $assertsCallback = null): true|array
{
try {
Expand Down

0 comments on commit 01270d1

Please sign in to comment.