This commit is contained in:
Dan Harrin
2025-04-07 10:24:45 +01:00
parent 6a0503ed1d
commit c768180a70
2 changed files with 10 additions and 25 deletions
+6 -13
View File
@@ -74,7 +74,7 @@ trait HasCellState
return $this->evaluate($this->defaultState);
}
public function getState(): mixed
public function getState(bool $isCached = true): mixed
{
$record = $this->getRecord();
@@ -84,7 +84,7 @@ trait HasCellState
$recordKey = (string) $record->getKey();
if (array_key_exists($recordKey, $this->cachedState)) {
if ($isCached && array_key_exists($recordKey, $this->cachedState)) {
return $this->cachedState[$recordKey];
}
@@ -103,6 +103,10 @@ trait HasCellState
$state = $this->getDefaultState();
}
if (! $isCached) {
return $state;
}
return $this->cachedState[$recordKey] = $state;
}
@@ -142,17 +146,6 @@ trait HasCellState
return $state->all();
}
public function clearCache(): static
{
if (! app()->isRunningUnitTests()) {
throw new Exception('Clearing cache is only available in unit tests.');
}
$this->cachedState = [];
return $this;
}
public function separator(string | Closure | null $separator = ','): static
{
$this->separator = $separator;
+4 -12
View File
@@ -180,9 +180,7 @@ class TestsColumns
$livewireClass = $this->instance()::class;
$column->clearCache();
$state = $column->getState();
$state = $column->getState(isCached: false);
if (is_array($state)) {
$state = json_encode($state);
@@ -218,9 +216,7 @@ class TestsColumns
$livewireClass = $this->instance()::class;
$column->clearCache();
$state = $column->getState();
$state = $column->getState(isCached: false);
if (is_array($state)) {
$state = json_encode($state);
@@ -256,11 +252,9 @@ class TestsColumns
$livewireClass = $this->instance()::class;
$column->clearCache();
Assert::assertEquals(
$value,
$column->formatState($column->getState()),
$column->formatState($column->getState(isCached: false)),
message: "Failed asserting that a table column with name [{$name}] has a formatted state of [{$value}] for record [{$record->getKey()}] on the [{$livewireClass}] component.",
);
@@ -285,10 +279,8 @@ class TestsColumns
$livewireClass = $this->instance()::class;
$column->clearCache();
Assert::assertFalse(
$column->formatState($column->getState()) == $value,
$column->formatState($column->getState(isCached: false)) == $value,
message: "Failed asserting that a table column with name [{$name}] does not have a formatted state of [{$value}] for record [{$record->getKey()}] on the [{$livewireClass}] component.",
);