diff --git a/app/Http/Controllers/SavedReportsController.php b/app/Http/Controllers/SavedReportsController.php
index fcb9b5460..a28af2aa9 100644
--- a/app/Http/Controllers/SavedReportsController.php
+++ b/app/Http/Controllers/SavedReportsController.php
@@ -9,13 +9,14 @@ class SavedReportsController extends Controller
{
public function store(Request $request)
{
+ // @todo: make this dynamic
$savedReport = SavedReport::first();
$savedReport->options = $request->except('_token');
$savedReport->save();
- // @todo: should this redirect elsewhere?
+ // @todo: redirect back with the saved report pre-populated?
return redirect()->back();
}
}
diff --git a/app/Models/SavedReport.php b/app/Models/SavedReport.php
index afefc37ba..417a6ccad 100644
--- a/app/Models/SavedReport.php
+++ b/app/Models/SavedReport.php
@@ -37,6 +37,17 @@ class SavedReport extends Model
return $this->options[$property] ?? '0';
}
+ public function radioValue($property, $value, $return)
+ {
+ // @todo: this method feels more like "radioShouldBeChecked" or something...
+
+ if (array_has($this->options, $property) && $this->options[$property] === $value) {
+ return $return;
+ }
+
+ return null;
+ }
+
public function selectValue($property)
{
return $this->options[$property] ?? null;
diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php
index e85271f8c..0dd623447 100644
--- a/resources/views/reports/custom.blade.php
+++ b/resources/views/reports/custom.blade.php
@@ -336,17 +336,16 @@
-
diff --git a/tests/Unit/SavedReportTest.php b/tests/Unit/SavedReportTest.php
index 294766708..b447b0d45 100644
--- a/tests/Unit/SavedReportTest.php
+++ b/tests/Unit/SavedReportTest.php
@@ -11,40 +11,53 @@ class SavedReportTest extends TestCase
{
$savedReport = SavedReport::factory()->create([
'options' => [
- 'is_a_checkbox_value' => '1',
+ 'is_a_checkbox_field' => '1',
],
]);
- $this->assertEquals('1', $savedReport->checkmarkValue('is_a_checkbox_value'));
+ $this->assertEquals('1', $savedReport->checkmarkValue('is_a_checkbox_field'));
$this->assertEquals('0', $savedReport->checkmarkValue('non_existent_key'));
- $this->assertEquals('1', (new SavedReport)->checkmarkValue('is_a_checkbox_value'));
+ $this->assertEquals('1', (new SavedReport)->checkmarkValue('is_a_checkbox_field'));
}
public function testParsingTextValue()
{
$savedReport = SavedReport::factory()->create([
'options' => [
- 'is_a_text_value' => 'some text',
+ 'is_a_text_field' => 'some text',
],
]);
- $this->assertEquals('some text', $savedReport->textValue('is_a_text_value'));
+ $this->assertEquals('some text', $savedReport->textValue('is_a_text_field'));
$this->assertEquals('', $savedReport->textValue('non_existent_key'));
- $this->assertEquals('', (new SavedReport)->textValue('is_a_text_value'));
+ $this->assertEquals('', (new SavedReport)->textValue('is_a_text_field'));
+ }
+
+ public function testParsingRadioValue()
+ {
+ $savedReport = SavedReport::factory()->create([
+ 'options' => [
+ 'is_a_radio_field' => null,
+ ],
+ ]);
+
+ $this->assertEquals('return_value', $savedReport->radioValue('is_a_radio_field', null, 'return_value'));
+ $this->assertEquals(null, $savedReport->radioValue('is_a_radio_field', 'another_value', 'return_value'));
+ $this->assertNull($savedReport->radioValue('non_existent_key', '1', true));
}
public function testParsingSelectValue()
{
$savedReport = SavedReport::factory()->create([
'options' => [
- 'is_a_text_value_as_well' => '4',
+ 'is_a_text_field_as_well' => '4',
'contains_a_null_value' => null,
],
]);
- $this->assertEquals('4', $savedReport->selectValue('is_a_text_value_as_well'));
+ $this->assertEquals('4', $savedReport->selectValue('is_a_text_field_as_well'));
$this->assertEquals('', $savedReport->selectValue('non_existent_key'));
$this->assertNull($savedReport->selectValue('contains_a_null_value'));
}
@@ -95,4 +108,22 @@ class SavedReportTest extends TestCase
// Another option would be to have checkbox that asks the user if they would like to save the dates?
// I'm not sure how helpful that is, and it would probably be a future feature if implemented.
}
+
+ public function testSavedReportHasDefaultValuesSet()
+ {
+ $this->markTestIncomplete();
+
+ // Quick thought: I think deleted_assets should be set to null so that
+ // "Exclude Deleted Assets" is selected when using a new'd up SavedReport.
+ }
+
+ public function testOldValuesStillWorkAfterTheseChanges()
+ {
+ $this->markTestIncomplete();
+
+ // Another marker that won't actually be a test case:
+ // We need to make sure that any behavior involving using "old" input.
+ // I explicitly removed the old()s from the "deleted_assets" radio buttons.
+ // The "x-selects" partials still include them, but I haven't tested them yet.
+ }
}