@@ -27,117 +27,65 @@ describe('List Typeahead', () => {
27
27
) ;
28
28
}
29
29
30
+ let items : SignalLike < TestItem [ ] > ;
31
+ let typeahead : ListTypeahead < TestItem > ;
32
+ let navigation : ListNavigation < TestItem > ;
33
+
34
+ beforeEach ( ( ) => {
35
+ items = getItems ( 5 ) ;
36
+ navigation = new ListNavigation ( {
37
+ items,
38
+ wrap : signal ( false ) ,
39
+ activeIndex : signal ( 0 ) ,
40
+ skipDisabled : signal ( false ) ,
41
+ textDirection : signal ( 'ltr' ) ,
42
+ orientation : signal ( 'vertical' ) ,
43
+ } ) ;
44
+ typeahead = new ListTypeahead ( {
45
+ navigation,
46
+ typeaheadDelay : signal ( 0.5 ) ,
47
+ } ) ;
48
+ } ) ;
49
+
30
50
describe ( '#search' , ( ) => {
31
51
it ( 'should navigate to an item' , ( ) => {
32
- const items = getItems ( 5 ) ;
33
- const activeIndex = signal ( 0 ) ;
34
- const navigation = new ListNavigation ( {
35
- items,
36
- activeIndex,
37
- wrap : signal ( false ) ,
38
- skipDisabled : signal ( false ) ,
39
- textDirection : signal ( 'ltr' ) ,
40
- orientation : signal ( 'vertical' ) ,
41
- } ) ;
42
- const typeahead = new ListTypeahead ( {
43
- navigation,
44
- typeaheadDelay : signal ( 0.5 ) ,
45
- } ) ;
46
-
47
52
typeahead . search ( 'i' ) ;
48
- expect ( activeIndex ( ) ) . toBe ( 1 ) ;
53
+ expect ( navigation . inputs . activeIndex ( ) ) . toBe ( 1 ) ;
49
54
50
55
typeahead . search ( 't' ) ;
51
56
typeahead . search ( 'e' ) ;
52
57
typeahead . search ( 'm' ) ;
53
58
typeahead . search ( ' ' ) ;
54
59
typeahead . search ( '3' ) ;
55
- expect ( activeIndex ( ) ) . toBe ( 3 ) ;
60
+ expect ( navigation . inputs . activeIndex ( ) ) . toBe ( 3 ) ;
56
61
} ) ;
57
62
58
63
it ( 'should reset after a delay' , fakeAsync ( ( ) => {
59
- const items = getItems ( 5 ) ;
60
- const activeIndex = signal ( 0 ) ;
61
- const navigation = new ListNavigation ( {
62
- items,
63
- activeIndex,
64
- wrap : signal ( false ) ,
65
- skipDisabled : signal ( false ) ,
66
- textDirection : signal ( 'ltr' ) ,
67
- orientation : signal ( 'vertical' ) ,
68
- } ) ;
69
- const typeahead = new ListTypeahead ( {
70
- navigation,
71
- typeaheadDelay : signal ( 0.5 ) ,
72
- } ) ;
73
-
74
64
typeahead . search ( 'i' ) ;
75
- expect ( activeIndex ( ) ) . toBe ( 1 ) ;
65
+ expect ( navigation . inputs . activeIndex ( ) ) . toBe ( 1 ) ;
76
66
77
67
tick ( 500 ) ;
78
68
79
69
typeahead . search ( 'i' ) ;
80
- expect ( activeIndex ( ) ) . toBe ( 2 ) ;
70
+ expect ( navigation . inputs . activeIndex ( ) ) . toBe ( 2 ) ;
81
71
} ) ) ;
82
72
83
73
it ( 'should skip disabled items' , ( ) => {
84
- const items = getItems ( 5 ) ;
85
- const activeIndex = signal ( 0 ) ;
86
- const navigation = new ListNavigation ( {
87
- items,
88
- activeIndex,
89
- wrap : signal ( false ) ,
90
- skipDisabled : signal ( true ) ,
91
- textDirection : signal ( 'ltr' ) ,
92
- orientation : signal ( 'vertical' ) ,
93
- } ) ;
94
- const typeahead = new ListTypeahead ( {
95
- navigation,
96
- typeaheadDelay : signal ( 0.5 ) ,
97
- } ) ;
98
74
items ( ) [ 1 ] . disabled . set ( true ) ;
99
-
75
+ ( navigation . inputs . skipDisabled as WritableSignalLike < boolean > ) . set ( true ) ;
100
76
typeahead . search ( 'i' ) ;
101
- expect ( activeIndex ( ) ) . toBe ( 2 ) ;
77
+ console . log ( typeahead . inputs . navigation . inputs . items ( ) . map ( i => i . disabled ( ) ) ) ;
78
+ expect ( navigation . inputs . activeIndex ( ) ) . toBe ( 2 ) ;
102
79
} ) ;
103
80
104
81
it ( 'should not skip disabled items' , ( ) => {
105
- const items = getItems ( 5 ) ;
106
- const activeIndex = signal ( 0 ) ;
107
- const navigation = new ListNavigation ( {
108
- items,
109
- activeIndex,
110
- wrap : signal ( false ) ,
111
- skipDisabled : signal ( false ) ,
112
- textDirection : signal ( 'ltr' ) ,
113
- orientation : signal ( 'vertical' ) ,
114
- } ) ;
115
- const typeahead = new ListTypeahead ( {
116
- navigation,
117
- typeaheadDelay : signal ( 0.5 ) ,
118
- } ) ;
119
82
items ( ) [ 1 ] . disabled . set ( true ) ;
120
-
83
+ ( navigation . inputs . skipDisabled as WritableSignalLike < boolean > ) . set ( false ) ;
121
84
typeahead . search ( 'i' ) ;
122
- expect ( activeIndex ( ) ) . toBe ( 1 ) ;
85
+ expect ( navigation . inputs . activeIndex ( ) ) . toBe ( 1 ) ;
123
86
} ) ;
124
87
125
88
it ( 'should ignore keys like shift' , ( ) => {
126
- const items = getItems ( 5 ) ;
127
- const activeIndex = signal ( 0 ) ;
128
- const navigation = new ListNavigation ( {
129
- items,
130
- activeIndex,
131
- wrap : signal ( false ) ,
132
- skipDisabled : signal ( false ) ,
133
- textDirection : signal ( 'ltr' ) ,
134
- orientation : signal ( 'vertical' ) ,
135
- } ) ;
136
- const typeahead = new ListTypeahead ( {
137
- navigation,
138
- typeaheadDelay : signal ( 0.5 ) ,
139
- } ) ;
140
-
141
89
typeahead . search ( 'i' ) ;
142
90
typeahead . search ( 't' ) ;
143
91
typeahead . search ( 'e' ) ;
@@ -147,7 +95,18 @@ describe('List Typeahead', () => {
147
95
typeahead . search ( 'm' ) ;
148
96
typeahead . search ( ' ' ) ;
149
97
typeahead . search ( '2' ) ;
150
- expect ( activeIndex ( ) ) . toBe ( 2 ) ;
98
+ expect ( navigation . inputs . activeIndex ( ) ) . toBe ( 2 ) ;
99
+ } ) ;
100
+
101
+ it ( 'should not allow a query to begin with a space' , ( ) => {
102
+ typeahead . search ( ' ' ) ;
103
+ typeahead . search ( 'i' ) ;
104
+ typeahead . search ( 't' ) ;
105
+ typeahead . search ( 'e' ) ;
106
+ typeahead . search ( 'm' ) ;
107
+ typeahead . search ( ' ' ) ;
108
+ typeahead . search ( '3' ) ;
109
+ expect ( navigation . inputs . activeIndex ( ) ) . toBe ( 3 ) ;
151
110
} ) ;
152
111
} ) ;
153
112
} ) ;
0 commit comments