Skip to content

Commit

Permalink
ConfigurableArea Test Tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe committed Jan 23, 2025
1 parent 74f6a5f commit 31561e5
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 84 deletions.
20 changes: 0 additions & 20 deletions tests/Unit/Traits/Configuration/ComponentConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,26 +294,6 @@ public function test_can_set_tr_url_target_advanced(): void
$this->assertSame($this->basicTable->getTableRowUrlTarget(2), 'navigate');
}

public function test_can_set_hide_configurable_areas_when_reordering_status(): void
{
$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());

$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(false);

$this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());

$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true);

$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());

$this->basicTable->setHideConfigurableAreasWhenReorderingDisabled();

$this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());

$this->basicTable->setHideConfigurableAreasWhenReorderingEnabled();

$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true);
}

public function test_no_extra_withs_by_default(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,99 @@

namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Configuration;

use PHPUnit\Framework\Attributes\DataProvider;
use Rappasoft\LaravelLivewireTables\Tests\TestCase;

final class ConfigurableAreaConfigurationTest extends TestCase
{
public function test_can_set_configurable_area(): void

public static function configurableAreaProvider(): array
{
return [
['before-tools', 'path.to.my.before-tools.view'],
['toolbar-left-start', 'path.to.my.toolbar-left-start.view'],
['toolbar-left-end', 'path.to.my.toolbar-left-end.view'],
['toolbar-right-start', 'path.to.my.toolbar-right-start.view'],
['toolbar-right-end', 'path.to.my.toolbar-right-end.view'],
['before-toolbar', 'path.to.my.before-toolbar.view'],
['after-toolbar', 'path.to.my.after-toolbar.view'],
['after-tools', 'path.to.my.after-tools.view'],
['before-pagination', 'path.to.my.before-pagination.view'],
['after-pagination', 'path.to.my.after-pagination.view'],
];
}

#[DataProvider('configurableAreaProvider')]
public function test_can_set_configurable_area(string $configurableArea, string $configurableAreaViewPath): void
{
$defaults = [
'before-tools' => null,
'toolbar-left-start' => null,
'toolbar-left-end' => null,
'toolbar-right-start' => null,
'toolbar-right-end' => null,
'before-toolbar' => null,
'after-toolbar' => null,
'after-tools' => null,
'before-pagination' => null,
'after-pagination' => null,
];
$this->basicTable->setConfigurableAreas($defaults);

$this->assertNull($this->basicTable->getConfigurableAreaFor($configurableArea));

$this->basicTable->setConfigurableArea($configurableArea, $configurableAreaViewPath);

$this->assertSame($configurableAreaViewPath, $this->basicTable->getConfigurableAreaFor($configurableArea));
}

public function test_can_set_multiple_configurable_areas(): void
{
$defaults = [
'before-tools' => null,
'toolbar-left-start' => null,
'toolbar-left-end' => null,
'toolbar-right-start' => null,
'toolbar-right-end' => null,
'before-toolbar' => null,
'after-toolbar' => null,
'after-tools' => null,
'before-pagination' => null,
'after-pagination' => null,
];
$this->basicTable->setConfigurableAreas($defaults);

$this->assertNull($this->basicTable->getConfigurableAreaFor('before-tools'));
$this->assertNull($this->basicTable->getConfigurableAreaFor('after-toolbar'));

$this->basicTable->setConfigurableArea('before-tools', 'path.to.before-tools.view');
$this->assertSame('path.to.before-tools.view', $this->basicTable->getConfigurableAreaFor('before-tools'));

$this->basicTable->setConfigurableArea('before-tools', 'path.to.my.view');
$this->basicTable->setConfigurableArea('after-toolbar', 'path.to.after-toolbar.view');
$this->assertSame('path.to.after-toolbar.view', $this->basicTable->getConfigurableAreaFor('after-toolbar'));
$this->assertSame('path.to.before-tools.view', $this->basicTable->getConfigurableAreaFor('before-tools'));

$this->assertSame('path.to.my.view', $this->basicTable->getConfigurableAreaFor('before-tools'));
}

public function test_can_set_hide_configurable_areas_when_reordering_status(): void
{
$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());

$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(false);

$this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());

$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true);

