Tests: Add browser test for #7231

pull/7266/head
Aleksander Machniak 4 years ago
parent 68c8ee0a2b
commit b2391417b3

@ -0,0 +1,71 @@
<?php
namespace Tests\Browser\Components;
use Tests\Browser\Browser;
use PHPUnit\Framework\Assert;
use Laravel\Dusk\Component;
class RecipientInput extends Component
{
public $selector;
/**
* Class constructor
*/
public function __construct($selector)
{
$this->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);
}
}

@ -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 <johndoe@example.org>');
});
});
}
}

@ -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');

Loading…
Cancel
Save