Tests: Add more Dashlets/Pane use cases

This commit is contained in:
Yonas Habteab 2022-06-03 17:53:41 +02:00
parent 12af0d2ce1
commit 05fec9de89
2 changed files with 224 additions and 0 deletions

View File

@ -5,8 +5,201 @@
namespace Tests\Icinga\Web\Dashboard;
use Icinga\Test\BaseDashboardTestCase;
use Icinga\Web\Dashboard\Dashlet;
use Icinga\Web\Dashboard\Pane;
class DashletTest extends BaseDashboardTestCase
{
const TEST_DASHLET = 'Test Dashlet';
protected function getTestDashlet(string $name = self::TEST_DASHLET): Dashlet
{
return new Dashlet($name, 'from/new-test');
}
public function testWhetherManageEntryManagesANewDashlet()
{
$home = $this->getTestHome();
$this->dashboard->manageEntry($home);
$pane = new Pane('Test Pane');
$home->manageEntry($pane);
$pane->manageEntry([$this->getTestDashlet(), $this->getTestDashlet('Test Me')]);
$this->dashboard->load(self::TEST_HOME);
$home = $this->dashboard->getActiveHome();
$pane = $home->getActivePane();
$this->assertCount(
2,
$pane->getEntries(),
'Pane::manageEntry() could not manage a new Dashlet'
);
}
/**
* @depends testWhetherManageEntryManagesANewDashlet
*/
public function testWhetherManageEntryUpdatesExistingDashlet()
{
$home = $this->getTestHome();
$this->dashboard->manageEntry($home);
$pane = new Pane('Test Pane');
$home->manageEntry($pane);
$pane->manageEntry($this->getTestDashlet());
$this->dashboard->load(self::TEST_HOME);
$home = $this->dashboard->getActiveHome();
$pane = $home->getActivePane();
$pane->getEntry(self::TEST_DASHLET)->setTitle('Hello');
$pane->manageEntry($pane->getEntries());
$this->dashboard->load(self::TEST_HOME);
$home = $this->dashboard->getActiveHome();
$pane = $home->getActivePane();
$this->assertEquals(
'Hello',
$pane->getEntry(self::TEST_DASHLET)->getTitle(),
'Pane::manageEntry() could not update existing Dashlet'
);
}
/**
* @depends testWhetherManageEntryUpdatesExistingDashlet
*/
public function testWhetherManageEntryMovesADashletToAnotherPaneWithinTheSameHome()
{
$default = $this->getTestHome();
$this->dashboard->manageEntry($default);
$pane1 = new Pane('Test1');
$pane2 = new Pane('Test2');
$default->manageEntry([$pane1, $pane2]);
$pane1->manageEntry($this->getTestDashlet());
$this->dashboard->load(self::TEST_HOME);
$default = $this->dashboard->getActiveHome();
$pane1 = $default->getActivePane();
$pane2 = $default->getEntry('Test2');
// Move the dashlet from pane1 -> pane2
$pane2->manageEntry($pane1->getEntries(), $pane1);
$this->dashboard->load(self::TEST_HOME);
$default = $this->dashboard->getActiveHome();
$pane1 = $default->getActivePane();
$pane2 = $default->getEntry('Test2');
$this->assertCount(
1,
$pane2->getEntries(),
'Pane::manageEntry() could not move a Dashlet to another Pane within the same Dashboard Home'
);
$this->assertCount(
0,
$pane1->getEntries(),
'Pane::manageEntry() could not completely move a Dashlet to another Pane'
);
}
/**
* @depends testWhetherManageEntryMovesADashletToAnotherPaneWithinTheSameHome
*/
public function testWhetherManageEntryMovesADashletToAnotherPaneAndAnotherHome()
{
$this->dashboard->load(); // Not to encounter any duplicate errors
$default = $this->getTestHome();
$home = $this->getTestHome('Home Test');
$this->dashboard->manageEntry([$default, $home]);
$pane1 = new Pane('Test1');
$pane2 = new Pane('Test2');
$default->manageEntry($pane1);
$home->manageEntry($pane2);
$pane1->manageEntry($this->getTestDashlet());
$this->dashboard->load(self::TEST_HOME, $pane1->getName(), true);
$default = $this->dashboard->getActiveHome();
$home = $this->dashboard->getEntry($home->getName());
$home->loadDashboardEntries();
$pane1 = $default->getActivePane();
$pane2 = $home->getActivePane();
// Move the dashlet from pane1 -> pane2
$pane2->manageEntry($pane1->getEntries(), $pane1);
$this->dashboard->load(self::TEST_HOME, $pane1->getName(), true);
//$default = $this->dashboard->getActiveHome();
$home = $this->dashboard->getEntry($home->getName());
$home->loadDashboardEntries();
$pane2 = $home->getActivePane();
$this->assertCount(
1,
$pane2->getEntries(),
'Pane::manageEntry() could not move a Dashlet to another Pane from another Dashboard Home'
);
}
public function testWhetherManageEntryThrowsAnExceptionWhenDashboardHomeIsNotSet()
{
$this->expectException(\LogicException::class);
$default = new Pane('Test Pane');
$default->manageEntry($this->getTestDashlet());
}
public function testWhetherManageEntryThrowsAnExceptionOnDuplicatedError()
{
$this->expectException(\LogicException::class);
$default = $this->getTestHome();
$this->dashboard->manageEntry($default);
// Dashboard Panes
$pane1 = new Pane('Test1');
$pane2 = new Pane('Test2');
$default->manageEntry([$pane1, $pane2]);
// Dashlets
$pane1->manageEntry([$this->getTestDashlet(), $this->getTestDashlet('Test Me')]);
$pane2->manageEntry([$this->getTestDashlet(), $this->getTestDashlet('Test Me')]);
$this->dashboard->load($default->getName());
$default = $this->dashboard->getActiveHome();
$pane1 = $default->getActivePane();
$pane2 = $default->getEntry('Test2');
$pane1->manageEntry($this->getTestDashlet(), $pane2);
}
public function testWhetherManageEntryThrowsAnExceptionWhenPassingInvalidArgument()
{
$this->expectException(\InvalidArgumentException::class);
$default = new Pane('Test Pane');
$default->manageEntry($this->getTestDashlet(), $this->getTestHome());
}
}

View File

@ -173,4 +173,35 @@ class PaneTest extends BaseDashboardTestCase
'DashboardHome::manageEntry() could not move a Dashboard Pane to another existing Dashboard Home'
);
}
public function testWhetherManageEntryThrowsAnExceptionOnDuplicatedError()
{
$this->expectException(\LogicException::class);
$default = $this->getTestHome();
$home = $this->getTestHome('Second Home');
// Dashboard Homes
$this->dashboard->manageEntry([$home, $default]);
// Dashboard Panes
$default->manageEntry([$this->getTestPane(), $this->getTestPane('Test Me')]);
$home->manageEntry([$this->getTestPane(), $this->getTestPane('Test Me')]);
$this->dashboard->load();
$home = $this->dashboard->getActiveHome();
$default = $this->dashboard->getEntry(self::TEST_HOME);
$default->loadDashboardEntries();
$default->manageEntry($home->getEntry(self::TEST_PANE), $home);
}
public function testWhetherManageEntryThrowsAnExceptionWhenPassingInvalidArgument()
{
$this->expectException(\InvalidArgumentException::class);
$default = $this->getTestHome();
$default->manageEntry($this->getTestPane(), $this->getTestPane());
}
}