@@ -30,9 +30,48 @@ struct ConnectionSwitcherFilterTests {
3030 #expect( ConnectionSwitcherFilter . matches ( connection, query: " analy " ) )
3131 }
3232
33+ @Test ( " Host is searched " )
34+ func hostMatch( ) {
35+ let connection = TestFixtures . makeConnection ( name: " Primary " , database: " analytics " )
36+ #expect( ConnectionSwitcherFilter . matches ( connection, query: " localhost " ) )
37+ }
38+
3339 @Test ( " Non-matching query returns false " )
3440 func noMatch( ) {
3541 let connection = TestFixtures . makeConnection ( name: " Primary " , database: " analytics " )
3642 #expect( !ConnectionSwitcherFilter. matches ( connection, query: " zzz " ) )
3743 }
3844}
45+
46+ @Suite ( " Connection Switcher Selection " )
47+ struct ConnectionSwitcherSelectionTests {
48+ @Test ( " Empty list yields no selection " )
49+ func emptyList( ) {
50+ #expect( ConnectionSwitcherSelection . moved ( in: [ ] , from: nil , by: 1 ) == nil )
51+ }
52+
53+ @Test ( " Moving down advances to the next id " )
54+ func movesDown( ) {
55+ let ( a, b, c) = ( UUID ( ) , UUID ( ) , UUID ( ) )
56+ #expect( ConnectionSwitcherSelection . moved ( in: [ a, b, c] , from: a, by: 1 ) == b)
57+ #expect( ConnectionSwitcherSelection . moved ( in: [ a, b, c] , from: b, by: 1 ) == c)
58+ }
59+
60+ @Test ( " Moving up retreats to the previous id " )
61+ func movesUp( ) {
62+ let ( a, b, c) = ( UUID ( ) , UUID ( ) , UUID ( ) )
63+ #expect( ConnectionSwitcherSelection . moved ( in: [ a, b, c] , from: c, by: - 1 ) == b)
64+ }
65+
66+ @Test ( " Moving past the top clamps to the first id " )
67+ func clampsAtTop( ) {
68+ let ( a, b, c) = ( UUID ( ) , UUID ( ) , UUID ( ) )
69+ #expect( ConnectionSwitcherSelection . moved ( in: [ a, b, c] , from: a, by: - 1 ) == a)
70+ }
71+
72+ @Test ( " Moving past the bottom clamps to the last id " )
73+ func clampsAtBottom( ) {
74+ let ( a, b, c) = ( UUID ( ) , UUID ( ) , UUID ( ) )
75+ #expect( ConnectionSwitcherSelection . moved ( in: [ a, b, c] , from: c, by: 1 ) == c)
76+ }
77+ }
0 commit comments