$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());

$this->basicTable->setHideConfigurableAreasWhenReorderingDisabled();

$this->assertFalse($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());

$this->basicTable->setHideConfigurableAreasWhenReorderingEnabled();

$this->basicTable->setHideConfigurableAreasWhenReorderingStatus(true);
}

}
61 changes: 0 additions & 61 deletions tests/Unit/Traits/Helpers/ComponentHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,67 +181,6 @@ public function test_can_add_additional_selects_nonarray(): void
$this->assertEquals(['name', 'updated_at'], $this->basicTable->getAdditionalSelects());
}

public function test_can_get_configurable_areas(): void
{
$this->assertEquals([
'before-tools' => null,
'toolbar-left-start' => null,
'toolbar-left-end' => null,
'toolbar-right-start' => null,
'toolbar-right-end' => null,
'before-toolbar' => null,
'after-toolbar' => null,
'after-tools' => null,
'before-pagination' => null,
'after-pagination' => null,
], $this->basicTable->getConfigurableAreas());

$this->basicTable->setConfigurableAreas([
'toolbar-left-start' => 'includes.areas.toolbar-left-start',
]);

$this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start'));

$this->basicTable->setConfigurableAreas([
'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']],
]);

$this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start'));
}

public function test_can_get_configurable_area_parameters(): void
{
$this->basicTable->setConfigurableAreas([
'toolbar-left-start' => 'includes.areas.toolbar-left-start',
]);

$this->assertEquals([], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start'));

$this->basicTable->setConfigurableAreas([
'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']],
]);

$this->assertEquals(['param1' => 'hello'], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start'));
}

public function test_can_get_hide_configurable_areas_when_reordering_status(): void
{
$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());

$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());

$this->basicTable->setHideConfigurableAreasWhenReorderingDisabled();

$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled());

$this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());

$this->basicTable->setHideConfigurableAreasWhenReorderingEnabled();

$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());

$this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled());
}

// Exists in DataTableComponentTest
// public function test_can_get_dataTable_fingerprint(): void
Expand Down
72 changes: 72 additions & 0 deletions tests/Unit/Traits/Helpers/ConfigurableAreaHelpersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Helpers;

use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
use Rappasoft\LaravelLivewireTables\Tests\TestCase;

final class ConfigurableAreaHelpersTest extends TestCase
{
public function test_can_get_configurable_areas(): void
{
$this->assertEquals([
'before-tools' => null,
'toolbar-left-start' => null,
'toolbar-left-end' => null,
'toolbar-right-start' => null,
'toolbar-right-end' => null,
'before-toolbar' => null,
'after-toolbar' => null,
'after-tools' => null,
'before-pagination' => null,
'after-pagination' => null,
], $this->basicTable->getConfigurableAreas());

$this->basicTable->setConfigurableAreas([
'toolbar-left-start' => 'includes.areas.toolbar-left-start',
]);

$this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start'));

$this->basicTable->setConfigurableAreas([
'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']],
]);

$this->assertEquals('includes.areas.toolbar-left-start', $this->basicTable->getConfigurableAreaFor('toolbar-left-start'));
}

public function test_can_get_configurable_area_parameters(): void
{
$this->basicTable->setConfigurableAreas([
'toolbar-left-start' => 'includes.areas.toolbar-left-start',
]);

$this->assertEquals([], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start'));

$this->basicTable->setConfigurableAreas([
'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => 'hello']],
]);

$this->assertEquals(['param1' => 'hello'], $this->basicTable->getParametersForConfigurableArea('toolbar-left-start'));
}

public function test_can_get_hide_configurable_areas_when_reordering_status(): void
{
$this->assertTrue($this->basicTable->getHideConfigurableAreasWhenReorderingStatus());

$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());

$this->basicTable->setHideConfigurableAreasWhenReorderingDisabled();

$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled());

$this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());

$this->basicTable->setHideConfigurableAreasWhenReorderingEnabled();

$this->assertTrue($this->basicTable->hideConfigurableAreasWhenReorderingIsEnabled());

$this->assertFalse($this->basicTable->hideConfigurableAreasWhenReorderingIsDisabled());
}

}

0 comments on commit 31561e5

Please sign in to comment.