22
33namespace Tests \Unit \Controllers ;
44
5+ use App \Models \Application ;
6+ use App \Models \LogFile ;
7+ use App \Models \Server ;
8+ use App \Models \User ;
59use PHPUnit \Framework \Attributes \Test ;
610use Tests \TestCase ;
711
@@ -10,18 +14,85 @@ class DashboardControllerTest extends TestCase
1014 #[Test]
1115 public function you_must_be_logged_in_to_see_the_dashboard ()
1216 {
13- //
17+ $ this ->assertGuest ();
18+
19+ $ this ->get (route ('dashboard ' ))
20+ ->assertRedirectToRoute ('login ' );
1421 }
1522
1623 #[Test]
1724 public function it_can_show_the_empty_dashboard ()
1825 {
19- //
26+ $ user = User::factory ()->create ();
27+
28+ $ this ->actingAs ($ user )
29+ ->get (route ('dashboard ' ))
30+ ->assertStatus (200 );
2031 }
2132
2233 #[Test]
2334 public function it_can_show_the_dashboard ()
2435 {
25- //
36+ $ user = User::factory ()->create ();
37+
38+ $ server1 = Server::factory ()->create ();
39+ $ application1 = Application::factory ()->create (['server_id ' => $ server1 ->id ]);
40+ $ application2 = Application::factory ()->create (['server_id ' => $ server1 ->id ]);
41+
42+ $ server2 = Server::factory ()->create ();
43+ $ application3 = Application::factory ()->create (['server_id ' => $ server2 ->id ]);
44+
45+ $ this ->actingAs ($ user )
46+ ->get (route ('dashboard ' ))
47+ ->assertStatus (200 )
48+ ->assertSee ($ server1 ->name )
49+ ->assertSee ($ server2 ->name )
50+ ->assertSee ($ application1 ->name )
51+ ->assertSee ($ application2 ->name )
52+ ->assertSee ($ application3 ->name );
53+ }
54+
55+ #[Test]
56+ public function it_can_show_the_dashboard__modal_one_deep ()
57+ {
58+ $ user = User::factory ()->create ();
59+
60+ $ server1 = Server::factory ()->create ();
61+ $ application1 = Application::factory ()->create (['server_id ' => $ server1 ->id ]);
62+ $ application2 = Application::factory ()->create (['server_id ' => $ server1 ->id ]);
63+
64+ $ this ->actingAs ($ user )
65+ ->get (route ('dashboard.show-two ' , [$ server1 ->slug , $ application1 ->slug ]))
66+ ->assertStatus (200 );
67+ }
68+
69+ #[Test]
70+ public function it_can_show_the_dashboard__modal_two_deep ()
71+ {
72+ $ user = User::factory ()->create ();
73+
74+ $ server1 = Server::factory ()->create ();
75+ $ application1 = Application::factory ()->create (['server_id ' => $ server1 ->id ]);
76+ $ application2 = Application::factory ()->create (['server_id ' => $ server1 ->id ]);
77+
78+ $ logFile = LogFile::factory ()->forApplication ($ application2 )->create ();
79+
80+ $ this ->actingAs ($ user )
81+ ->get (route ('dashboard.show-three ' , [$ application2 ->server ->slug , $ application2 ->slug , $ logFile ->file_name ]))
82+ ->assertStatus (200 );
83+ }
84+
85+ #[Test]
86+ public function it_can_show_the_dashboard__modal_redirects_if_log_does_not_exist ()
87+ {
88+ $ user = User::factory ()->create ();
89+
90+ $ application = Application::factory ()->create ();
91+
92+ $ logFile = LogFile::factory ()->forApplication ($ application )->create ();
93+
94+ $ this ->actingAs ($ user )
95+ ->get (route ('dashboard.show-three ' , [$ application ->server ->slug , $ application ->slug , 'some-other-file.log ' ]))
96+ ->assertRedirectToRoute ('dashboard ' );
2697 }
2798}
0 commit comments