Tests: Add folder creation test

pull/7181/head
Aleksander Machniak 5 years ago
parent 4f47ac0405
commit 5a6606a245

@ -233,6 +233,18 @@ class Browser extends \Laravel\Dusk\Browser
return $this;
}
/**
* Close UI (notice/confirmation/loading/error/warning) message
*/
public function closeMessage($type)
{
$selector = '#messagestack > div.' . $type;
$this->click($selector);
return $this;
}
/**
* Wait for UI (notice/confirmation/loading/error/warning) message
* and assert it's text

@ -6,6 +6,15 @@ use Tests\Browser\Components\App;
class Folders extends \Tests\Browser\TestCase
{
public static function setUpBeforeClass()
{
\bootstrap::init_imap();
\bootstrap::reset_mailboxes();
}
/**
* Test Folders UI
*/
public function testFolders()
{
$this->browse(function ($browser) {
@ -24,11 +33,103 @@ class Folders extends \Tests\Browser\TestCase
$browser->assertVisible('#settings-menu li.folders.selected');
}
// Folders list
$browser->assertVisible('#subscription-table li.mailbox.inbox');
if ($browser->isPhone()) {
$browser->assertVisible('.floating-action-buttons a.create:not(.disabled)');
}
else {
$browser->assertMissing('.floating-action-buttons a.create:not(.disabled)');
}
// Toolbar menu
$browser->assertToolbarMenu(['create'], ['delete', 'purge']);
// Folders list
$browser->with('#subscription-table', function ($browser) {
$browser->assertElementsCount('li', 1)
->assertVisible('li.mailbox.inbox')
->assertSeeIn('li.mailbox.inbox', 'Inbox')
->assertPresent('li [type=checkbox][disabled]');
});
});
}
/**
* Test folder creation
*/
public function testFolderCreate()
{
$this->browse(function ($browser) {
$browser->go('settings', 'folders');
if ($browser->isPhone()) {
$browser->assertVisible('.floating-action-buttons a.create:not(.disabled)')
->click('.floating-action-buttons a.create')
->waitFor('#preferences-frame');
}
else {
$browser->clickToolbarMenuItem('create');
}
$browser->withinFrame('#preferences-frame', function($browser) {
$browser->waitFor('form')
->with('form fieldset', function ($browser) {
$browser->assertVisible('input[name=_name]')
->assertValue('input[name=_name]', '')
->assertVisible('select[name=_parent]')
->assertSelected('select[name=_parent]', '');
})
/*
->with('form fieldset:last-child', function ($browser) {
$browser->assertSeeIn('legend', 'Settings')
->assertVisible('select[name=_viewmode]')
->assertSelected('select[name=_viewmode]', '0');
})
*/
->type('input[name=_name]', 'Test');
if (!$browser->isPhone()) {
$browser->click('.formbuttons button.submit');
}
});
if ($browser->isPhone()) {
$browser->assertVisible('#layout-content .header a.back-list-button')
->assertVisible('#layout-content .footer .buttons a.button.submit')
->click('#layout-content .footer .buttons a.button.submit')
->waitFor('#subscription-table');
}
else {
$browser->waitForMessage('confirmation', 'Folder created successfully.');
}
$browser->closeMessage('confirmation');
// Folders list
$browser->with('#subscription-table', function ($browser) {
// Note: li.root is hidden in Elastic
$browser->waitFor('li.mailbox:nth-child(3)')
->assertElementsCount('li', 2)
->assertPresent('li.mailbox:nth-child(3) [type=checkbox]:not([disabled])')
->click('li.mailbox:nth-child(3)');
});
if ($browser->isPhone()) {
$browser->waitFor('#preferences-frame');
}
$browser->withinFrame('#preferences-frame', function($browser) {
$browser->waitFor('form');
// TODO
});
// Test unsubscribe of the newly created folder
if ($browser->isPhone()) {
$browser->click('a.back-list-button')
->waitFor('#subscription-table');
}
$browser->setCheckboxState('#subscription-table li:nth-child(3) input', false)
->waitForMessage('confirmation', 'Folder successfully unsubscribed.');
});
}
}

@ -190,6 +190,24 @@ class bootstrap
}
}
/**
* Make sure only special folders exist in IMAP
*/
public static function reset_mailboxes()
{
if (!self::init_imap()) {
die(__METHOD__ . ': IMAP connection unavailable');
}
$imap = rcmail::get_instance()->get_storage();
foreach ($imap->list_folders() as $folder) {
if (!$imap->is_special_folder($folder)) {
$imap->delete_folder($folder);
}
}
}
/**
* Check IMAP capabilities
*/

Loading…
Cancel
Save