fixed tests and bulk action export
This commit is contained in:
		| @@ -96,33 +96,40 @@ class ItemsTest extends FeatureTestCase | ||||
|             ->get(route('items.export')) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::matchByRegex(); | ||||
|  | ||||
|         \Excel::assertDownloaded( | ||||
|             \Str::filename(trans_choice('general.items', 2)) . '.xlsx', | ||||
|             '/' . \Str::filename(trans_choice('general.items', 2)) . '-\d{10}\.xlsx/', | ||||
|             function (Export $export) use ($count) { | ||||
|                 // Assert that the correct export is downloaded. | ||||
|                 return $export->sheets()['items']->collection()->count() === $count; | ||||
|                 return $export->sheets()[0]->collection()->count() === $count; | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldExportSelectedItems() | ||||
|     { | ||||
|         $count = 5; | ||||
|         $items = Item::factory()->count($count)->create(); | ||||
|         $create_count = 5; | ||||
|         $select_count = 3; | ||||
|  | ||||
|         $items = Item::factory()->count($create_count)->create(); | ||||
|  | ||||
|         \Excel::fake(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post( | ||||
|                 route('bulk-actions.action', ['group' => 'common', 'type' => 'items']), | ||||
|                 ['handle' => 'export', 'selected' => [$items->random()->id]] | ||||
|                 ['handle' => 'export', 'selected' => $items->take($select_count)->pluck('id')->toArray()] | ||||
|             ) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::matchByRegex(); | ||||
|  | ||||
|         \Excel::assertDownloaded( | ||||
|             \Str::filename(trans_choice('general.items', 2)) . '.xlsx', | ||||
|             function (Export $export) { | ||||
|                 return $export->sheets()['items']->collection()->count() === 1; | ||||
|             '/' . \Str::filename(trans_choice('general.items', 2)) . '-\d{10}\.xlsx/', | ||||
|             function (Export $export) use ($select_count) { | ||||
|                 // Assert that the correct export is downloaded. | ||||
|                 return $export->sheets()[0]->collection()->count() === $select_count; | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user