Skip to content

Commit b35294a

Browse files
committed
Add Editor test
1 parent db9ff5f commit b35294a

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

src/Html/Editor/Editor.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@
99
use Yajra\DataTables\Utilities\Helper;
1010

1111
/**
12+
* @property string $instance
1213
* @property string|null $table
1314
* @property string|array|null $ajax
14-
* @property array $events
15+
* @property array $fields
16+
* @property string|null $template
1517
*/
1618
class Editor extends Fluent
1719
{
1820
use HasEvents;
1921
use HasAuthorizations;
2022

23+
public array $events = [];
24+
2125
const DISPLAY_LIGHTBOX = 'lightbox';
2226
const DISPLAY_ENVELOPE = 'envelope';
2327
const DISPLAY_BOOTSTRAP = 'bootstrap';
@@ -167,7 +171,6 @@ public function formOptions(array $formOptions): static
167171
*
168172
* @param array $formOptions
169173
* @return $this
170-
* @throws \Yajra\DataTables\Exceptions\Exception
171174
* @see https://editor.datatables.net/reference/option/formOptions.bubble
172175
*/
173176
public function formOptionsBubble(array $formOptions): static
@@ -180,7 +183,6 @@ public function formOptionsBubble(array $formOptions): static
180183
*
181184
* @param array $formOptions
182185
* @return $this
183-
* @throws \Yajra\DataTables\Exceptions\Exception
184186
* @see https://editor.datatables.net/reference/option/formOptions.inline
185187
*/
186188
public function formOptionsInline(array $formOptions): static
@@ -193,7 +195,6 @@ public function formOptionsInline(array $formOptions): static
193195
*
194196
* @param array $formOptions
195197
* @return $this
196-
* @throws \Yajra\DataTables\Exceptions\Exception
197198
* @see https://editor.datatables.net/reference/option/formOptions.main
198199
*/
199200
public function formOptionsMain(array $formOptions): static

tests/EditorTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Yajra\DataTables\Html\Tests;
4+
5+
use Yajra\DataTables\Html\Editor\Editor;
6+
use Yajra\DataTables\Html\Editor\Fields\Text;
7+
8+
class EditorTest extends TestCase
9+
{
10+
/** @test */
11+
public function it_can_create_an_editor()
12+
{
13+
$editor = $this->getEditor();
14+
15+
$this->assertInstanceOf(Editor::class, $editor);
16+
$this->assertEquals('editor', $editor->instance);
17+
$this->assertEmpty($editor->fields);
18+
$this->assertEmpty($editor->ajax);
19+
$this->assertEmpty($editor->template);
20+
21+
$editor
22+
->fields([
23+
Text::make('name'),
24+
])
25+
->ajax('/test')
26+
->template('#template');
27+
28+
$this->assertCount(1, $editor->fields);
29+
$this->assertEquals('/test', $editor->ajax);
30+
$this->assertEquals('#template', $editor->template);
31+
}
32+
33+
/** @test */
34+
public function it_can_have_events()
35+
{
36+
$editor = $this->getEditor();
37+
38+
$editor->onPostSubmit('post');
39+
$editor->onDisplayOrder('display');
40+
41+
$this->assertCount(2, $editor->events);
42+
43+
$event = [
44+
'event' => 'postSubmit',
45+
'script' => 'post',
46+
];
47+
48+
$this->assertEquals($event, $editor->events[0]);
49+
}
50+
51+
/**
52+
* @param string $instance
53+
* @return \Yajra\DataTables\Html\Editor\Editor
54+
*/
55+
protected function getEditor(string $instance = 'editor'): Editor
56+
{
57+
return Editor::make($instance);
58+
}
59+
}

0 commit comments

Comments
 (0)