ResponsibleControllerTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Models\Dictionary\Area;
  4. use App\Models\Dictionary\District;
  5. use App\Models\Responsible;
  6. use App\Models\Role;
  7. use App\Models\User;
  8. use Illuminate\Foundation\Testing\RefreshDatabase;
  9. use Tests\TestCase;
  10. class ResponsibleControllerTest extends TestCase
  11. {
  12. use RefreshDatabase;
  13. protected $seed = true;
  14. private User $adminUser;
  15. protected function setUp(): void
  16. {
  17. parent::setUp();
  18. $this->adminUser = User::factory()->create(['role' => Role::ADMIN]);
  19. }
  20. public function test_responsibles_index_filters_by_area_name(): void
  21. {
  22. $district = District::factory()->create();
  23. $matchingResponsible = Responsible::query()->create([
  24. 'name' => 'Иван Иванов',
  25. 'phone' => '+79990000001',
  26. 'post' => 'Куратор',
  27. ]);
  28. $otherResponsible = Responsible::query()->create([
  29. 'name' => 'Петр Петров',
  30. 'phone' => '+79990000002',
  31. 'post' => 'Куратор',
  32. ]);
  33. Area::factory()->create([
  34. 'district_id' => $district->id,
  35. 'name' => 'Тверской',
  36. 'responsible_id' => $matchingResponsible->id,
  37. ]);
  38. Area::factory()->create([
  39. 'district_id' => $district->id,
  40. 'name' => 'Арбат',
  41. 'responsible_id' => $otherResponsible->id,
  42. ]);
  43. $response = $this->actingAs($this->adminUser)
  44. ->get(route('responsible.index', [
  45. 'filters' => ['area_name' => 'Тверской'],
  46. ]));
  47. $response->assertOk();
  48. $response->assertSee('Иван Иванов');
  49. $response->assertDontSee('Петр Петров');
  50. }
  51. public function test_responsible_area_filter_values_are_loaded_from_view(): void
  52. {
  53. $district = District::factory()->create();
  54. $responsible = Responsible::query()->create([
  55. 'name' => 'Иван Иванов',
  56. 'phone' => '+79990000001',
  57. 'post' => 'Куратор',
  58. ]);
  59. Area::factory()->create([
  60. 'district_id' => $district->id,
  61. 'name' => 'Тверской',
  62. 'responsible_id' => $responsible->id,
  63. ]);
  64. $response = $this->actingAs($this->adminUser)
  65. ->getJson(route('getFilters', [
  66. 'table' => 'responsibles',
  67. 'column' => 'area_name',
  68. ]));
  69. $response->assertOk();
  70. $response->assertJsonFragment(['Тверской']);
  71. }
  72. }