|
2 | 2 |
|
3 | 3 | namespace Javaabu\Forms\Tests\Feature; |
4 | 4 |
|
| 5 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 6 | +use Illuminate\Support\Facades\Route; |
5 | 7 | use Javaabu\Forms\Tests\TestCase; |
| 8 | +use Javaabu\Forms\Tests\TestSupport\Models\Category; |
6 | 9 |
|
7 | 10 | class SelectTest extends TestCase |
8 | 11 | { |
| 12 | + use RefreshDatabase; |
| 13 | + |
9 | 14 | /** @test */ |
10 | 15 | public function it_shows_the_slot_if_the_options_are_empty() |
11 | 16 | { |
@@ -40,4 +45,48 @@ public function it_adds_a_sync_field_for_multi_selects() |
40 | 45 | ->seeElement('option[value="b"]') |
41 | 46 | ->seeElement('option[value="c"]'); |
42 | 47 | } |
| 48 | + |
| 49 | + /** @test */ |
| 50 | + public function it_can_exclude_the_sync_field_for_multi_selects() |
| 51 | + { |
| 52 | + $this->registerTestRoute('select-sync-field'); |
| 53 | + |
| 54 | + $this->visit('/select-sync-field') |
| 55 | + ->dontSeeElement('input[type="hidden"][name="sync_exclude_sync"]') |
| 56 | + ->dontSeeElement('input[type="hidden"][name="sync_disabled_sync"]') |
| 57 | + ->seeElement('input[type="hidden"][name="custom_sync_name"][value="1"]'); |
| 58 | + } |
| 59 | + |
| 60 | + /** @test */ |
| 61 | + public function it_includes_old_values_for_tags() |
| 62 | + { |
| 63 | + $this->registerTestRoute('select-tags'); |
| 64 | + |
| 65 | + $this->session(['_old_input' => ['tags' => ['a', 'b', 'c']]]); |
| 66 | + |
| 67 | + $this->visit('/select-tags') |
| 68 | + ->seeElement('option[value="a"]:selected') |
| 69 | + ->seeElement('option[value="b"]:selected') |
| 70 | + ->seeElement('option[value="c"]:selected'); |
| 71 | + } |
| 72 | + |
| 73 | + /** @test */ |
| 74 | + public function it_can_load_options_from_a_translatable_model() |
| 75 | + { |
| 76 | + $category1 = Category::create(['name' => 'Category 1']); |
| 77 | + $category2 = Category::create(['name' => 'Category 2']); |
| 78 | + |
| 79 | + $options = Category::query(); |
| 80 | + |
| 81 | + Route::get('select-translatable', function () use ($options) { |
| 82 | + return view('select-translatable') |
| 83 | + ->with('options', $options); |
| 84 | + })->middleware('web'); |
| 85 | + |
| 86 | + $this->visit('/select-translatable') |
| 87 | + ->seeElement('option[value="' . $category1->id . '"]') |
| 88 | + ->see('Category 1') |
| 89 | + ->seeElement('option[value="' . $category2->id . '"]') |
| 90 | + ->see('Category 2'); |
| 91 | + } |
43 | 92 | } |
0 commit comments