Commit 9fd57f5 1 parent acf17ac commit 9fd57f5 Copy full SHA for 9fd57f5
File tree 5 files changed +36
-24
lines changed
5 files changed +36
-24
lines changed Original file line number Diff line number Diff line change @@ -15,21 +15,21 @@ type HomePage struct {
15
15
once sync.Once
16
16
}
17
17
18
- // homePageInstance holds the singleton instance of HomePage
19
- var homePageInstance * HomePage
18
+ // HomePageInstance holds the singleton instance of HomePage
19
+ var HomePageInstance * HomePage
20
20
21
21
// GetHomePage returns the singleton instance of the HomePage state
22
22
func GetHomePage () * HomePage {
23
23
// Use sync.Once to ensure the HomePage is initialized only once
24
- if homePageInstance == nil {
25
- homePageInstance = & HomePage {}
26
- homePageInstance .once .Do (func () {
27
- homePageInstance .BaseState = BaseState {
24
+ if HomePageInstance == nil {
25
+ HomePageInstance = & HomePage {}
26
+ HomePageInstance .once .Do (func () {
27
+ HomePageInstance .BaseState = BaseState {
28
28
Transitions : []State {GetInitiaInit ()}, // Ensure all transitions are properly initialized
29
29
}
30
30
})
31
31
}
32
- return homePageInstance
32
+ return HomePageInstance
33
33
}
34
34
35
35
func (hp * HomePage ) Init () tea.Cmd {
Original file line number Diff line number Diff line change @@ -14,20 +14,20 @@ type LaunchNewMinitia struct {
14
14
once sync.Once
15
15
}
16
16
17
- // launchNewMinitiaInstance holds the singleton instance of LaunchNewMinitia
18
- var launchNewMinitiaInstance * LaunchNewMinitia
17
+ // LaunchNewMinitiaInstance holds the singleton instance of LaunchNewMinitia
18
+ var LaunchNewMinitiaInstance * LaunchNewMinitia
19
19
20
20
// GetLaunchNewMinitia returns the singleton instance of the LaunchNewMinitia state
21
21
func GetLaunchNewMinitia () * LaunchNewMinitia {
22
- if launchNewMinitiaInstance == nil {
23
- launchNewMinitiaInstance = & LaunchNewMinitia {}
24
- launchNewMinitiaInstance .once .Do (func () {
25
- launchNewMinitiaInstance .BaseState = BaseState {
22
+ if LaunchNewMinitiaInstance == nil {
23
+ LaunchNewMinitiaInstance = & LaunchNewMinitia {}
24
+ LaunchNewMinitiaInstance .once .Do (func () {
25
+ LaunchNewMinitiaInstance .BaseState = BaseState {
26
26
Transitions : []State {},
27
27
}
28
28
})
29
29
}
30
- return launchNewMinitiaInstance
30
+ return LaunchNewMinitiaInstance
31
31
}
32
32
33
33
func (lnm * LaunchNewMinitia ) Init () tea.Cmd {
Original file line number Diff line number Diff line change @@ -14,20 +14,20 @@ type RunL1Node struct {
14
14
once sync.Once
15
15
}
16
16
17
- // runL1NodeInstance holds the singleton instance of RunL1Node
18
- var runL1NodeInstance * RunL1Node
17
+ // RunL1NodeInstance holds the singleton instance of RunL1Node
18
+ var RunL1NodeInstance * RunL1Node
19
19
20
20
// GetRunL1Node returns the singleton instance of the RunL1Node state
21
21
func GetRunL1Node () * RunL1Node {
22
- if runL1NodeInstance == nil {
23
- runL1NodeInstance = & RunL1Node {}
24
- runL1NodeInstance .once .Do (func () {
25
- runL1NodeInstance .BaseState = BaseState {
22
+ if RunL1NodeInstance == nil {
23
+ RunL1NodeInstance = & RunL1Node {}
24
+ RunL1NodeInstance .once .Do (func () {
25
+ RunL1NodeInstance .BaseState = BaseState {
26
26
Transitions : []State {},
27
27
}
28
28
})
29
29
}
30
- return runL1NodeInstance
30
+ return RunL1NodeInstance
31
31
}
32
32
33
33
func (rl1 * RunL1Node ) Init () tea.Cmd {
Original file line number Diff line number Diff line change @@ -6,10 +6,10 @@ import (
6
6
7
7
// Example Reset function for all states:
8
8
func ResetStates () {
9
- homePageInstance = nil
9
+ HomePageInstance = nil
10
10
InitiaInitInstance = nil
11
- runL1NodeInstance = nil
12
- launchNewMinitiaInstance = nil
11
+ RunL1NodeInstance = nil
12
+ LaunchNewMinitiaInstance = nil
13
13
}
14
14
15
15
type State interface {
Original file line number Diff line number Diff line change @@ -9,6 +9,18 @@ import (
9
9
"github.com/initia-labs/weave/states"
10
10
)
11
11
12
+ func TestSingletonInitializations (t * testing.T ) {
13
+ // Reset all singleton instances before testing to ensure a clean state
14
+ states .ResetStates ()
15
+ states .GetHomePage ()
16
+
17
+ // Assert that none of the singleton instances are nil
18
+ assert .NotNil (t , states .HomePageInstance , "HomePage instance should not be nil" )
19
+ assert .NotNil (t , states .InitiaInitInstance , "InitiaInit instance should not be nil" )
20
+ assert .NotNil (t , states .RunL1NodeInstance , "RunL1Node instance should not be nil" )
21
+ assert .NotNil (t , states .LaunchNewMinitiaInstance , "LaunchNewMinitia instance should not be nil" )
22
+ }
23
+
12
24
func TestInitiaInitNavigation (t * testing.T ) {
13
25
states .ResetStates () // Optional: Reset at package initialization if needed for all tests
14
26
home := states .GetHomePage ()
You can’t perform that action at this time.
0 commit comments