Skip to content

Commit

Permalink
PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Oct 19, 2021
1 parent a658779 commit 4b7af85
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
70 changes: 69 additions & 1 deletion tests/QueuedJobsAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
'<input type="text" name="filter[QueuedJobDescriptor][Implementation]" class="text',
$header
);
$this->assertContains(
'<select name="filter[QueuedJobDescriptor][JobType]" class="dropdown',
$header
);
$this->assertContains(
'<select name="filter[QueuedJobDescriptor][JobStatus]" class="dropdown',
$header
);
$this->assertContains(
'<input type="text" name="filter[QueuedJobDescriptor][JobTitle]" class="text',
$header
);
$this->assertContains(
'<select name="filter[QueuedJobDescriptor][Added]" class="dropdown',
$header
);
$this->assertContains(
'<select name="filter[QueuedJobDescriptor][Scheduled]" class="dropdown',
$header
);
}

public function advancedUIProvider(): array
{
return [
[false],
[true],
];
}
}

0 comments on commit 4b7af85

Please sign in to comment.