@@ -4,78 +4,105 @@ defmodule LiveDebugger.Services.ModuleDiscoveryServiceTest do
44 import Mox
55
66 alias LiveDebugger.Services.ModuleDiscoveryService
7+ alias LiveDebugger.MockModuleService
8+
9+ @ modules [
10+ CoolApp.LiveViews.UserDashboard ,
11+ CoolApp.LiveViews.UserProfile ,
12+ CoolApp.Service.UserService ,
13+ CoolApp.LiveComponent.UserElement ,
14+ CoolApp.LiveComponent.UserSettings
15+ ]
16+
17+ test "all_modules/0 returns all modules" do
18+ modules = @ modules
19+
20+ MockModuleService
21+ |> expect ( :all , fn ->
22+ Enum . map ( modules , fn module ->
23+ { to_charlist ( module ) , to_charlist ( "/prefix/lib/#{ module } .beam" ) ,
24+ module == CoolApp.LiveViews.UserDashboard }
25+ end )
26+ end )
27+
28+ assert modules == ModuleDiscoveryService . all_modules ( )
29+ end
730
831 describe "live_view_modules/1" do
932 test "filters LiveView modules correctly" do
10- modules = [
11- CoolApp.LiveViews.UserDashboard ,
12- CoolApp.Service.UserService ,
13- CoolApp.LiveComponent.UserElement
14- ]
15-
16- LiveDebugger.MockModuleService
17- |> expect ( :loaded? , 3 , fn _module -> true end )
18- |> expect ( :behaviours , 3 , fn module ->
19- case module do
20- CoolApp.LiveViews.UserDashboard -> [ Phoenix.LiveView ]
21- CoolApp.Service.UserService -> [ ]
22- CoolApp.LiveComponent.UserElement -> [ Phoenix.LiveComponent ]
23- end
33+ modules = @ modules
34+
35+ MockModuleService
36+ |> expect ( :loaded? , 5 , fn _module -> true end )
37+ |> expect ( :behaviours , 5 , fn module ->
38+ get_behaviours ( module )
2439 end )
2540
26- result = ModuleDiscoveryService . live_view_modules ( modules )
27- assert result == [ CoolApp.LiveViews.UserDashboard ]
41+ assert ModuleDiscoveryService . live_view_modules ( modules ) == [
42+ CoolApp.LiveViews.UserDashboard ,
43+ CoolApp.LiveViews.UserProfile
44+ ]
2845 end
2946
3047 test "filters unloaded modules correctly" do
31- modules = [
32- CoolApp.LiveViews.UserDashboard ,
33- CoolApp.Service.UserService ,
34- CoolApp.LiveComponent.UserElement
35- ]
48+ modules = @ modules
3649
37- LiveDebugger.MockModuleService
38- |> expect ( :loaded? , 3 , fn _module -> false end )
50+ MockModuleService
51+ |> expect ( :loaded? , 5 , fn
52+ CoolApp.LiveViews.UserDashboard -> false
53+ _ -> true
54+ end )
55+ |> expect ( :behaviours , 4 , fn module ->
56+ get_behaviours ( module )
57+ end )
3958
40- result = ModuleDiscoveryService . live_view_modules ( modules )
41- assert result == [ ]
59+ assert ModuleDiscoveryService . live_view_modules ( modules ) == [
60+ CoolApp.LiveViews.UserProfile
61+ ]
4262 end
4363 end
4464
4565 describe "live_component_modules/1" do
4666 test "filters LiveComponent modules correctly" do
47- loaded_modules = [
48- CoolApp.LiveViews.UserDashboard ,
49- CoolApp.Service.UserService ,
50- CoolApp.LiveComponent.UserElement
51- ]
52-
53- LiveDebugger.MockModuleService
54- |> expect ( :loaded? , 3 , fn _module -> true end )
55- |> expect ( :behaviours , 3 , fn module ->
56- case module do
57- CoolApp.LiveViews.UserDashboard -> [ Phoenix.LiveView ]
58- CoolApp.Service.UserService -> [ ]
59- CoolApp.LiveComponent.UserElement -> [ Phoenix.LiveComponent ]
60- end
67+ modules = @ modules
68+
69+ MockModuleService
70+ |> expect ( :loaded? , 5 , fn _module -> true end )
71+ |> expect ( :behaviours , 5 , fn module ->
72+ get_behaviours ( module )
6173 end )
6274
63- result = ModuleDiscoveryService . live_component_modules ( loaded_modules )
64- assert result == [ CoolApp.LiveComponent.UserElement ]
75+ assert ModuleDiscoveryService . live_component_modules ( modules ) == [
76+ CoolApp.LiveComponent.UserElement ,
77+ CoolApp.LiveComponent.UserSettings
78+ ]
6579 end
6680
6781 test "filters unloaded modules correctly" do
68- modules = [
69- CoolApp.LiveViews.UserDashboard ,
70- CoolApp.Service.UserService ,
71- CoolApp.LiveComponent.UserElement
72- ]
82+ modules = @ modules
7383
74- LiveDebugger.MockModuleService
75- |> expect ( :loaded? , 3 , fn _module -> false end )
84+ MockModuleService
85+ |> expect ( :loaded? , 5 , fn
86+ CoolApp.LiveComponent.UserElement -> false
87+ _ -> true
88+ end )
89+ |> expect ( :behaviours , 4 , fn module ->
90+ get_behaviours ( module )
91+ end )
92+
93+ assert ModuleDiscoveryService . live_component_modules ( modules ) == [
94+ CoolApp.LiveComponent.UserSettings
95+ ]
96+ end
97+ end
7698
77- result = ModuleDiscoveryService . live_component_modules ( modules )
78- assert result == [ ]
99+ defp get_behaviours ( module ) do
100+ case module do
101+ CoolApp.LiveViews.UserDashboard -> [ Phoenix.LiveView ]
102+ CoolApp.LiveViews.UserProfile -> [ Phoenix.LiveView ]
103+ CoolApp.Service.UserService -> [ ]
104+ CoolApp.LiveComponent.UserElement -> [ Phoenix.LiveComponent ]
105+ CoolApp.LiveComponent.UserSettings -> [ Phoenix.LiveComponent ]
79106 end
80107 end
81108end
0 commit comments