Tests: Added browser tests for Archive plugin

pull/7195/head
Aleksander Machniak 4 years ago
parent c6392f2168
commit 84aa5d93f1

@ -18,3 +18,8 @@ $config['create_default_folders'] = true;
$config['skin'] = 'elastic';
$config['support_url'] = 'http://support.url';
// Plugins with tests
$config['plugins'] = ['archive'];
$config['archive_mbox'] = 'Archive';

@ -0,0 +1,82 @@
<?php
namespace Tests\Browser\Plugins\Archive;
use Tests\Browser\Components\Popupmenu;
class MailTest extends \Tests\Browser\TestCase
{
public static function setUpBeforeClass()
{
\bootstrap::init_db();
\bootstrap::init_imap();
\bootstrap::purge_mailbox('INBOX');
\bootstrap::purge_mailbox('Archive');
// import single email messages
foreach (glob(TESTS_DIR . 'data/mail/list_00.eml') as $f) {
\bootstrap::import_message($f, 'INBOX');
}
}
public function testMailUI()
{
$this->browse(function ($browser) {
$browser->go('mail');
if (!$browser->isDesktop()) {
$browser->click('.back-sidebar-button');
}
// Folders list
$browser->whenAvailable('#mailboxlist', function ($browser) {
$browser->assertVisible('li.mailbox.archive')
->assertMissing('li.mailbox.archive .unreadcount');
});
if (!$browser->isDesktop()) {
$browser->click('.back-list-button');
}
// Toolbar menu (Archive button inactive)
$browser->assertToolbarMenu([], ['archive']);
$browser->whenAvailable('#messagelist tbody', function ($browser) {
$browser->ctrlClick('tr:last-child');
});
$browser->clickToolbarMenuItem('archive')
->waitForMessage('confirmation', 'Successfully archived')
->closeMessage('confirmation');
if (!$browser->isDesktop()) {
$browser->click('.back-sidebar-button');
}
// Folders list
$browser->whenAvailable('#mailboxlist', function ($browser) {
$browser->assertSeeIn('li.mailbox.archive .unreadcount', '1')
->click('li.mailbox.archive')
->waitUntilNotBusy();
});
// Messages list contains the moved message
$browser->assertElementsCount('#messagelist tbody tr', 1);
// Toolbar menu (Archive button inactive again)
$browser->assertToolbarMenu([], ['archive']);
// Test archive class on folder in folder selector
$browser->ctrlClick('#messagelist tbody tr')
->clickToolbarMenuItem('more')
->with(new Popupmenu('message-menu'), function ($browser) {
$browser->clickMenuItem('move');
})
->with(new Popupmenu('folder-selector'), function ($browser) {
$browser->assertVisible('li.archive')
->assertSeeIn('li.archive', 'Archive');
})
->click(); // close menus
});
}
}

