diff --git a/tests/Browser/Components/RecipientInput.php b/tests/Browser/Components/RecipientInput.php new file mode 100644 index 000000000..d851252d1 --- /dev/null +++ b/tests/Browser/Components/RecipientInput.php @@ -0,0 +1,71 @@ +selector = trim($selector); + } + + /** + * Get the root selector for the component. + * + * @return string + */ + public function selector() + { + return $this->selector; + } + + /** + * Assert that the browser page contains the component. + * + * @param Browser $browser + * + * @return void + */ + public function assert($browser) + { + $browser->waitFor($this->selector() . ' @input'); + } + + /** + * Get the element shortcuts for the component. + * + * @return array + */ + public function elements() + { + return [ + '@list' => 'ul.recipient-input', + '@field' => '.input-group > input, input-group > textarea', + '@input' => '@list input', + '@add-contact' => 'a.add.recipient', + '@add-header' => '.input-group-append:last-child a.add', + '@recipient' => '@list li.recipient', + ]; + } + + /** + * Assert recipient box content + */ + public function assertRecipient($browser, $num, $recipient) + { + $browser->ensurejQueryIsAvailable(); + $selector = $this->selector() . " ul.recipient-input li.recipient:nth-child($num)"; + $text = $browser->driver->executeScript("return \$('$selector').text()"); + + Assert::assertSame($recipient, is_string($text) ? trim($text, ", ") : null); + } +} diff --git a/tests/Browser/Mail/ComposeTest.php b/tests/Browser/Mail/ComposeTest.php index a61025837..0cbdb43c9 100644 --- a/tests/Browser/Mail/ComposeTest.php +++ b/tests/Browser/Mail/ComposeTest.php @@ -5,9 +5,15 @@ namespace Tests\Browser\Mail; use Facebook\Webdriver\WebDriverKeys; use Tests\Browser\Components\App; use Tests\Browser\Components\HtmlEditor; +use Tests\Browser\Components\RecipientInput; class ComposeTest extends \Tests\Browser\TestCase { + public static function setUpBeforeClass() + { + \bootstrap::init_db(); + } + public function testCompose() { $this->browse(function ($browser) { @@ -65,6 +71,10 @@ class ComposeTest extends \Tests\Browser\TestCase // Compose options $browser->assertSeeIn('#layout-sidebar .header', 'Options and attachments'); $browser->assertVisible('#compose-attachments'); + + if ($browser->isPhone()) { + $browser->click('#layout-sidebar a.back-content-button'); + } }); } @@ -98,4 +108,26 @@ class ComposeTest extends \Tests\Browser\TestCase }); }); } + + /** + * depends @testCompose + */ + function testRecipientInput() + { + // Test for #7231: Recipient input bug when using click + // to select a contact from autocomplete list + $this->browse(function ($browser) { + $browser->with(new RecipientInput('#compose_to'), function ($browser) { + $browser->type('@input', 'johndoe@e') + ->withinBody(function ($browser) { + $browser->whenAvailable('#rcmKSearchpane', function ($browser) { + $browser->click('li:first-child'); + }); + }) + ->waitFor('@recipient') + ->assertElementsCount('@recipient', 1) + ->assertRecipient(1, 'John Doe '); + }); + }); + } } diff --git a/tests/Browser/bootstrap.php b/tests/Browser/bootstrap.php index 01244d2d5..4e5f5f31c 100644 --- a/tests/Browser/bootstrap.php +++ b/tests/Browser/bootstrap.php @@ -40,6 +40,7 @@ require_once(__DIR__ . '/Components/App.php'); require_once(__DIR__ . '/Components/Dialog.php'); require_once(__DIR__ . '/Components/HtmlEditor.php'); require_once(__DIR__ . '/Components/Popupmenu.php'); +require_once(__DIR__ . '/Components/RecipientInput.php'); require_once(__DIR__ . '/Components/Taskmenu.php'); require_once(__DIR__ . '/Components/Toolbarmenu.php');