|
2 | 2 |
|
3 | 3 | declare(strict_types=1); |
4 | 4 |
|
5 | | -use PepperFM\FilamentJson\Tests\src\Models\User; |
| 5 | +use PepperFM\FilamentJson\Columns\JsonColumn; |
| 6 | +use PepperFM\FilamentJson\Enums\ContainerModeEnum; |
| 7 | +use PepperFM\FilamentJson\Enums\RenderModeEnum; |
| 8 | +use PepperFM\FilamentJson\Dto\ButtonConfigDto; |
| 9 | +use PepperFM\FilamentJson\Dto\ModalConfigDto; |
6 | 10 |
|
7 | | -use function Pest\Livewire\livewire; |
| 11 | +test('it creates column with default settings', function (): void { |
| 12 | + $column = JsonColumn::make('properties'); |
8 | 13 |
|
9 | | -test('can render column', function (): void { |
10 | | - $user = User::factory()->make(); |
| 14 | + expect($column->getName())->toBe('properties') |
| 15 | + ->and($column->getRenderMode())->toBe(RenderModeEnum::Tree) |
| 16 | + ->and($column->getContainerMode())->toBe(ContainerModeEnum::Drawer) |
| 17 | + ->and($column->getFilterNullable())->toBeTrue() |
| 18 | + ->and($column->getMaxDepth())->toBe(3) |
| 19 | + ->and($column->getCharacterLimit())->toBeNull() |
| 20 | + ->and($column->getInitiallyCollapsed())->toBe(1) |
| 21 | + ->and($column->getExpandAllToggle())->toBeFalse() |
| 22 | + ->and($column->getCopyJsonAction())->toBeTrue(); |
| 23 | +}); |
11 | 24 |
|
12 | | - livewire(\PepperFM\FilamentJson\Tests\src\Fixtures\ListUsers::class) |
13 | | - ->assertSuccessful() |
14 | | - ->assertCanRenderTableColumn('properties') |
15 | | - ->assertTableColumnExists('properties') |
16 | | - ->assertTableColumnStateSet('properties', $user->properties, $user); |
17 | | -})->skip(); |
| 25 | +test('it sets render mode', function (): void { |
| 26 | + $column = JsonColumn::make('data'); |
| 27 | + |
| 28 | + $column->renderAs(RenderModeEnum::Table); |
| 29 | + expect($column->getRenderMode())->toBe(RenderModeEnum::Table) |
| 30 | + ->and($column->isTable())->toBeTrue() |
| 31 | + ->and($column->isTree())->toBeFalse(); |
| 32 | + |
| 33 | + $column->asTree(); |
| 34 | + expect($column->getRenderMode())->toBe(RenderModeEnum::Tree) |
| 35 | + ->and($column->isTree())->toBeTrue(); |
| 36 | + |
| 37 | + $column->asTable(); |
| 38 | + expect($column->isTable())->toBeTrue(); |
| 39 | +}); |
| 40 | + |
| 41 | +test('it sets container mode', function (): void { |
| 42 | + $column = JsonColumn::make('data'); |
| 43 | + |
| 44 | + $column->presentIn(ContainerModeEnum::Modal); |
| 45 | + expect($column->getContainerMode())->toBe(ContainerModeEnum::Modal) |
| 46 | + ->and($column->isModalContainer())->toBeTrue() |
| 47 | + ->and($column->isDrawerContainer())->toBeFalse(); |
| 48 | + |
| 49 | + $column->inDrawer(); |
| 50 | + expect($column->isDrawerContainer())->toBeTrue(); |
| 51 | + |
| 52 | + $column->inModal(); |
| 53 | + expect($column->isModalContainer())->toBeTrue(); |
| 54 | + |
| 55 | + $column->inlineContainer(); |
| 56 | + expect($column->isInlineContainer())->toBeTrue(); |
| 57 | +}); |
| 58 | + |
| 59 | +test('deprecated container methods delegate to new API', function (): void { |
| 60 | + $column = JsonColumn::make('data'); |
| 61 | + |
| 62 | + $column->asModal(); |
| 63 | + expect($column->isModalContainer())->toBeTrue() |
| 64 | + ->and($column->getAsModal())->toBeTrue(); |
| 65 | + |
| 66 | + $column->asDrawer(); |
| 67 | + expect($column->isDrawerContainer())->toBeTrue() |
| 68 | + ->and($column->getAsDrawer())->toBeTrue(); |
| 69 | +}); |
| 70 | + |
| 71 | +test('it configures UX toggles', function (): void { |
| 72 | + $column = JsonColumn::make('data') |
| 73 | + ->initiallyCollapsed(2) |
| 74 | + ->expandAllToggle() |
| 75 | + ->copyJsonAction(false) |
| 76 | + ->maxDepth(5) |
| 77 | + ->filterNullable(false) |
| 78 | + ->characterLimit(100); |
| 79 | + |
| 80 | + expect($column->getInitiallyCollapsed())->toBe(2) |
| 81 | + ->and($column->getExpandAllToggle())->toBeTrue() |
| 82 | + ->and($column->getCopyJsonAction())->toBeFalse() |
| 83 | + ->and($column->getMaxDepth())->toBe(5) |
| 84 | + ->and($column->getFilterNullable())->toBeFalse() |
| 85 | + ->and($column->getCharacterLimit())->toBe(100); |
| 86 | +}); |
| 87 | + |
| 88 | +test('it configures table labels', function (): void { |
| 89 | + $column = JsonColumn::make('data') |
| 90 | + ->keyColumnLabel('Property') |
| 91 | + ->valueColumnLabel('Data'); |
| 92 | + |
| 93 | + expect($column->getKeyColumnLabel())->toBe('Property') |
| 94 | + ->and($column->getValueColumnLabel())->toBe('Data'); |
| 95 | +}); |
| 96 | + |
| 97 | +test('it applies character limit to strings', function (): void { |
| 98 | + $column = JsonColumn::make('data')->characterLimit(10); |
| 99 | + |
| 100 | + expect($column->applyLimit('short'))->toBe('short') |
| 101 | + ->and($column->applyLimit('this is a very long string'))->toBe('this is a...') |
| 102 | + ->and($column->applyLimit(null))->toBeNull() |
| 103 | + ->and($column->applyLimit(['array']))->toBe(['array']); |
| 104 | +}); |
| 105 | + |
| 106 | +test('it accepts button config', function (): void { |
| 107 | + $column = JsonColumn::make('data') |
| 108 | + ->button(['color' => 'danger', 'label' => 'View']); |
| 109 | + |
| 110 | + $config = $column->getButtonConfig(); |
| 111 | + |
| 112 | + expect($config)->toBeInstanceOf(ButtonConfigDto::class) |
| 113 | + ->and($config->color)->toBe('danger') |
| 114 | + ->and($config->label)->toBe('View'); |
| 115 | +}); |
| 116 | + |
| 117 | +test('it accepts modal config', function (): void { |
| 118 | + $column = JsonColumn::make('data') |
| 119 | + ->modal(['width' => 'lg', 'closedByEscaping' => false]); |
| 120 | + |
| 121 | + $config = $column->getModalConfig(); |
| 122 | + |
| 123 | + expect($config)->toBeInstanceOf(ModalConfigDto::class) |
| 124 | + ->and($config->width)->toBe('lg') |
| 125 | + ->and($config->closedByEscaping)->toBeFalse(); |
| 126 | +}); |
| 127 | + |
| 128 | +test('initiallyCollapsed enforces minimum of 0', function (): void { |
| 129 | + $column = JsonColumn::make('data')->initiallyCollapsed(-1); |
| 130 | + |
| 131 | + expect($column->getInitiallyCollapsed())->toBe(0); |
| 132 | +}); |
| 133 | + |
| 134 | +test('maxDepth enforces minimum of 1', function (): void { |
| 135 | + $column = JsonColumn::make('data')->maxDepth(0); |
| 136 | + |
| 137 | + expect($column->getMaxDepth())->toBe(1); |
| 138 | +}); |
0 commit comments