@ -0,0 +1,108 @@
<?php
namespace Tests\Browser\Plugins\Archive;
class SettingsTest extends \Tests\Browser\TestCase
{
public static function setUpBeforeClass()
{
\bootstrap::init_db();
}
/**
* Test Folders UI
*/
public function testFolders()
{
$this->browse(function ($browser) {
$browser->go('settings', 'folders');
// Folders list
$browser->with('#subscription-table', function ($browser) {
$browser->assertHasClass('li:nth-child(7)', 'archive')
->assertSeeIn('li:nth-child(7)', 'Archive')
->assertPresent('li:nth-child(7) [type=checkbox][disabled]');
});
});
}
/**
* Test Preferences UI
*/
public function testPreferences()
{
$this->browse(function ($browser) {
$browser->go('settings');
if (!$browser->isDesktop()) {
$browser->click('#settings-menu li.preferences')
->waitFor('#sections-table');
}
$browser->click('#sections-table tr.folders');
if ($browser->isPhone()) {
$browser->waitFor('#layout-content .footer a.button.submit:not(.disabled)');
}
$browser->withinFrame('#preferences-frame', function ($browser) {
if (!$browser->isPhone()) {
$browser->waitFor('.formbuttons button.submit');
}
// Main Options fieldset
$browser->with('form.propform fieldset.main', function ($browser) {
$browser->assertSeeIn('legend', 'Main Options');
$browser->assertSeeIn('label[for=_archive_mbox]', 'Archive')
->assertVisible('select[name=_archive_mbox]')
->assertSelected('select[name=_archive_mbox]', 'Archive');
$browser->select('_archive_mbox', 'Drafts');
});
// Archive fieldset
$browser->with('form.propform fieldset.archive', function ($browser) {
$browser->assertSeeIn('legend', 'Archive');
$browser->assertSeeIn('label[for=ff_archive_type]', 'Divide archive by')
->assertVisible('select[name=_archive_type]')
->assertSelected('select[name=_archive_type]', '')
->with('select[name=_archive_type]', function ($browser) {
$browser->assertValue('option:nth-child(1)', '')
->assertSeeIn('option:nth-child(1)', 'None')
->assertValue('option:nth-child(2)', 'year')
->assertSeeIn('option:nth-child(2)', 'Year (e.g. Archive/2012)')
->assertValue('option:nth-child(3)', 'month')
->assertSeeIn('option:nth-child(3)', 'Month (e.g. Archive/2012/06)')
->assertValue('option:nth-child(4)', 'tbmonth')
->assertSeeIn('option:nth-child(4)', 'Month - Thunderbird compatible (e.g. Archive/2012/2012-06)')
->assertValue('option:nth-child(5)', 'sender')
->assertSeeIn('option:nth-child(5)', 'Sender email')
->assertValue('option:nth-child(6)', 'folder')
->assertSeeIn('option:nth-child(6)', 'Original folder');
});
$browser->select('_archive_type', 'year');
});
// Submit form
if (!$browser->isPhone()) {
$browser->click('.formbuttons button.submit');
}
});
if ($browser->isPhone()) {
$browser->click('#layout-content .footer a.submit');
}
$browser->waitForMessage('confirmation', 'Successfully saved');
// Verify if every option has been updated
$browser->withinFrame('#preferences-frame', function ($browser) {
$browser->assertSelected('_archive_mbox', 'Drafts');
$browser->assertSelected('_archive_type', 'year');
});
});
}
}

