소스 검색

Form表单字段class增加前缀 close #190

jqh 4 년 전
부모
커밋
f853dbc975
3개의 변경된 파일11개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 1
      src/Form/Field.php
  2. 2 0
      tests/Browser/Cases/IndexTest.php
  3. 4 1
      tests/Browser/Components/Form/Field/Tree.php

+ 5 - 1
src/Form/Field.php

@@ -25,6 +25,8 @@ class Field implements Renderable
 
     const FILE_DELETE_FLAG = '_file_del_';
 
+    const FIELD_CLASS_PREFIX = 'field_';
+
     /**
      * Element id.
      *
@@ -926,7 +928,9 @@ class Field implements Renderable
         if (! $this->elementClass) {
             $name = $this->getElementName();
 
-            $this->elementClass = (array) str_replace(['[', ']'], '_', $name);
+            $this->elementClass = array_map(function ($v) {
+                return static::FIELD_CLASS_PREFIX.$v;
+            }, (array) str_replace(['[', ']'], '_', $name));
         }
 
         return $this->elementClass;

+ 2 - 0
tests/Browser/Cases/IndexTest.php

@@ -17,6 +17,7 @@ class IndexTest extends TestCase
     {
         $this->browse(function (Browser $browser) {
             $browser->visit(admin_base_path('/'))
+                ->pause(200)
                 ->assertSeeText('Administrator')
                 ->assertSeeText('Dashboard')
                 ->assertSeeText('Description...')
@@ -36,6 +37,7 @@ class IndexTest extends TestCase
             $browser->visit(admin_base_path('/'))
                 ->within('.main-menu-content', function (Browser $browser) {
                     $browser
+                        ->pause(500)
                         ->clickLink($this->translateMenuTitle('Admin'));
 //                        ->whenTextAvailable($this->translateMenuTitle('Users'), 2)
 //                        ->clickLink($this->translateMenuTitle('Users'))

+ 4 - 1
tests/Browser/Components/Form/Field/Tree.php

@@ -2,6 +2,7 @@
 
 namespace Tests\Browser\Components\Form\Field;
 
+use Dcat\Admin\Form\Field;
 use Laravel\Dusk\Browser;
 use Tests\Browser\Components\Component;
 
@@ -44,8 +45,10 @@ class Tree extends Component
      */
     public function elements()
     {
+        $prefix = Field::FIELD_CLASS_PREFIX;
+
         return [
-            '@container' => ".{$this->name}-tree-wrapper",
+            '@container' => ".{$prefix}{$this->name}-tree-wrapper",
             '@tree'      => '.da-tree',
             '@input'     => sprintf('input[name="%s"][type="hidden"]', $this->name),
         ];