Tests: Fix testing with create_default_folders=true

pull/7186/head
Aleksander Machniak 5 years ago
parent b6e75ebea7
commit 2037f2612b

@ -57,6 +57,20 @@ class Browser extends \Laravel\Dusk\Browser
return $this; return $this;
} }
/**
* Assert that the given element has specified class assigned.
*/
public function assertHasClass($selector, $class_name)
{
$fullSelector = $this->resolver->format($selector);
$element = $this->resolver->findOrFail($selector);
$classes = explode(' ', (string) $element->getAttribute('class'));
Assert::assertContains($class_name, $classes);
return $this;
}
/** /**
* Assert Task menu state * Assert Task menu state
*/ */

@ -45,10 +45,23 @@ class Folders extends \Tests\Browser\TestCase
// Folders list // Folders list
$browser->with('#subscription-table', function ($browser) { $browser->with('#subscription-table', function ($browser) {
$browser->assertElementsCount('li', 1) $browser->assertElementsCount('li', 5)
->assertVisible('li.mailbox.inbox') // Note: first li element is root which is hidden in Elastic
->assertSeeIn('li.mailbox.inbox', 'Inbox') ->assertHasClass('li:nth-child(2)', 'inbox')
->assertPresent('li [type=checkbox][disabled]'); ->assertSeeIn('li:nth-child(2)', 'Inbox')
->assertPresent('li:nth-child(2) [type=checkbox][disabled]')
->assertHasClass('li:nth-child(3)', 'drafts')
->assertSeeIn('li:nth-child(3)', 'Drafts')
->assertPresent('li:nth-child(3) [type=checkbox][disabled]')
->assertHasClass('li:nth-child(4)', 'sent')
->assertSeeIn('li:nth-child(4)', 'Sent')
->assertPresent('li:nth-child(4) [type=checkbox][disabled]')
->assertHasClass('li:nth-child(5)', 'junk')
->assertSeeIn('li:nth-child(5)', 'Junk')
->assertPresent('li:nth-child(5) [type=checkbox][disabled]')
->assertHasClass('li:nth-child(6)', 'trash')
->assertSeeIn('li:nth-child(6)', 'Trash')
->assertPresent('li:nth-child(6) [type=checkbox][disabled]');
}); });
}); });
} }
@ -107,10 +120,10 @@ class Folders extends \Tests\Browser\TestCase
// Folders list // Folders list
$browser->with('#subscription-table', function ($browser) { $browser->with('#subscription-table', function ($browser) {
// Note: li.root is hidden in Elastic // Note: li.root is hidden in Elastic
$browser->waitFor('li.mailbox:nth-child(3)') $browser->waitFor('li.mailbox:nth-child(7)')
->assertElementsCount('li', 2) ->assertElementsCount('li', 6)
->assertPresent('li.mailbox:nth-child(3) [type=checkbox]:not([disabled])') ->assertPresent('li.mailbox:nth-child(7) [type=checkbox]:not([disabled])')
->click('li.mailbox:nth-child(3)'); ->click('li.mailbox:nth-child(7)');
}); });
if ($browser->isPhone()) { if ($browser->isPhone()) {
@ -128,7 +141,7 @@ class Folders extends \Tests\Browser\TestCase
->waitFor('#subscription-table'); ->waitFor('#subscription-table');
} }
$browser->setCheckboxState('#subscription-table li:nth-child(3) input', false) $browser->setCheckboxState('#subscription-table li:nth-child(7) input', false)
->waitForMessage('confirmation', 'Folder successfully unsubscribed.'); ->waitForMessage('confirmation', 'Folder successfully unsubscribed.');
}); });
} }

Loading…
Cancel
Save