Skip to content

Commit 4bf32e2

Browse files
Copilotnielsdrost7
andauthored
Fix Filament action imports, grid calculations, and refactor test mocks to fakes in Report Builder (#351)
* Initial plan * Fix ReportBlocksTable imports, actions, GridSnapperService, test mock, and CSS syntax Co-authored-by: nielsdrost7 <47660417+nielsdrost7@users.noreply.github.com> * Refactor tests to use Storage::fake() instead of mocking repository Co-authored-by: nielsdrost7 <47660417+nielsdrost7@users.noreply.github.com> * Change actions to recordActions in ReportBlocksTable --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nielsdrost7 <47660417+nielsdrost7@users.noreply.github.com>
1 parent 7bdbf52 commit 4bf32e2

4 files changed

Lines changed: 35 additions & 24 deletions

File tree

Modules/Core/Filament/Admin/Resources/ReportBlocks/Tables/ReportBlocksTable.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Modules\Core\Filament\Admin\Resources\ReportBlocks\Tables;
44

5-
use Filament\Actions\ActionGroup;
6-
use Filament\Actions\DeleteAction;
7-
use Filament\Actions\EditAction;
5+
use Filament\Tables\Actions\ActionGroup;
6+
use Filament\Tables\Actions\DeleteAction;
7+
use Filament\Tables\Actions\EditAction;
88
use Filament\Tables\Columns\IconColumn;
99
use Filament\Tables\Columns\TextColumn;
1010
use Filament\Tables\Table;
@@ -40,7 +40,7 @@ public static function configure(Table $table): Table
4040
ActionGroup::make([
4141
EditAction::make(),
4242
DeleteAction::make('delete')
43-
->action(function (ReportBlock $record, array $data) {
43+
->action(function (ReportBlock $record) {
4444
app(ReportBlockService::class)->deleteReportBlock($record);
4545
}),
4646
]),

Modules/Core/Services/GridSnapperService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function snap(GridPositionDTO $position): GridPositionDTO
2626
{
2727
$x = max(0, min($position->getX(), $this->gridSize - 1));
2828
$y = max(0, $position->getY());
29-
$width = max(1, min($position->getWidth(), $this->gridSize - $position->getX()));
29+
$width = max(1, min($position->getWidth(), $this->gridSize - $x));
3030
$height = max(1, $position->getHeight());
3131

3232
return GridPositionDTO::create($x, $y, $width, $height);

Modules/Core/Tests/Unit/ReportTemplateServiceTest.php

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Modules\Core\Tests\Unit;
44

5+
use Illuminate\Support\Facades\Storage;
56
use InvalidArgumentException;
67
use Modules\Core\DTOs\BlockDTO;
78
use Modules\Core\DTOs\GridPositionDTO;
@@ -26,7 +27,9 @@ protected function setUp(): void
2627
{
2728
parent::setUp();
2829

29-
$this->fileRepository = $this->createMock(ReportTemplateFileRepository::class);
30+
Storage::fake('report_templates');
31+
32+
$this->fileRepository = new ReportTemplateFileRepository();
3033
$this->gridSnapper = new GridSnapperService(12);
3134
$this->service = new ReportTemplateService($this->fileRepository, $this->gridSnapper);
3235
}
@@ -200,22 +203,28 @@ public function it_persists_blocks(): void
200203
$template->slug = 'test-template';
201204

202205
$position = new GridPositionDTO();
203-
204-
/* act */
205206
$position->setX(0)->setY(0)->setWidth(6)->setHeight(4);
206207

207-
/* assert */
208208
$block = new BlockDTO();
209209
$block->setId('block_1')
210210
->setType('company_header')
211211
->setPosition($position)
212212
->setConfig([])
213213
->setIsCloneable(true)
214214
->setIsCloned(false);
215-
$this->fileRepository->expects($this->once())
216-
->method('save')
217-
->with(1, 'test-template', $this->isType('array'));
215+
216+
/* act */
218217
$this->service->persistBlocks($template, [$block]);
218+
219+
/* assert */
220+
Storage::disk('report_templates')->assertExists('1/test-template.json');
221+
$content = Storage::disk('report_templates')->get('1/test-template.json');
222+
$data = json_decode($content, true);
223+
224+
$this->assertIsArray($data);
225+
$this->assertCount(1, $data);
226+
$this->assertEquals('block_1', $data[0]['id']);
227+
$this->assertEquals('company_header', $data[0]['type']);
219228
}
220229

221230
#[Test]
@@ -227,17 +236,19 @@ public function it_loads_blocks(): void
227236
$template->company_id = 1;
228237
$template->slug = 'test-template';
229238

230-
$this->fileRepository->expects($this->once())
231-
->method('load')
232-
->with(1, 'test-template')
233-
->willReturn([
234-
[
235-
'id' => 'block_1',
236-
'type' => 'company_header',
237-
'position' => ['x' => 0, 'y' => 0, 'width' => 6, 'height' => 4],
238-
'config' => [],
239-
],
240-
]);
239+
$fileData = [
240+
[
241+
'id' => 'block_1',
242+
'type' => 'company_header',
243+
'position' => ['x' => 0, 'y' => 0, 'width' => 6, 'height' => 4],
244+
'config' => [],
245+
],
246+
];
247+
248+
Storage::disk('report_templates')->put(
249+
'1/test-template.json',
250+
json_encode($fileData, JSON_PRETTY_PRINT)
251+
);
241252

242253
/* act */
243254
$blocks = $this->service->loadBlocks($template);

resources/css/filament/company/invoiceplane.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
.fi-sidebar-item.fi-active {
6060
@apply text-white;
61-
@apply !bg-primary-700;
61+
@apply bg-primary-700!;
6262
@apply rounded-lg;
6363
}
6464

0 commit comments

Comments
 (0)