| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace Tests\Feature;
- use App\Models\Dictionary\Area;
- use App\Models\Dictionary\District;
- use App\Models\Responsible;
- use App\Models\Role;
- use App\Models\User;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Tests\TestCase;
- class ResponsibleControllerTest extends TestCase
- {
- use RefreshDatabase;
- protected $seed = true;
- private User $adminUser;
- protected function setUp(): void
- {
- parent::setUp();
- $this->adminUser = User::factory()->create(['role' => Role::ADMIN]);
- }
- public function test_responsibles_index_filters_by_area_name(): void
- {
- $district = District::factory()->create();
- $matchingResponsible = Responsible::query()->create([
- 'name' => 'Иван Иванов',
- 'phone' => '+79990000001',
- 'post' => 'Куратор',
- ]);
- $otherResponsible = Responsible::query()->create([
- 'name' => 'Петр Петров',
- 'phone' => '+79990000002',
- 'post' => 'Куратор',
- ]);
- Area::factory()->create([
- 'district_id' => $district->id,
- 'name' => 'Тверской',
- 'responsible_id' => $matchingResponsible->id,
- ]);
- Area::factory()->create([
- 'district_id' => $district->id,
- 'name' => 'Арбат',
- 'responsible_id' => $otherResponsible->id,
- ]);
- $response = $this->actingAs($this->adminUser)
- ->get(route('responsible.index', [
- 'filters' => ['area_name' => 'Тверской'],
- ]));
- $response->assertOk();
- $response->assertSee('Иван Иванов');
- $response->assertDontSee('Петр Петров');
- }
- public function test_responsible_area_filter_values_are_loaded_from_view(): void
- {
- $district = District::factory()->create();
- $responsible = Responsible::query()->create([
- 'name' => 'Иван Иванов',
- 'phone' => '+79990000001',
- 'post' => 'Куратор',
- ]);
- Area::factory()->create([
- 'district_id' => $district->id,
- 'name' => 'Тверской',
- 'responsible_id' => $responsible->id,
- ]);
- $response = $this->actingAs($this->adminUser)
- ->getJson(route('getFilters', [
- 'table' => 'responsibles',
- 'column' => 'area_name',
- ]));
- $response->assertOk();
- $response->assertJsonFragment(['Тверской']);
- }
- }
|