users weekly stats as bar-chart in dashboard (#847)
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
|
||||
namespace App\Tests\Repository;
|
||||
|
||||
use App\Model\Widget;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Repository\WidgetRepository;
|
||||
use App\Security\CurrentUser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -22,8 +22,9 @@ class WidgetRepositoryTest extends TestCase
|
||||
public function testHasWidget()
|
||||
{
|
||||
$repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$userMock = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => []]);
|
||||
$sut = new WidgetRepository($repoMock, $userMock, ['test' => []]);
|
||||
|
||||
$this->assertFalse($sut->has('foo'));
|
||||
$this->assertTrue($sut->has('test'));
|
||||
@@ -31,14 +32,41 @@ class WidgetRepositoryTest extends TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Cannot find widget: foo
|
||||
* @expectedExceptionMessage Cannot find widget "foo".
|
||||
*/
|
||||
public function testGetWidgetThrowsExceptionOnNonExistingWidget()
|
||||
{
|
||||
$repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$userMock = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => []]);
|
||||
$sut->get('foo', null);
|
||||
$sut = new WidgetRepository($repoMock, $userMock, ['test' => []]);
|
||||
$sut->get('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \App\Widget\WidgetException
|
||||
* @expectedExceptionMessage Unknown widget type "\App\Widget\Type\FooBar"
|
||||
*/
|
||||
public function testGetWidgetThrowsExceptionOnInvalidType()
|
||||
{
|
||||
$repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$userMock = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$sut = new WidgetRepository($repoMock, $userMock, ['test' => ['type' => 'FooBar', 'user' => false]]);
|
||||
$sut->get('test');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \App\Widget\WidgetException
|
||||
* @expectedExceptionMessage Invalid widget type "\App\Widget\Type\CompoundChart" does not extend AbstractWidgetType
|
||||
*/
|
||||
public function testGetWidgetTriggersExceptionOnWrongClass()
|
||||
{
|
||||
$repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$userMock = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$sut = new WidgetRepository($repoMock, $userMock, ['test' => ['type' => 'CompoundChart', 'user' => false]]);
|
||||
$sut->get('test');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,6 +77,8 @@ class WidgetRepositoryTest extends TestCase
|
||||
$repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$repoMock->method('getStatistic')->willReturn($data);
|
||||
|
||||
$userMock = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$widget = [
|
||||
'color' => 'sunny',
|
||||
'icon' => 'far fa-test',
|
||||
@@ -59,24 +89,25 @@ class WidgetRepositoryTest extends TestCase
|
||||
'title' => 'Test widget',
|
||||
];
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => $widget]);
|
||||
$widget = $sut->get('test', null);
|
||||
$sut = new WidgetRepository($repoMock, $userMock, ['test' => $widget]);
|
||||
$widget = $sut->get('test');
|
||||
|
||||
$options = $widget->getOptions();
|
||||
$this->assertEquals('Test widget', $widget->getTitle());
|
||||
$this->assertEquals($data, $widget->getData());
|
||||
$this->assertEquals('sunny', $widget->getColor());
|
||||
$this->assertEquals('far fa-test', $widget->getIcon());
|
||||
$this->assertEquals($dataType, $widget->getDataType());
|
||||
$this->assertEquals('sunny', $options['color']);
|
||||
$this->assertEquals('far fa-test', $options['icon']);
|
||||
$this->assertEquals($dataType, $options['dataType']);
|
||||
}
|
||||
|
||||
public function getWidgetData()
|
||||
{
|
||||
return [
|
||||
[12, TimesheetRepository::STATS_QUERY_DURATION, Widget::DATA_TYPE_DURATION],
|
||||
[112233, TimesheetRepository::STATS_QUERY_AMOUNT, Widget::DATA_TYPE_INT],
|
||||
[37, TimesheetRepository::STATS_QUERY_ACTIVE, Widget::DATA_TYPE_INT],
|
||||
[375, TimesheetRepository::STATS_QUERY_RATE, Widget::DATA_TYPE_MONEY],
|
||||
[['test' => 'foo'], TimesheetRepository::STATS_QUERY_USER, Widget::DATA_TYPE_INT],
|
||||
[12, TimesheetRepository::STATS_QUERY_DURATION, 'duration'],
|
||||
[112233, TimesheetRepository::STATS_QUERY_AMOUNT, 'int'],
|
||||
[37, TimesheetRepository::STATS_QUERY_ACTIVE, 'int'],
|
||||
[375, TimesheetRepository::STATS_QUERY_RATE, 'money'],
|
||||
[['test' => 'foo'], TimesheetRepository::STATS_QUERY_USER, 'int'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user