added export/ bulk action export and import feature test for vendors..
This commit is contained in:
parent
d7bd69eb5f
commit
a94c9dc9c5
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Purchases;
|
namespace Tests\Feature\Purchases;
|
||||||
|
|
||||||
|
use App\Exports\Common\Contacts as Export;
|
||||||
use App\Jobs\Common\CreateContact;
|
use App\Jobs\Common\CreateContact;
|
||||||
use App\Models\Common\Contact;
|
use App\Models\Common\Contact;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class VendorsTest extends FeatureTestCase
|
class VendorsTest extends FeatureTestCase
|
||||||
@ -96,6 +99,70 @@ class VendorsTest extends FeatureTestCase
|
|||||||
$this->assertSoftDeleted('contacts', $request);
|
$this->assertSoftDeleted('contacts', $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportVendors()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
Contact::factory()->vendor()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->get(route('vendors.export'))
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.vendors', 2)) . '.xlsx',
|
||||||
|
function (Export $export) use ($count) {
|
||||||
|
// Assert that the correct export is downloaded.
|
||||||
|
return $export->collection()->count() === $count;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportSelectedVendors()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
$vendors = Contact::factory()->vendor()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('bulk-actions.action', ['group' => 'purchases', 'type' => 'vendors']),
|
||||||
|
['handle' => 'export', 'selected' => [$vendors->random()->id]]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.vendors', 2)) . '.xlsx',
|
||||||
|
function (Export $export) {
|
||||||
|
return $export->collection()->count() === 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldImportVendors()
|
||||||
|
{
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('vendors.import'),
|
||||||
|
[
|
||||||
|
'import' => UploadedFile::fake()->createWithContent(
|
||||||
|
'vendors.xlsx',
|
||||||
|
File::get(public_path('files/import/vendors.xlsx'))
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertImported('vendors.xlsx');
|
||||||
|
|
||||||
|
$this->assertFlashLevel('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return Contact::factory()->vendor()->enabled()->raw();
|
return Contact::factory()->vendor()->enabled()->raw();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user