Tests: Add Dialog component

pull/7186/head
Aleksander Machniak 5 years ago
parent d979aa0584
commit d1b61410fc

@ -0,0 +1,125 @@
<?php
namespace Tests\Browser\Components;
use Tests\Browser\Browser;
use Laravel\Dusk\Component;
class Dialog extends Component
{
public $num;
/**
* Class constructor
*/
public function __construct($num = 1)
{
$this->num = $num ?: 1;
}
/**
* Get the root selector for the component.
*
* @return string
*/
public function selector()
{
// work with the specified dialog (in case there's more than one)
$suffix = $this->num > 1 ? str_repeat(' + div + .ui-dialog', $this->num - 1) : '';
return '.ui-dialog' . $suffix;
}
/**
* Assert that the browser page contains the component.
*
* @param Browser $browser
*
* @return void
*/
public function assert($browser)
{
$browser->waitFor($this->selector());
}
/**
* Get the element shortcuts for the component.
*
* @return array
*/
public function elements()
{
return [
'@title' => '.ui-dialog-titlebar',
'@content' => '.ui-dialog-content',
'@footer' => '.ui-dialog-buttonset',
];
}
/**
* Assert dialog title
*/
public function assertDialogTitle($browser, $title)
{
$browser->assertSeeIn('@title', $title);
}
/**
* Assert dialog content (for simple text dialogs)
*/
public function assertDialogContent($browser, $text)
{
$browser->assertSeeIn('@content', $text);
}
/**
* Assert dialog button
*/
public function assertButton($browser, $name, $label)
{
$selector = "@footer button.{$name}";
$browser->assertVisible($selector, $title)
->assertSeeIn($selector, $label);
}
/**
* Click dialog button
*/
public function clickButton($browser, $name, $expect_close = true)
{
$browser->click('@footer button.' . $name);
if ($expect_close) {
$browser->waitUntilMissing($this->selector());
}
}
/**
* Close dialog
*/
public function closeDialog($browser)
{
$browser->click('@footer button.cancel, @footer button.close')
->waitUntilMissing($this->selector());
}
/**
* Close dialog with ESC key
*/
public function pressESC($browser)
{
$browser->driver->getKeyboard()->sendKeys(\Facebook\WebDriver\WebDriverKeys::ESCAPE);
$browser->waitUntilMissing($this->selector());
}
/**
* Execute code within dialog's iframe
*/
public function withinDialogFrame($browser, $callback)
{
$browser->withinFrame('@content iframe', function ($browser) use ($callback) {
$browser->withinBody(function ($browser) use ($callback) {
$callback($browser);
});
});
}
}

