Skip to content

Commit

Permalink
[9] Add AboutApplicationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
denniseilander committed Jan 21, 2025
1 parent 6dc4393 commit 246e281
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/AboutApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

use Denniseilander\AboutApplication\AboutApplication;
use Illuminate\Support\Collection;

it('formats information correctly', function () {
$information = new Collection([
'strings' => [
'filled' => 'foo',
'empty_string' => '',
],
'booleans' => [
'true_value' => true,
'false_value' => false,
],
'numbers' => [
'integer' => 12345,
'float' => 123.45,
],
'arrays' => [
'simple_array' => ['one', 'two', 'three'],
'empty_array' => [],
],
'nullables' => [
'null_value' => null,
'empty_string' => '',
],
]);

// Simulate the configuration for categories to hide.
config(['pulse-about-application.hide' => ['nullables']]);

$formatted = AboutApplication::formatInformation($information);

// Assert the structure and transformations.
expect($formatted)->toBeInstanceOf(Collection::class);

// Ensure hidden categories are removed.
expect($formatted->has('nullables'))->toBeFalse();

// Validate transformations.
expect($formatted['strings']['filled'])->toBe('foo');
expect($formatted['strings']['empty_string'])->toBe('-');

expect($formatted['booleans']['true_value'])->toBe('Yes');
expect($formatted['booleans']['false_value'])->toBe('No');

expect($formatted['numbers']['integer'])->toBe('12,345');
expect($formatted['numbers']['float'])->toBe('123.45');

expect($formatted['arrays']['simple_array'])->toBe('one, two, three');
expect($formatted['arrays']['empty_array'])->toBe('');
});

0 comments on commit 246e281

Please sign in to comment.