@ -139,6 +139,8 @@ class Browser extends \Laravel\Dusk\Browser
$this->driver->getKeyboard()->pressKey(WebDriverKeys::LEFT_CONTROL);
$this->element($selector)->click();
$this->driver->getKeyboard()->releaseKey(WebDriverKeys::LEFT_CONTROL);
return $this;
}
/**
@ -259,6 +261,16 @@ class Browser extends \Laravel\Dusk\Browser
return $this;
}
/**
* Wait until the UI is unlocked
*/
public function waitUntilNotBusy()
{
$this->waitUntil("!rcmail.busy");
return $this;
}
/**
* Wait for UI (notice/confirmation/loading/error/warning) message
* and assert it's text

@ -25,7 +25,8 @@ class ListTest extends \Tests\Browser\TestCase
$this->browse(function ($browser) {
$browser->go('mail');
$browser->assertElementsCount('#messagelist tbody tr', self::$msgcount);
$browser->waitUntilNotBusy()
->assertElementsCount('#messagelist tbody tr', self::$msgcount);
// check message list
$browser->assertVisible('#messagelist tbody tr:first-child.unread');

@ -45,9 +45,8 @@ class FoldersTest extends \Tests\Browser\TestCase
// Folders list
$browser->with('#subscription-table', function ($browser) {
$browser->assertElementsCount('li', 5)
// Note: first li element is root which is hidden in Elastic
->assertHasClass('li:nth-child(2)', 'inbox')
// Note: first li element is root which is hidden in Elastic
$browser->assertHasClass('li:nth-child(2)', 'inbox')
->assertSeeIn('li:nth-child(2)', 'Inbox')
->assertPresent('li:nth-child(2) [type=checkbox][disabled]')
->assertHasClass('li:nth-child(3)', 'drafts')
@ -74,6 +73,8 @@ class FoldersTest extends \Tests\Browser\TestCase
$this->browse(function ($browser) {
$browser->go('settings', 'folders');
$num = count($browser->elements('#subscription-table li'));
if ($browser->isPhone()) {
$browser->assertVisible('.floating-action-buttons a.create:not(.disabled)')
->click('.floating-action-buttons a.create')
@ -117,13 +118,15 @@ class FoldersTest extends \Tests\Browser\TestCase
$browser->closeMessage('confirmation');
$num++;
// Folders list
$browser->with('#subscription-table', function ($browser) {
$browser->with('#subscription-table', function ($browser) use ($num) {
// Note: li.root is hidden in Elastic
$browser->waitFor('li.mailbox:nth-child(7)')
->assertElementsCount('li', 6)
->assertPresent('li.mailbox:nth-child(7) [type=checkbox]:not([disabled])')
->click('li.mailbox:nth-child(7)');
$browser->waitFor("li.mailbox:nth-child({$num})")
->assertElementsCount('li', $num - 1)
->assertPresent("li.mailbox:nth-child({$num}) [type=checkbox]:not([disabled])")
->click("li.mailbox:nth-child({$num})");
});
if ($browser->isPhone()) {
@ -141,7 +144,7 @@ class FoldersTest extends \Tests\Browser\TestCase
->waitFor('#subscription-table');
}
$browser->setCheckboxState('#subscription-table li:nth-child(7) input', false)
$browser->setCheckboxState("#subscription-table li:nth-child({$num}) input", false)
->waitForMessage('confirmation', 'Folder successfully unsubscribed.');
});
}

@ -6,13 +6,9 @@ use Tests\Browser\Components\App;
class GeneralTest extends \Tests\Browser\TestCase
{
protected function tearDown()
public static function setUpBeforeClass()
{
parent::tearDown();
// Reset user preferences back to defaults
$db = $this->app->get_dbh();
$db->query("UPDATE users SET preferences = '' WHERE username = ?", TESTS_USER);
\bootstrap::init_db();
}
public function testGeneral()

@ -19,20 +19,19 @@ class PreferencesTest extends \Tests\Browser\TestCase
// On phone/tablet #sections-table is initially hidden
if (!$browser->isDesktop()) {
$browser->assertMissing('#sections-table');
$browser->click('#settings-menu li.preferences');
$browser->waitFor('#sections-table');
$browser->assertMissing('#sections-table')
->click('#settings-menu li.preferences')
->waitFor('#sections-table');
}
// Preferences actions
$browser->with('#sections-table', function($browser) {
$browser->assertSeeIn('tr.general', 'User Interface');
$browser->assertSeeIn('tr.mailbox', 'Mailbox View');
$browser->assertSeeIn('tr.mailview', 'Displaying Messages');
$browser->assertSeeIn('tr.compose', 'Composing Messages');
$browser->assertSeeIn('tr.addressbook', 'Contacts');
$browser->assertSeeIn('tr.folders', 'Special Folders');
$browser->assertSeeIn('tr.server', 'Server Settings');
$browser->assertSeeIn('tr.general', 'User Interface')
->assertSeeIn('tr.mailbox', 'Mailbox View')
->assertSeeIn('tr.mailview', 'Displaying Messages')
->assertSeeIn('tr.compose', 'Composing Messages')
->assertSeeIn('tr.addressbook', 'Contacts')
->assertSeeIn('tr.folders', 'Special Folders')
->assertSeeIn('tr.server', 'Server Settings');
});
});
}

@ -110,8 +110,6 @@ class bootstrap
}
self::connect_imap(TESTS_USER, TESTS_PASS);
self::purge_mailbox('INBOX');
// self::ensure_mailbox('Archive', true);
return self::$imap_ready;
}
@ -145,6 +143,12 @@ class bootstrap
rcube::raise_error("IMAP error: unable to authenticate with user " . TESTS_USER, false, true);
}
if (in_array('archive', (array) $rcmail->config->get('plugins'))) {
// Register special folder type for the Archive plugin.
// As we're in cli mode the plugin can't do it by its own
rcube_storage::$folder_types[] = 'archive';
}
self::$imap_ready = true;
}

@ -14,5 +14,8 @@
<testsuite name="Mail">
<directory suffix="Test.php">Mail</directory>
</testsuite>
<testsuite name="Plugins">
<directory suffix="Test.php">../../plugins/*/tests/Browser</directory>
</testsuite>
</testsuites>
</phpunit>

Loading…
Cancel
Save