Automatically check the send email to user checkbox in certain conditions

This commit is contained in:
Marcus Moore 2023-08-02 16:04:01 -07:00
parent dee6ebf8e0
commit 269414e4f2
No known key found for this signature in database
2 changed files with 66 additions and 1 deletions

View file

@ -18,7 +18,9 @@ class CategoryEditForm extends Component
public function mount() public function mount()
{ {
if ($this->eulaText || $this->useDefaultEula) {
$this->checkinEmail = true;
}
} }
public function render() public function render()
@ -26,6 +28,13 @@ class CategoryEditForm extends Component
return view('livewire.category-edit-form'); return view('livewire.category-edit-form');
} }
public function updated($property, $value)
{
if (in_array($property, ['eulaText', 'useDefaultEula']) && ($this->eulaText || $this->useDefaultEula)) {
$this->checkinEmail = (bool)$value;
}
}
public function getShouldDisplayEmailMessageProperty(): bool public function getShouldDisplayEmailMessageProperty(): bool
{ {
return $this->eulaText || $this->useDefaultEula; return $this->eulaText || $this->useDefaultEula;

View file

@ -12,4 +12,60 @@ class CategoryEditFormTest extends TestCase
{ {
Livewire::test(CategoryEditForm::class)->assertStatus(200); Livewire::test(CategoryEditForm::class)->assertStatus(200);
} }
public function testSendEmailCheckboxIsCheckedOnLoadWhenSendEmailIsExistingSetting()
{
Livewire::test(CategoryEditForm::class, [
'checkinEmail' => true,
'eulaText' => '',
'useDefaultEula' => false,
])->assertSet('checkinEmail', true);
}
public function testSendEmailCheckboxIsCheckedOnLoadWhenCategoryEulaSet()
{
Livewire::test(CategoryEditForm::class, [
'checkinEmail' => false,
'eulaText' => 'Some Content',
'useDefaultEula' => false,
])->assertSet('checkinEmail', true);
}
public function testSendEmailCheckboxIsCheckedOnLoadWhenUsingDefaultEula()
{
Livewire::test(CategoryEditForm::class, [
'checkinEmail' => false,
'eulaText' => '',
'useDefaultEula' => true,
])->assertSet('checkinEmail', true);
}
public function testSendEmailCheckBoxIsUncheckedOnLoadWhenSendEmailIsFalseNoCategoryEulaSetAndNotUsingDefaultEula()
{
Livewire::test(CategoryEditForm::class, [
'checkinEmail' => false,
'eulaText' => '',
'useDefaultEula' => false,
])->assertSet('checkinEmail', false);
}
public function testSendEmailCheckboxIsCheckedWhenCategoryEulaEntered()
{
Livewire::test(CategoryEditForm::class, [
'checkinEmail' => false,
'useDefaultEula' => false,
])->assertSet('checkinEmail', false)
->set('eulaText', 'Some Content')
->assertSet('checkinEmail', true);
}
public function testSendEmailCheckboxCheckedWhenUseDefaultEulaSelected()
{
Livewire::test(CategoryEditForm::class, [
'checkinEmail' => false,
'useDefaultEula' => false,
])->assertSet('checkinEmail', false)
->set('useDefaultEula', true)
->assertSet('checkinEmail', true);
}
} }