diff --git a/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php b/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php index 597d120d04..b084678de0 100644 --- a/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php +++ b/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php @@ -71,8 +71,8 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator $current->addDay(); } $data['datasets'][] = $set; - $data['count']++; } + $data['count'] = count($data['datasets']); return $data; } diff --git a/tests/database/.gitignore b/tests/database/.gitignore deleted file mode 100644 index 9b1dffd90f..0000000000 --- a/tests/database/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.sqlite diff --git a/tests/generators/ChartJsAccountChartGeneratorTest.php b/tests/generators/ChartJsAccountChartGeneratorTest.php index cc5f9b713a..fd6cd6118f 100644 --- a/tests/generators/ChartJsAccountChartGeneratorTest.php +++ b/tests/generators/ChartJsAccountChartGeneratorTest.php @@ -1,19 +1,32 @@ object = new ChartJsAccountChartGenerator; + parent::setUp(); + } /** @@ -26,20 +39,41 @@ class ChartJsAccountChartGeneratorTest extends TestCase parent::setUpBeforeClass(); } - /** - * @covers FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator::all - */ - public function testAll() - { - $this->markTestIncomplete(); - } - /** * @covers FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator::frontpage */ public function testFrontpage() { - $this->markTestIncomplete(); + // be somebody + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + // create some accounts: + $accounts = new Collection; + for ($i = 0; $i < 5; $i++) { + $accounts->push(FactoryMuffin::create('FireflyIII\Models\Account')); + } + + $preference = FactoryMuffin::create('FireflyIII\Models\Preference'); + $preference->data = 'en'; + $preference->save(); + + // data for call: + $start = Carbon::createFromDate(2015, 1, 1); + $end = Carbon::createFromDate(2015, 1, 15); + + // mock language preference: + Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference); + + // mock Steam::balance + Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0); + + // call + $result = $this->object->frontpage($accounts, $start, $end); + + $this->assertEquals($accounts->count(), $result['count']); + $this->assertCount(15, $result['labels']); + $this->assertCount($accounts->count(), $result['datasets']); } /** @@ -47,6 +81,34 @@ class ChartJsAccountChartGeneratorTest extends TestCase */ public function testSingle() { - $this->markTestIncomplete(); + // be somebody + $user = FactoryMuffin::create('FireflyIII\User'); + $this->be($user); + + $preference = FactoryMuffin::create('FireflyIII\Models\Preference'); + $preference->data = 'en'; + $preference->save(); + + // mock language preference: + Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference); + + // mock Steam::balance + Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0); + + // data for call: + $start = Carbon::createFromDate(2015, 1, 1); + $end = Carbon::createFromDate(2015, 1, 15); + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + + // call + $result = $this->object->single($account, $start, $end); + + + // test + $this->assertCount(15, $result['labels']); + $this->assertEquals($account->name, $result['datasets'][0]['label']); + $this->assertCount(15, $result['datasets'][0]['data']); + + } } \ No newline at end of file