Skip to content

Commit 15f0df2

Browse files
committed
Add table options tests
1 parent fd4e9e8 commit 15f0df2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/BuilderTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Yajra\DataTables\Html\Tests;
44

5+
use Illuminate\Support\HtmlString;
56
use Yajra\DataTables\Html\Builder;
67
use Yajra\DataTables\Html\Column;
78
use Yajra\DataTables\Html\ColumnDefinition;
@@ -209,4 +210,26 @@ public function it_has_column_defs()
209210
$this->assertEquals([['targets' => 1]], $builder->getAttribute('columnDefs'));
210211
$this->assertCount(1, $builder->getAttribute('columnDefs'));
211212
}
213+
214+
/** @test */
215+
public function it_has_table_options()
216+
{
217+
$builder = $this->getHtmlBuilder();
218+
$builder->setTableId('my-table');
219+
220+
$this->assertEquals('my-table', $builder->getTableId());
221+
$this->assertEquals(['id' => 'my-table', 'class' => 'table'], $builder->getTableAttributes());
222+
223+
$builder->setTableAttribute('class', 'dTable');
224+
$this->assertEquals(['id' => 'my-table', 'class' => 'dTable'], $builder->getTableAttributes());
225+
226+
$builder->addTableClass('table');
227+
$this->assertEquals(['id' => 'my-table', 'class' => 'dTable table'], $builder->getTableAttributes());
228+
229+
$builder->removeTableClass('dTable');
230+
$this->assertEquals(['id' => 'my-table', 'class' => 'table'], $builder->getTableAttributes());
231+
232+
$this->assertInstanceOf(HtmlString::class, $builder->table());
233+
$this->assertEquals('<table class="table" id="my-table"><thead><tr></tr></thead></table>', $builder->table()->toHtml());
234+
}
212235
}

0 commit comments

Comments
 (0)