diff --git a/composer.json b/composer.json index be6af229..33699814 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ }, "require-dev": { "sminnee/phpunit": "^5.7", - "squizlabs/php_codesniffer": "^3" + "squizlabs/php_codesniffer": "^3", + "silverstripe-terraformers/gridfield-rich-filter-header": "^2.1" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/tests/QueuedJobsAdminTest.php b/tests/QueuedJobsAdminTest.php index bb89e054..d768be48 100644 --- a/tests/QueuedJobsAdminTest.php +++ b/tests/QueuedJobsAdminTest.php @@ -2,17 +2,19 @@ namespace Symbiote\QueuedJobs\Tests; -use SilverStripe\Core\Config\Config; use SilverStripe\Control\HTTPRequest; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\FunctionalTest; use SilverStripe\Forms\FieldList; +use SilverStripe\Forms\GridField\GridField; +use SilverStripe\Forms\GridField\GridFieldFilterHeader; use SilverStripe\Forms\TextareaField; use SilverStripe\ORM\FieldType\DBDatetime; use Symbiote\QueuedJobs\Controllers\QueuedJobsAdmin; use Symbiote\QueuedJobs\Jobs\PublishItemsJob; use Symbiote\QueuedJobs\Services\QueuedJobService; use Symbiote\QueuedJobs\Tests\Jobs\TestDummyJob; +use Terraformers\RichFilterHeader\Form\GridField\RichFilterHeader; /** * Tests for the QueuedJobsAdmin ModelAdmin clas @@ -120,4 +122,70 @@ public function testCreateJobWithStartAfterOption() $this->admin->createjob($form->getData(), $form); } + + /** + * @param bool $enabled + * @dataProvider advancedUIProvider + */ + public function testAdvancedUI(bool $enabled): void + { + // enable / disable the advanced UI + QueuedJobsAdmin::config()->set('advanced_admin_ui', $enabled); + + $fields = $this->admin->getEditForm('foo', new FieldList())->Fields(); + + /** @var GridField $field */ + $field = $fields->fieldByName('QueuedJobDescriptor'); + $this->assertInstanceOf(GridField::class, $field); + $this->assertCount(1, $field->getConfig()->getComponentsByType(GridFieldFilterHeader::class)); + + $expected = $enabled ? 1 : 0; + $this->assertCount($expected, $field->getConfig()->getComponentsByType(RichFilterHeader::class)); + + if (!$enabled) { + // If the advanced UI is not enabled we can bail out here + return; + } + + /** @var RichFilterHeader $filterHeader */ + $filterHeader = $field->getConfig()->getComponentByType(RichFilterHeader::class); + $html = $filterHeader->getHTMLFragments($field); + + $this->assertArrayHasKey('header', $html); + $header = (string) $html['header']; + + // Make sure that the advanced UI is properly rendered - we want to see dropdown fields and other inputs + $this->assertContains( + '