mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Implemented bill chart JS test.
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class GoogleBillChartGeneratorTest
|
* Class GoogleBillChartGeneratorTest
|
||||||
@@ -6,6 +10,9 @@
|
|||||||
class ChartJsBillChartGeneratorTest extends TestCase
|
class ChartJsBillChartGeneratorTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var \FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator */
|
||||||
|
protected $object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the fixture, for example, opens a network connection.
|
* Sets up the fixture, for example, opens a network connection.
|
||||||
* This method is called before a test is executed.
|
* This method is called before a test is executed.
|
||||||
@@ -14,6 +21,9 @@ class ChartJsBillChartGeneratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->object = new ChartJsBillChartGenerator();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +41,31 @@ class ChartJsBillChartGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testFrontpage()
|
public function testFrontpage()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
// to test frontpage, we generate the exact fake entries
|
||||||
|
// needed:
|
||||||
|
$paid = new Collection;
|
||||||
|
for ($i = 0; $i < 5; $i++) {
|
||||||
|
$obj = new stdClass();
|
||||||
|
$obj->description = 'Something';
|
||||||
|
$obj->amount = 100;
|
||||||
|
$paid->push($obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
$unpaid = new Collection;
|
||||||
|
$sum = 0;
|
||||||
|
for ($i = 0; $i < 5; $i++) {
|
||||||
|
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||||
|
$date = new Carbon;
|
||||||
|
$sum += (($bill->amount_max + $bill->amount_min) / 2);
|
||||||
|
$unpaid->push([$bill, $date]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$data = $this->object->frontpage($paid, $unpaid);
|
||||||
|
|
||||||
|
$this->assertCount(2, $data);
|
||||||
|
$this->assertEquals($sum, $data[0]['value']);
|
||||||
|
$this->assertEquals(500, $data[1]['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,6 +73,28 @@ class ChartJsBillChartGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testSingle()
|
public function testSingle()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
|
||||||
|
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$preference->data = 'en';
|
||||||
|
$preference->save();
|
||||||
|
|
||||||
|
// mock language preference:
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
|
||||||
|
|
||||||
|
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
|
||||||
|
$entries = new Collection;
|
||||||
|
for ($i = 0; $i < 5; $i++) {
|
||||||
|
$obj = new stdClass;
|
||||||
|
$obj->amount = 100;
|
||||||
|
$obj->date = new Carbon;
|
||||||
|
$entries->push($obj);
|
||||||
|
}
|
||||||
|
$data = $this->object->single($bill, $entries);
|
||||||
|
|
||||||
|
$this->assertCount(5, $data['labels']);
|
||||||
|
$this->assertCount(5, $data['datasets'][1]['data']);
|
||||||
|
$this->assertEquals(100, $data['datasets'][1]['data'][0]); // see if first is equal.
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user