Skip to content

Commit c0f5cc9

Browse files
author
Mohammad Arif
committed
improve test caces and add functionality to changes size of icon
1 parent d3adc7b commit c0f5cc9

File tree

6 files changed

+227
-33
lines changed

6 files changed

+227
-33
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A modern, customizable alert box plugin for FilamentPHP with render hooks suppor
55
[![Latest Version on Packagist](https://img.shields.io/packagist/v/rifrocket/filament-alert-box.svg?style=flat-square)](https://packagist.org/packages/rifrocket/filament-alert-box)
66
[![Total Downloads](https://img.shields.io/packagist/dt/rifrocket/filament-alert-box.svg?style=flat-square)](https://packagist.org/packages/rifrocket/filament-alert-box)
77

8+
89
## Features
910

1011
- 🎨 **4 Beautiful Card Styles** - Banner, Card with Border, Modern Card, and Minimalist

phpunit.xml

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
processIsolation="false"
7-
stopOnFailure="false"
8-
cacheDirectory=".phpunit.cache"
9-
backupGlobals="false">
10-
<testsuites>
11-
<testsuite name="RifRocket Test Suite">
12-
<directory suffix="Test.php">./tests</directory>
13-
</testsuite>
14-
</testsuites>
15-
<coverage>
16-
<include>
17-
<directory suffix=".php">./src</directory>
18-
</include>
19-
<exclude>
20-
<directory>./tests</directory>
21-
<directory>./vendor</directory>
22-
</exclude>
23-
</coverage>
24-
<php>
25-
<env name="APP_ENV" value="testing"/>
26-
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
27-
<env name="DB_CONNECTION" value="sqlite"/>
28-
<env name="DB_DATABASE" value=":memory:"/>
29-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupGlobals="false">
3+
<testsuites>
4+
<testsuite name="RifRocket Test Suite">
5+
<directory suffix="Test.php">./tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<php>
9+
<env name="APP_ENV" value="testing"/>
10+
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
11+
<env name="DB_CONNECTION" value="sqlite"/>
12+
<env name="DB_DATABASE" value=":memory:"/>
13+
</php>
14+
<source>
15+
<include>
16+
<directory suffix=".php">./src</directory>
17+
</include>
18+
<exclude>
19+
<directory>./tests</directory>
20+
<directory>./vendor</directory>
21+
</exclude>
22+
</source>
3023
</phpunit>

phpunit.xml.bak

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
processIsolation="false"
7+
stopOnFailure="false"
8+
cacheDirectory=".phpunit.cache"
9+
backupGlobals="false">
10+
<testsuites>
11+
<testsuite name="RifRocket Test Suite">
12+
<directory suffix="Test.php">./tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
<coverage>
16+
<include>
17+
<directory suffix=".php">./src</directory>
18+
</include>
19+
<exclude>
20+
<directory>./tests</directory>
21+
<directory>./vendor</directory>
22+
</exclude>
23+
</coverage>
24+
<php>
25+
<env name="APP_ENV" value="testing"/>
26+
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
27+
<env name="DB_CONNECTION" value="sqlite"/>
28+
<env name="DB_DATABASE" value=":memory:"/>
29+
</php>
30+
</phpunit>

src/AlertBuilder.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ public function iconColor(string $color): self
217217
public function iconSize(string $size): self
218218
{
219219
$size = strtolower($size);
220-
221-
if (!in_array($size, self::VALID_ICON_SIZES, true)) {
220+
221+
if (! in_array($size, self::VALID_ICON_SIZES, true)) {
222222
throw new InvalidArgumentException(
223223
sprintf('Icon size must be one of: %s, got %s', implode(', ', self::VALID_ICON_SIZES), $size)
224224
);
@@ -235,6 +235,7 @@ public function iconSize(string $size): self
235235
public function iconXS(): self
236236
{
237237
$this->config['icon_size'] = 'xs';
238+
238239
return $this;
239240
}
240241

@@ -244,6 +245,7 @@ public function iconXS(): self
244245
public function iconS(): self
245246
{
246247
$this->config['icon_size'] = 's';
248+
247249
return $this;
248250
}
249251

@@ -253,6 +255,7 @@ public function iconS(): self
253255
public function iconM(): self
254256
{
255257
$this->config['icon_size'] = 'm';
258+
256259
return $this;
257260
}
258261

@@ -262,6 +265,7 @@ public function iconM(): self
262265
public function iconLG(): self
263266
{
264267
$this->config['icon_size'] = 'lg';
268+
265269
return $this;
266270
}
267271

@@ -271,6 +275,7 @@ public function iconLG(): self
271275
public function iconXL(): self
272276
{
273277
$this->config['icon_size'] = 'xl';
278+
274279
return $this;
275280
}
276281

tests/AlertBoxManagerTest.php

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,91 @@ public function test_alert_count_increases_after_adding(): void
4141

4242
public function test_can_clear_all_alerts(): void
4343
{
44-
// Add some alerts
45-
AlertBoxManager::make('Test 1')->success()->show();
46-
AlertBoxManager::make('Test 2')->danger()->show();
44+
AlertBoxManager::addAlert('position1', ['id' => 'alert1', 'type' => 'info']);
45+
AlertBoxManager::addAlert('position2', ['id' => 'alert2', 'type' => 'success']);
4746

4847
$this->assertGreaterThan(0, AlertBoxManager::getAlertCount());
4948

5049
AlertBoxManager::clearAll();
5150

5251
$this->assertEquals(0, AlertBoxManager::getAlertCount());
5352
}
53+
54+
// Icon Size Tests
55+
public function test_default_icon_size_is_medium(): void
56+
{
57+
$alert = new AlertBuilder('Test Alert');
58+
$config = $alert->toArray();
59+
60+
$this->assertEquals('m', $config['icon_size']);
61+
}
62+
63+
public function test_can_set_icon_size_using_method(): void
64+
{
65+
$alert = new AlertBuilder('Test Alert');
66+
$alert->iconSize('lg');
67+
$config = $alert->toArray();
68+
69+
$this->assertEquals('lg', $config['icon_size']);
70+
}
71+
72+
public function test_can_set_icon_size_using_convenience_methods(): void
73+
{
74+
$testCases = [
75+
['iconXS', 'xs'],
76+
['iconS', 's'],
77+
['iconM', 'm'],
78+
['iconLG', 'lg'],
79+
['iconXL', 'xl'],
80+
];
81+
82+
foreach ($testCases as [$method, $expectedSize]) {
83+
$alert = new AlertBuilder('Test Alert');
84+
$alert->$method();
85+
$config = $alert->toArray();
86+
87+
$this->assertEquals($expectedSize, $config['icon_size'], "Method {$method} should set size to {$expectedSize}");
88+
}
89+
}
90+
91+
public function test_invalid_icon_size_throws_exception(): void
92+
{
93+
$this->expectException(\InvalidArgumentException::class);
94+
$this->expectExceptionMessage('Icon size must be one of: xs, s, m, lg, xl, got invalid');
95+
96+
$alert = new AlertBuilder('Test Alert');
97+
$alert->iconSize('invalid');
98+
}
99+
100+
public function test_icon_size_is_case_insensitive(): void
101+
{
102+
$alert = new AlertBuilder('Test Alert');
103+
$alert->iconSize('XL');
104+
$config = $alert->toArray();
105+
106+
$this->assertEquals('xl', $config['icon_size']);
107+
}
108+
109+
public function test_no_icon_resets_size_to_default(): void
110+
{
111+
$alert = new AlertBuilder('Test Alert');
112+
$alert->iconSize('xl');
113+
$alert->noIcon(true);
114+
$config = $alert->toArray();
115+
116+
$this->assertEquals('m', $config['icon_size']);
117+
}
118+
119+
public function test_method_chaining_works_with_icon_sizes(): void
120+
{
121+
$alert = new AlertBuilder('Test Alert');
122+
$result = $alert->success()->iconLG()->description('Test description');
123+
124+
$this->assertInstanceOf(AlertBuilder::class, $result);
125+
126+
$config = $alert->toArray();
127+
$this->assertEquals('success', $config['type']);
128+
$this->assertEquals('lg', $config['icon_size']);
129+
$this->assertEquals('Test description', $config['description']);
130+
}
54131
}

tests/IconSizeTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RifRocket\FilamentAlertBox\Tests;
6+
7+
use InvalidArgumentException;
8+
use RifRocket\FilamentAlertBox\AlertBuilder;
9+
10+
class IconSizeTest extends TestCase
11+
{
12+
public function test_default_icon_size_is_medium(): void
13+
{
14+
$alert = new AlertBuilder('Test Alert');
15+
$config = $alert->toArray();
16+
17+
$this->assertEquals('m', $config['icon_size']);
18+
}
19+
20+
public function test_can_set_icon_size_using_method(): void
21+
{
22+
$alert = new AlertBuilder('Test Alert');
23+
$alert->iconSize('lg');
24+
$config = $alert->toArray();
25+
26+
$this->assertEquals('lg', $config['icon_size']);
27+
}
28+
29+
public function test_can_set_icon_size_using_convenience_methods(): void
30+
{
31+
$testCases = [
32+
['iconXS', 'xs'],
33+
['iconS', 's'],
34+
['iconM', 'm'],
35+
['iconLG', 'lg'],
36+
['iconXL', 'xl'],
37+
];
38+
39+
foreach ($testCases as [$method, $expectedSize]) {
40+
$alert = new AlertBuilder('Test Alert');
41+
$alert->$method();
42+
$config = $alert->toArray();
43+
44+
$this->assertEquals($expectedSize, $config['icon_size'], "Method {$method} should set size to {$expectedSize}");
45+
}
46+
}
47+
48+
public function test_invalid_icon_size_throws_exception(): void
49+
{
50+
$this->expectException(InvalidArgumentException::class);
51+
$this->expectExceptionMessage('Icon size must be one of: xs, s, m, lg, xl, got invalid');
52+
53+
$alert = new AlertBuilder('Test Alert');
54+
$alert->iconSize('invalid');
55+
}
56+
57+
public function test_icon_size_is_case_insensitive(): void
58+
{
59+
$alert = new AlertBuilder('Test Alert');
60+
$alert->iconSize('XL');
61+
$config = $alert->toArray();
62+
63+
$this->assertEquals('xl', $config['icon_size']);
64+
}
65+
66+
public function test_no_icon_resets_size_to_default(): void
67+
{
68+
$alert = new AlertBuilder('Test Alert');
69+
$alert->iconSize('xl');
70+
$alert->noIcon(true);
71+
$config = $alert->toArray();
72+
73+
$this->assertEquals('m', $config['icon_size']);
74+
}
75+
76+
public function test_method_chaining_works_with_icon_sizes(): void
77+
{
78+
$alert = new AlertBuilder('Test Alert');
79+
$result = $alert->success()->iconLG()->description('Test description');
80+
81+
$this->assertInstanceOf(AlertBuilder::class, $result);
82+
83+
$config = $alert->toArray();
84+
$this->assertEquals('success', $config['type']);
85+
$this->assertEquals('lg', $config['icon_size']);
86+
$this->assertEquals('Test description', $config['description']);
87+
}
88+
}

0 commit comments

Comments
 (0)