@ -2,6 +2,7 @@
namespace Tests\Browser\Contacts;
use Tests\Browser\Components\Dialog;
use Tests\Browser\Components\Popupmenu;
class GroupsTest extends \Tests\Browser\TestCase
@ -61,17 +62,15 @@ class GroupsTest extends \Tests\Browser\TestCase
$browser->clickMenuItem('create');
});
$browser->waitFor('.ui-dialog');
$browser->with('.ui-dialog', function ($browser) {
$browser
->assertSeeIn('.ui-dialog-titlebar', 'Create new group')
->assertFocused('input.form-control')
->type('input.form-control', 'New Group')
->click('button.mainaction');
$browser->with(new Dialog(), function ($browser) {
$browser->assertDialogTitle('Create new group')
->assertButton('save.mainaction', 'Save')
->assertButton('cancel', 'Cancel')
->assertFocused('@content input.form-control')
->type('@content input.form-control', 'New Group')
->clickButton('save');
});
$browser->waitUntilMissing('.ui-dialog');
$browser->with('#directorylist', function ($browser) {
$browser->waitFor('li:first-child ul.groups')
->assertVisible('.treetoggle.expanded')
@ -113,17 +112,17 @@ class GroupsTest extends \Tests\Browser\TestCase
$browser->clickMenuItem('group.rename');
});
$browser->waitFor('.ui-dialog');
$browser->with('.ui-dialog', function ($browser) {
$browser->assertSeeIn('.ui-dialog-titlebar', 'Rename group')
->assertFocused('input.form-control')
->assertValue('input.form-control', 'New Group')
->type('input.form-control', 'Renamed')
->click('button.mainaction');
$browser->with(new Dialog(), function ($browser) {
$browser
->assertDialogTitle('Rename group')
->assertButton('save.mainaction', 'Save')
->assertButton('cancel', 'Cancel')
->assertFocused('@content input.form-control')
->assertValue('@content input.form-control', 'New Group')
->type('@content input.form-control', 'Renamed')
->clickButton('save');
});
$browser->waitUntilMissing('.ui-dialog');
$browser->with('#directorylist', function ($browser) {
$browser->waitFor('li:first-child ul.groups')
->assertVisible('.treetoggle.expanded')
@ -165,16 +164,15 @@ class GroupsTest extends \Tests\Browser\TestCase
$browser->clickMenuItem('group.delete');
});
$browser->waitFor('.ui-dialog');
$browser->with('.ui-dialog', function ($browser) {
$browser->assertSeeIn('.ui-dialog-titlebar', 'Are you sure...')
->assertSeeIn('.ui-dialog-content', 'Do you really want to delete selected group?')
->assertFocused('button.mainaction.delete')
->click('button.mainaction.delete');
$browser->with(new Dialog(), function ($browser) {
$browser
->assertDialogTitle('Are you sure...')
->assertDialogContent('Do you really want to delete selected group?')
->assertButton('delete.mainaction', 'Delete')
->assertButton('cancel', 'Cancel')
->clickButton('delete');
});
$browser->waitUntilMissing('.ui-dialog');
$browser->with('#directorylist', function ($browser) {
$browser->assertMissing('.treetoggle.expanded')
->assertMissing('ul.groups');

@ -3,6 +3,7 @@
namespace Tests\Browser\Contacts;
use Tests\Browser\Components\App;
use Tests\Browser\Components\Dialog;
class ImportTest extends \Tests\Browser\TestCase
{
@ -21,9 +22,11 @@ class ImportTest extends \Tests\Browser\TestCase
$browser->clickToolbarMenuItem('import');
$browser->assertSeeIn('.ui-dialog-title', 'Import contacts');
$browser->assertVisible('.ui-dialog button.mainaction.import');
$browser->assertVisible('.ui-dialog button.cancel');
$browser->with(new Dialog(), function ($browser) {
$browser->assertDialogTitle('Import contacts')
->assertButton('mainaction.import', 'Import')
->assertButton('cancel', 'Cancel');
});
$browser->withinFrame('.ui-dialog iframe', function ($browser) {
// check task and action
@ -44,8 +47,9 @@ class ImportTest extends \Tests\Browser\TestCase
});
// Close the dialog
$browser->click('.ui-dialog button.cancel');
$browser->assertMissing('.ui-dialog');
$browser->with(new Dialog(), function ($browser) {
$browser->clickButton('cancel');
});
});
}
@ -59,28 +63,31 @@ class ImportTest extends \Tests\Browser\TestCase
$this->browse(function ($browser) {
// Open the dialog again
$browser->clickToolbarMenuItem('import');
$browser->assertSeeIn('.ui-dialog-title', 'Import contacts');
// Submit the form with no file attached
$browser->click('.ui-dialog button.mainaction');
$browser->waitForText('Attention');
$browser->assertSee('Please select a file');
$browser->driver->getKeyboard()->sendKeys(\Facebook\WebDriver\WebDriverKeys::ESCAPE);
$browser->assertElementsCount('.ui-dialog', 1);
$browser->withinFrame('.ui-dialog iframe', function ($browser) {
$browser->attach('.custom-file input', TESTS_DIR . 'data/contacts.vcf');
$browser->with(new Dialog(), function ($browser) {
$browser->assertDialogTitle('Import contacts')
->clickButton('import');
});
$browser->click('.ui-dialog button.mainaction');
// Submit the form with no file attached
$browser->with(new Dialog(2), function ($browser) {
$browser->assertDialogTitle('Attention')
->assertDialogContent('Please select a file')
->assertButton('save.mainaction', 'OK')
->pressESC();
});
$browser->withinFrame('.ui-dialog iframe', function ($browser) {
$browser->with(new Dialog(), function ($browser) {
$browser->withinDialogFrame(function ($browser) {
$browser->attach('.custom-file input', TESTS_DIR . 'data/contacts.vcf');
})
->clickButton('import')
->withinDialogFrame(function ($browser) {
$browser->waitForText('Successfully imported 2 contacts:');
})
->closeDialog();
});
// Close the dialog
$browser->click('.ui-dialog button.cancel');
// Expected existing contacts + imported
$browser->waitFor('#contacts-table tr')
->assertElementsCount('#contacts-table tbody tr', 4)

@ -3,6 +3,7 @@
namespace Tests\Browser\Mail;
use Tests\Browser\Components\App;
use Tests\Browser\Components\Dialog;
use Tests\Browser\Components\Popupmenu;
class PreviewTest extends \Tests\Browser\TestCase
@ -128,17 +129,15 @@ class PreviewTest extends \Tests\Browser\TestCase
->click('.header.cc a.morelink');
});
$browser->waitFor('.ui-dialog')
->with('.ui-dialog', function ($browser) {
$browser->assertSeeIn('.ui-dialog-titlebar', 'Cc')
->assertSeeIn('.ui-dialog-content', 'test1@domain.tld')
->assertSeeIn('.ui-dialog-content', 'test12@domain.tld')
->assertElementsCount('span.adr', 12)
->click('.ui-dialog-buttonset button.cancel');
$browser->with(new Dialog(), function ($browser) {
$browser->assertDialogTitle('Cc')
->assertDialogContent('test1@domain.tld')
->assertDialogContent('test12@domain.tld')
->assertElementsCount('@content span.adr', 12)
->assertButton('cancel', 'Close')
->clickButton('cancel');
});
$browser->waitUntilMissing('.ui-dialog');
// Attachments list
$browser->withinFrame('#messagecontframe', function ($browser) {
$browser->with('#attachment-list', function ($browser) {

@ -3,6 +3,7 @@
namespace Tests\Browser\Settings;
use Tests\Browser\Components\App;
use Tests\Browser\Components\Dialog;
class AboutTest extends \Tests\Browser\TestCase
{
@ -13,8 +14,15 @@ class AboutTest extends \Tests\Browser\TestCase
$browser->clickTaskMenuItem('about');
$browser->assertSeeIn('.ui-dialog-title', 'About');
$browser->assertVisible('.ui-dialog #aboutframe');
$browser->with(new Dialog(), function ($browser) {
$browser->assertDialogTitle('About')
->assertButton('cancel', 'Close')
->assertVisible('@content #aboutframe');
if ($url = \rcmail::get_instance()->config->get('support_url')) {
$browser->assertButton('mainaction.help', 'Get support');
}
});
$browser->withinFrame('#aboutframe', function ($browser) {
// check task and action
@ -26,6 +34,10 @@ class AboutTest extends \Tests\Browser\TestCase
$browser->assertSee($this->app->config->get('product_name'));
$browser->assertVisible('#pluginlist');
});
$browser->with(new Dialog(), function ($browser) {
$browser->closeDialog();
});
});
}
}

@ -3,6 +3,7 @@
namespace Tests\Browser\Settings;
use Tests\Browser\Components\App;
use Tests\Browser\Components\Dialog;
use Tests\Browser\Components\Popupmenu;
class ResponsesTest extends \Tests\Browser\TestCase
@ -124,15 +125,15 @@ class ResponsesTest extends \Tests\Browser\TestCase
$this->browse(function ($browser) {
$browser->clickToolbarMenuItem('delete');
$browser->waitFor('.ui-dialog')
->with('.ui-dialog', function ($browser) {
$browser->assertSeeIn('.ui-dialog-title', 'Are you sure...')
->assertSeeIn('.ui-dialog-content', 'Do you really want to delete this response text?')
->click('.ui-dialog-buttonpane button.mainaction.delete');
$browser->with(new Dialog(), function ($browser) {
$browser->assertDialogTitle('Are you sure...')
->assertDialogContent('Do you really want to delete this response text?')
->assertButton('mainaction.delete', 'Delete')
->assertButton('cancel', 'Cancel')
->clickButton('mainaction.delete');
});
$browser->waitForMessage('confirmation', 'Successfully deleted.')
->assertMissing('.ui-dialog')
->closeMessage('confirmation');
// Preview frame should reset to the watermark page

@ -37,6 +37,7 @@ define('TESTS_PASS', $rcmail->config->get('tests_password'));
require_once(__DIR__ . '/Browser.php');
require_once(__DIR__ . '/TestCase.php');
require_once(__DIR__ . '/Components/App.php');
require_once(__DIR__ . '/Components/Dialog.php');
require_once(__DIR__ . '/Components/Popupmenu.php');
require_once(__DIR__ . '/Components/Taskmenu.php');
require_once(__DIR__ . '/Components/Toolbarmenu.php');

Loading…
Cancel
Save