mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
More tests
This commit is contained in:
parent
8b7c226343
commit
3dc5c487e9
9 changed files with 214 additions and 88 deletions
25
tests/e2e/AlbumsScreenTest.php
Normal file
25
tests/e2e/AlbumsScreenTest.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace E2E;
|
||||||
|
|
||||||
|
use Facebook\WebDriver\WebDriverBy;
|
||||||
|
|
||||||
|
class AlbumsScreenTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testAlbumsScreen()
|
||||||
|
{
|
||||||
|
$this->loginAndWait()->goto('albums');
|
||||||
|
|
||||||
|
static::assertNotEmpty($this->els('#albumsWrapper .albums article.item'));
|
||||||
|
$firstAlbum = $this->el('#albumsWrapper .albums article.item:nth-child(1)');
|
||||||
|
static::assertNotEmpty($firstAlbum->findElement(WebDriverBy::cssSelector('.info .name'))->getText());
|
||||||
|
static::assertNotEmpty($firstAlbum->findElement(WebDriverBy::cssSelector('.info .artist'))->getText());
|
||||||
|
static::assertContains('10 songs', $firstAlbum->findElement(WebDriverBy::cssSelector('.meta'))->getText());
|
||||||
|
|
||||||
|
// test the view modes
|
||||||
|
$this->click('#albumsWrapper > h1.heading > span.view-modes > a:nth-child(2)');
|
||||||
|
static::assertCount(1, $this->els('#albumsWrapper > div.albums.as-list'));
|
||||||
|
$this->click('#albumsWrapper > h1.heading > span.view-modes > a:nth-child(1)');
|
||||||
|
static::assertCount(1, $this->els('#albumsWrapper > div.albums.as-thumbnails'));
|
||||||
|
}
|
||||||
|
}
|
8
tests/e2e/AllSongsScreenTest.php
Normal file
8
tests/e2e/AllSongsScreenTest.php
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace E2E;
|
||||||
|
|
||||||
|
abstract class AllSongsScreenTest extends TestCase
|
||||||
|
{
|
||||||
|
// All we need to test should have been cover in SongListTest class.
|
||||||
|
}
|
24
tests/e2e/ArtistsScreenTest.php
Normal file
24
tests/e2e/ArtistsScreenTest.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace E2E;
|
||||||
|
|
||||||
|
use Facebook\WebDriver\WebDriverBy;
|
||||||
|
|
||||||
|
class ArtistsScreenTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testArtistsScreen()
|
||||||
|
{
|
||||||
|
$this->loginAndWait()->goto('artists');
|
||||||
|
|
||||||
|
static::assertNotEmpty($this->els('#artistsWrapper .artists article.item'));
|
||||||
|
$firstArtist = $this->el('#artistsWrapper .artists article.item:nth-child(1)');
|
||||||
|
static::assertNotEmpty($firstArtist->findElement(WebDriverBy::cssSelector('.info .name'))->getText());
|
||||||
|
static::assertContains('5 albums • 50 songs', $firstArtist->findElement(WebDriverBy::cssSelector('.meta'))->getText());
|
||||||
|
|
||||||
|
// test the view modes
|
||||||
|
$this->click('#artistsWrapper > h1.heading > span.view-modes > a:nth-child(2)');
|
||||||
|
static::assertCount(1, $this->els('#artistsWrapper > div.artists.as-list'));
|
||||||
|
$this->click('#artistsWrapper > h1.heading > span.view-modes > a:nth-child(1)');
|
||||||
|
static::assertCount(1, $this->els('#artistsWrapper > div.artists.as-thumbnails'));
|
||||||
|
}
|
||||||
|
}
|
40
tests/e2e/DefaultsTest.php
Normal file
40
tests/e2e/DefaultsTest.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace E2E;
|
||||||
|
|
||||||
|
use Facebook\WebDriver\WebDriverBy;
|
||||||
|
use Facebook\WebDriver\WebDriverExpectedCondition;
|
||||||
|
|
||||||
|
class KoelTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testDefaults()
|
||||||
|
{
|
||||||
|
static::assertContains('Koel', $this->driver->getTitle());
|
||||||
|
|
||||||
|
$formSelector = '#app > div.login-wrapper > form';
|
||||||
|
|
||||||
|
// Our login form should be there.
|
||||||
|
static::assertCount(1, $this->els($formSelector));
|
||||||
|
|
||||||
|
// We submit rubbish and expect an error class on the form.
|
||||||
|
$this->login('foo@bar.com', 'ThisIsWongOnSoManyLevels');
|
||||||
|
$this->waitUntil(WebDriverExpectedCondition::presenceOfElementLocated(
|
||||||
|
WebDriverBy::cssSelector("$formSelector.error")
|
||||||
|
));
|
||||||
|
|
||||||
|
// Now we submit good stuff and make sure we're in.
|
||||||
|
$this->login();
|
||||||
|
$this->waitUntil(WebDriverExpectedCondition::textToBePresentInElement(
|
||||||
|
WebDriverBy::cssSelector('#userBadge > a.view-profile.control > span'), 'Koel Admin'
|
||||||
|
));
|
||||||
|
|
||||||
|
// Default URL must be Home
|
||||||
|
static::assertEquals($this->url.'/#!/home', $this->driver->getCurrentURL());
|
||||||
|
|
||||||
|
// While we're at this, test logging out as well.
|
||||||
|
$this->click('#userBadge > a.logout');
|
||||||
|
$this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(
|
||||||
|
WebDriverBy::cssSelector($formSelector)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
45
tests/e2e/HomeScreenTest.php
Normal file
45
tests/e2e/HomeScreenTest.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: an
|
||||||
|
* Date: 15/11/16
|
||||||
|
* Time: 4:14 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace E2E;
|
||||||
|
|
||||||
|
use Facebook\WebDriver\Remote\RemoteWebElement;
|
||||||
|
|
||||||
|
class HomeScreenTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testHomeScreen()
|
||||||
|
{
|
||||||
|
$this->loginAndWait();
|
||||||
|
|
||||||
|
$this->click('#sidebar a.home');
|
||||||
|
|
||||||
|
// We must see some greetings
|
||||||
|
static::assertTrue($this->el('#homeWrapper > h1')->isDisplayed());
|
||||||
|
|
||||||
|
// 6 recently added albums
|
||||||
|
static::assertCount(6, $this->els('#homeWrapper section.recently-added article'));
|
||||||
|
|
||||||
|
// 10 recently added songs
|
||||||
|
static::assertCount(10, $this->els('#homeWrapper .recently-added-song-list .song-item-home'));
|
||||||
|
|
||||||
|
// Shuffle must work for latest albums
|
||||||
|
$this->click('#homeWrapper section.recently-added article:nth-child(1) span.right a:nth-child(1)');
|
||||||
|
static::assertCount(10, $this->els('#queueWrapper .song-list-wrap tr.song-item'));
|
||||||
|
|
||||||
|
$this->goto('home');
|
||||||
|
|
||||||
|
// Simulate a "double click to play" action
|
||||||
|
/** @var $clickedSong RemoteWebElement */
|
||||||
|
$clickedSong = $this->el('#homeWrapper section.recently-added > div > div:nth-child(2) li:nth-child(1) .details');
|
||||||
|
$this->doubleClick($clickedSong);
|
||||||
|
// The song must appear at the top of "Recently played" section
|
||||||
|
/** @var $mostRecentSong RemoteWebElement */
|
||||||
|
$mostRecentSong = $this->el('#homeWrapper .recently-added-song-list .song-item-home:nth-child(1) .details');
|
||||||
|
static::assertEquals($mostRecentSong->getText(), $clickedSong->getText());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,84 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace E2E;
|
|
||||||
|
|
||||||
use Facebook\WebDriver\Remote\RemoteWebElement;
|
|
||||||
use Facebook\WebDriver\WebDriverBy;
|
|
||||||
use Facebook\WebDriver\WebDriverExpectedCondition;
|
|
||||||
|
|
||||||
class KoelTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testDefaults()
|
|
||||||
{
|
|
||||||
static::assertContains('Koel', $this->driver->getTitle());
|
|
||||||
|
|
||||||
$formSelector = '#app > div.login-wrapper > form';
|
|
||||||
|
|
||||||
// Our login form should be there.
|
|
||||||
static::assertCount(1, $this->els($formSelector));
|
|
||||||
|
|
||||||
// We submit rubbish and expect an error class on the form.
|
|
||||||
$this->login('foo@bar.com', 'ThisIsWongOnSoManyLevels');
|
|
||||||
$this->waitUntil(WebDriverExpectedCondition::presenceOfElementLocated(
|
|
||||||
WebDriverBy::cssSelector("$formSelector.error")
|
|
||||||
));
|
|
||||||
|
|
||||||
// Now we submit good stuff and make sure we're in.
|
|
||||||
$this->login();
|
|
||||||
$this->waitUntil(WebDriverExpectedCondition::textToBePresentInElement(
|
|
||||||
WebDriverBy::cssSelector('#userBadge > a.view-profile.control > span'), 'Koel Admin'
|
|
||||||
));
|
|
||||||
|
|
||||||
// Default URL must be Home
|
|
||||||
static::assertEquals($this->url.'/#!/home', $this->driver->getCurrentURL());
|
|
||||||
|
|
||||||
$this->_testSideBar();
|
|
||||||
$this->_testHomeScreen();
|
|
||||||
|
|
||||||
// While we're at this, test logging out as well.
|
|
||||||
$this->click('#userBadge > a.logout');
|
|
||||||
$this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(
|
|
||||||
WebDriverBy::cssSelector($formSelector)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function _testSideBar()
|
|
||||||
{
|
|
||||||
// All basic navigation
|
|
||||||
foreach (['home', 'queue', 'songs', 'albums', 'artists', 'youtube', 'settings', 'users'] as $screen) {
|
|
||||||
$this->goto($screen);
|
|
||||||
$this->waitUntil(function () use ($screen) {
|
|
||||||
return $this->driver->getCurrentURL() === $this->url.'/#!/'.$screen;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function _testHomeScreen()
|
|
||||||
{
|
|
||||||
$this->click('#sidebar a.home');
|
|
||||||
|
|
||||||
// We must see some greetings
|
|
||||||
static::assertTrue($this->el('#homeWrapper > h1')->isDisplayed());
|
|
||||||
|
|
||||||
// 6 recently added albums
|
|
||||||
static::assertCount(6, $this->els('#homeWrapper section.recently-added article'));
|
|
||||||
|
|
||||||
// 10 recently added songs
|
|
||||||
static::assertCount(10, $this->els('#homeWrapper .recently-added-song-list .song-item-home'));
|
|
||||||
|
|
||||||
// Shuffle must work for latest albums
|
|
||||||
$this->click('#homeWrapper section.recently-added article:nth-child(1) span.right a:nth-child(1)');
|
|
||||||
static::assertCount(10, $this->els('#queueWrapper .song-list-wrap tr.song-item'));
|
|
||||||
|
|
||||||
$this->goto('home');
|
|
||||||
|
|
||||||
// Simulate a "double click to play" action
|
|
||||||
/** @var $clickedSong RemoteWebElement */
|
|
||||||
$clickedSong = $this->el('#homeWrapper section.recently-added > div > div:nth-child(2) li:nth-child(1) .details');
|
|
||||||
$this->doubleClick($clickedSong);
|
|
||||||
// The song must appear at the top of "Recently played" section
|
|
||||||
/** @var $mostRecentSong RemoteWebElement */
|
|
||||||
$mostRecentSong = $this->el('#homeWrapper .recently-added-song-list .song-item-home:nth-child(1) .details');
|
|
||||||
static::assertEquals($mostRecentSong->getText(), $clickedSong->getText());
|
|
||||||
}
|
|
||||||
}
|
|
68
tests/e2e/SideBarTest.php
Normal file
68
tests/e2e/SideBarTest.php
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace E2E;
|
||||||
|
|
||||||
|
use Facebook\WebDriver\WebDriverBy;
|
||||||
|
use Facebook\WebDriver\WebDriverElement;
|
||||||
|
use Facebook\WebDriver\WebDriverExpectedCondition;
|
||||||
|
|
||||||
|
class SideBarTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testSideBar()
|
||||||
|
{
|
||||||
|
$this->loginAndWait();
|
||||||
|
|
||||||
|
// All basic navigation
|
||||||
|
foreach (['home', 'queue', 'songs', 'albums', 'artists', 'youtube', 'settings', 'users'] as $screen) {
|
||||||
|
$this->goto($screen);
|
||||||
|
$this->waitUntil(function () use ($screen) {
|
||||||
|
return $this->driver->getCurrentURL() === $this->url.'/#!/'.$screen;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a playlist
|
||||||
|
$this->click('#playlists > h1 > i.create');
|
||||||
|
$this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(
|
||||||
|
WebDriverBy::cssSelector('#playlists > form.create')
|
||||||
|
));
|
||||||
|
$this->typeIn('#playlists > form > input[type="text"]', 'Bar');
|
||||||
|
$this->enter();
|
||||||
|
/** @var WebDriverElement $mostRecentPlaylist */
|
||||||
|
$mostRecentPlaylist = null;
|
||||||
|
$this->waitUntil(function () use (&$mostRecentPlaylist) {
|
||||||
|
/** @var WebDriverElement $mostRecentPlaylist */
|
||||||
|
$list = $this->els('#playlists .playlist');
|
||||||
|
$mostRecentPlaylist = end($list);
|
||||||
|
|
||||||
|
return $mostRecentPlaylist->getText() === 'Bar';
|
||||||
|
});
|
||||||
|
|
||||||
|
// Double click to edit/rename a playlist
|
||||||
|
$this->doubleClick($mostRecentPlaylist);
|
||||||
|
$this->waitUntil(function () use (&$mostRecentPlaylist) {
|
||||||
|
return count($mostRecentPlaylist->findElements(WebDriverBy::cssSelector('input[type="text"]')));
|
||||||
|
});
|
||||||
|
$this->typeIn(
|
||||||
|
$mostRecentPlaylist->findElement(WebDriverBy::cssSelector('input[type="text"]')),
|
||||||
|
'Baz'
|
||||||
|
);
|
||||||
|
$this->enter();
|
||||||
|
$this->waitUntil(function () {
|
||||||
|
$list = $this->els('#playlists .playlist');
|
||||||
|
$mostRecentPlaylist = end($list);
|
||||||
|
|
||||||
|
return $mostRecentPlaylist->getText() === 'Baz';
|
||||||
|
});
|
||||||
|
|
||||||
|
// Edit with an empty name shouldn't do anything.
|
||||||
|
$this->doubleClick($mostRecentPlaylist);
|
||||||
|
$mostRecentPlaylist->findElement(WebDriverBy::cssSelector('input[type="text"]'))->clear();
|
||||||
|
$this->enter();
|
||||||
|
$this->waitUntil(function () {
|
||||||
|
$list = $this->els('#playlists .playlist');
|
||||||
|
$mostRecentPlaylist = end($list);
|
||||||
|
|
||||||
|
return $mostRecentPlaylist->getText() === 'Baz';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ use Facebook\WebDriver\WebDriverExpectedCondition;
|
||||||
use Illuminate\Contracts\Console\Kernel;
|
use Illuminate\Contracts\Console\Kernel;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
class TestCase extends \PHPUnit_Framework_TestCase
|
abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
use WebDriverShortcuts;
|
use WebDriverShortcuts;
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@ trait WebDriverShortcuts
|
||||||
*/
|
*/
|
||||||
protected function el($selector)
|
protected function el($selector)
|
||||||
{
|
{
|
||||||
if (is_a($selector, WebDriverElement::class)) {
|
if (is_string($selector)) {
|
||||||
return $selector;
|
return $this->driver->findElement(WebDriverBy::cssSelector($selector));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->driver->findElement(WebDriverBy::cssSelector($selector));
|
return $selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function els($selector)
|
protected function els($selector)
|
||||||
|
|
Loading…
Reference in a new issue