Skip to content

Commit 4cc6d1d

Browse files
committed
Add test for csv, xls & pdf download.
1 parent 331b501 commit 4cc6d1d

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

tests/DataTableServiceTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Yajra\DataTables\Buttons\Tests;
44

55
use Illuminate\Foundation\Testing\DatabaseTransactions;
6+
use Illuminate\Http\Response;
7+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
68
use Yajra\DataTables\Buttons\Tests\DataTables\UsersDataTable;
79

810
class DataTableServiceTest extends TestCase
@@ -21,6 +23,39 @@ public function it_can_handle_ajax_request()
2123
]);
2224
}
2325

26+
/** @test */
27+
public function it_returns_view_on_normal_get_request()
28+
{
29+
$response = $this->get('users');
30+
31+
$response->assertSeeText('users-table');
32+
$response->assertSeeText('LaravelDataTables');
33+
}
34+
35+
/** @test */
36+
public function it_can_return_a_csv_file()
37+
{
38+
$response = $this->get('users?action=csv');
39+
40+
$this->assertInstanceOf(BinaryFileResponse::class, $response->baseResponse);
41+
}
42+
43+
/** @test */
44+
public function it_can_return_a_xls_file()
45+
{
46+
$response = $this->get('users?action=excel');
47+
48+
$this->assertInstanceOf(BinaryFileResponse::class, $response->baseResponse);
49+
}
50+
51+
/** @test */
52+
public function it_can_return_a_pdf_file()
53+
{
54+
$response = $this->get('users?action=pdf');
55+
56+
$this->assertInstanceOf(Response::class, $response->baseResponse);
57+
}
58+
2459
protected function setUp(): void
2560
{
2661
parent::setUp();

tests/DataTables/UsersDataTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function query(User $user): Builder
2323
return $user->newQuery()->select('*');
2424
}
2525

26-
public function html()
26+
public function html(): \Yajra\DataTables\Html\Builder
2727
{
2828
return $this->builder()
2929
->setTableId('users-table')

tests/TestCase.php

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

33
namespace Yajra\DataTables\Buttons\Tests;
44

5+
use Barryvdh\Snappy\ServiceProvider;
56
use Illuminate\Database\Schema\Blueprint;
67
use Illuminate\Testing\TestResponse;
78
use Orchestra\Testbench\TestCase as BaseTestCase;
@@ -110,6 +111,7 @@ protected function getPackageProviders($app): array
110111
DataTablesServiceProvider::class,
111112
ButtonsServiceProvider::class,
112113
HtmlServiceProvider::class,
114+
ServiceProvider::class,
113115
];
114116
}
115117

tests/views/users.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{ $dataTable->table() }}
2+
3+
{{ $dataTable->scripts() }}

0 commit comments

Comments
 (0)