Skip to content

Commit 0291479

Browse files
committed
Revert "remove JS tests, this is hopeless"
This reverts commit cdc45cf.
1 parent 3a5e7cb commit 0291479

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Drupal\Tests\bar\FunctionalJavascript;
6+
7+
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
8+
use PHPUnit\Framework\Attributes\Group;
9+
10+
/**
11+
* Tests the generate JavaScript file..
12+
*/
13+
#[Group('DCG')]
14+
final class JavaScriptTest extends WebDriverTestBase {
15+
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
protected $defaultTheme = 'claro';
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected static $modules = ['bar'];
25+
26+
/**
27+
* Test callback.
28+
*/
29+
public function testJavascript(): void {
30+
// The `attach` method is evaluated as empty object.
31+
$result = $this->getSession()->evaluateScript('Drupal.behaviors.barHeavyMetal.attach');
32+
self::assertSame([], $result);
33+
34+
// Checking console.log() output is tricky. So we basically test that the
35+
// call for `attach()` method does not through JS exceptions.
36+
$result = $this->getSession()->evaluateScript('Drupal.behaviors.barHeavyMetal.attach()');
37+
self::assertNull($result);
38+
}
39+
40+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Drupal\Tests\qux\FunctionalJavascript;
6+
7+
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
8+
use Drupal\Tests\node\Traits\NodeCreationTrait;
9+
use PHPUnit\Framework\Attributes\Group;
10+
11+
/**
12+
* Tests the field plugins.
13+
*/
14+
#[Group('DCG')]
15+
abstract class FieldBase extends WebDriverTestBase {
16+
17+
use NodeCreationTrait;
18+
19+
/**
20+
* {@inheritdoc}
21+
*/
22+
protected $defaultTheme = 'claro';
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
protected static $modules = ['qux', 'node', 'field_ui', 'block'];
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
protected function setUp(): void {
33+
parent::setUp();
34+
35+
$this->createContentType(['type' => 'test']);
36+
37+
$permissions = [
38+
'administer node fields',
39+
'administer node form display',
40+
'administer node display',
41+
'create test content',
42+
'edit own test content',
43+
];
44+
$user = $this->createUser($permissions);
45+
$this->drupalLogin($user);
46+
47+
// Create text field.
48+
$this->drupalGet('admin/structure/types/manage/test/fields/add-field');
49+
50+
$driver = $this->getSession()->getDriver();
51+
$driver->click('//input[@name = "new_storage_type" and @value = "plain_text"]');
52+
$driver->click('//input[@value = "Continue"]');
53+
$driver->setValue('//input[@name = "label"]', 'Wine');
54+
$driver->setValue('//input[@name = "group_field_options_wrapper"]', 'string');
55+
$this->assertSession()->waitForElementVisible('css', '#edit-label-machine-name-suffix');
56+
$driver->click('//input[@value = "Continue"]');
57+
$driver->click('//input[@value = "Save settings"]');
58+
}
59+
60+
/**
61+
* Waits for Ajax request to be finished.
62+
*/
63+
protected function waitForAjax(): void {
64+
$page = $this->getSession()->getPage();
65+
$page->waitFor(10, static function () use ($page): bool {
66+
$element = $page->find('css', '.throbber');
67+
return $element === NULL || \count($element) === 0;
68+
});
69+
}
70+
71+
}

0 commit comments

Comments
 (0)