From fff6029af3c290936795870116058d07504335a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Fri, 12 Feb 2021 12:16:57 +0300 Subject: [PATCH] added export/ bulk action export and import feature test for bills.. --- tests/Feature/Purchases/BillsTest.php | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/Feature/Purchases/BillsTest.php b/tests/Feature/Purchases/BillsTest.php index b7e3a5e93..10a7866bc 100644 --- a/tests/Feature/Purchases/BillsTest.php +++ b/tests/Feature/Purchases/BillsTest.php @@ -2,8 +2,11 @@ namespace Tests\Feature\Purchases; +use App\Exports\Purchases\Bills as Export; use App\Jobs\Document\CreateDocument; use App\Models\Document\Document; +use Illuminate\Http\UploadedFile; +use Illuminate\Support\Facades\File; use Tests\Feature\FeatureTestCase; class BillsTest extends FeatureTestCase @@ -104,6 +107,69 @@ class BillsTest extends FeatureTestCase ]); } + public function testItShouldExportBills() + { + $count = 5; + Document::factory()->bill()->count($count)->create(); + + \Excel::fake(); + + $this->loginAs() + ->get(route('bills.export')) + ->assertStatus(200); + + \Excel::assertDownloaded( + \Str::filename(trans_choice('general.bills', 2)) . '.xlsx', + function (Export $export) use ($count) { + // Assert that the correct export is downloaded. + return $export->sheets()['bills']->collection()->count() === $count; + } + ); + } + + public function testItShouldExportSelectedBills() + { + $count = 5; + $bills = Document::factory()->bill()->count($count)->create(); + + \Excel::fake(); + + $this->loginAs() + ->post( + route('bulk-actions.action', ['group' => 'purchases', 'type' => 'bills']), + ['handle' => 'export', 'selected' => [$bills->random()->id]] + ) + ->assertStatus(200); + + \Excel::assertDownloaded( + \Str::filename(trans_choice('general.bills', 2)) . '.xlsx', + function (Export $export) { + return $export->sheets()['bills']->collection()->count() === 1; + } + ); + } + + public function testItShouldImportBills() + { + \Excel::fake(); + + $this->loginAs() + ->post( + route('bills.import'), + [ + 'import' => UploadedFile::fake()->createWithContent( + 'bills.xlsx', + File::get(public_path('files/import/bills.xlsx')) + ), + ] + ) + ->assertStatus(200); + + \Excel::assertImported('bills.xlsx'); + + $this->assertFlashLevel('success'); + } + public function getRequest($recurring = false) { $factory = Document::factory();