forked from codestudiohq/laravel-totem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewDashboardTest.php
97 lines (84 loc) · 2.89 KB
/
ViewDashboardTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Studio\Totem\Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Studio\Totem\Result;
use Studio\Totem\Task;
use Studio\Totem\Tests\TestCase;
class ViewDashboardTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function user_can_view_dashboard()
{
$this->signIn();
$response = $this->get(route('totem.dashboard'));
$response->assertStatus(302);
}
/** @test */
public function guest_can_not_view_dashboard()
{
$response = $this->get(route('totem.dashboard'));
$response->assertStatus(403);
}
/** @test */
public function view_dashboard_single_task_no_results()
{
$this->signIn();
$task = Task::factory()->create();
$response = $this->get(route('totem.tasks.all', $task));
$response->assertStatus(200);
$this->assertEmpty($task->results);
$this->assertSame(0.0, $task->averageRuntime);
$response->assertSee($task->description);
}
/** @test */
public function view_dashboard_single_task_with_results()
{
$this->signIn();
$tasks = $this->_get_task_with_results();
$response = $this->get(route('totem.tasks.all', $tasks[0]));
$response->assertStatus(200);
$this->assertNotEmpty($tasks[0]->results);
$this->assertGreaterThanOrEqual(0.0, $tasks[0]->averageRuntime);
$response->assertSee($tasks[0]->description);
}
/** @test */
public function view_dashboard_single_task_with_multiple_results()
{
$this->signIn();
$tasks = $this->_get_task_with_results(1, 9);
$response = $this->get(route('totem.tasks.all', $tasks[0]));
$response->assertStatus(200);
$this->assertNotEmpty($tasks[0]->results);
$this->assertGreaterThanOrEqual(0.0, $tasks[0]->averageRuntime);
$response->assertSee($tasks[0]->description);
}
/** @test */
public function view_dashboard_multiple_tasks_with_multiple_results()
{
$this->signIn();
$tasks = $this->_get_task_with_results(4, 5);
$response = $this->get(route('totem.tasks.all', $tasks[0]));
$response->assertStatus(200);
foreach ($tasks as $task) {
$this->assertNotEmpty($task->results);
$this->assertGreaterThanOrEqual(0.0, $task->averageRuntime);
$response->assertSee($task->description);
}
}
/**
* @param int $task_count
* @param int $result_count
* @return mixed
*/
private function _get_task_with_results($task_count = 1, $result_count = 1)
{
return Task::factory()->times($task_count)
->create()
->each(function ($task) use ($result_count) {
for ($i = 0; $i < $result_count; $i++) {
$task->results()->save(Result::factory()->make());
}
});
}
}