6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
- import { Signal , WritableSignal , signal } from '@angular/core' ;
9
+ import { WritableSignal , signal } from '@angular/core' ;
10
10
import { ListExpansion , ListExpansionInputs , ExpansionItem } from './expansion' ;
11
- import { ListFocus , ListFocusInputs , ListFocusItem } from '../list-focus/list-focus' ;
12
- import { getListFocus as getListFocusManager } from '../list-focus/list-focus.spec' ;
13
-
14
- type TestItem = ListFocusItem &
15
- ExpansionItem & {
16
- id : WritableSignal < string > ;
17
- disabled : WritableSignal < boolean > ;
18
- element : WritableSignal < HTMLElement > ;
19
- expandable : WritableSignal < boolean > ;
20
- expansionId : WritableSignal < string > ;
21
- } ;
22
-
23
- type TestInputs = Partial < Omit < ListExpansionInputs < TestItem > , 'items' | 'focusManager' > > &
24
- Partial <
25
- Pick < ListFocusInputs < TestItem > , 'focusMode' | 'disabled' | 'activeIndex' | 'skipDisabled' >
26
- > & {
27
- numItems ?: number ;
28
- initialExpandedIds ?: string [ ] ;
29
- } ;
11
+
12
+ type TestItem = ExpansionItem & {
13
+ id : WritableSignal < string > ;
14
+ disabled : WritableSignal < boolean > ;
15
+ expandable : WritableSignal < boolean > ;
16
+ expansionId : WritableSignal < string > ;
17
+ } ;
18
+
19
+ type TestInputs = Partial < Omit < ListExpansionInputs , 'items' > > & {
20
+ numItems ?: number ;
21
+ initialExpandedIds ?: string [ ] ;
22
+ expansionDisabled ?: boolean ;
23
+ } ;
30
24
31
25
function createItems ( length : number ) : WritableSignal < TestItem [ ] > {
32
26
return signal (
33
27
Array . from ( { length} ) . map ( ( _ , i ) => {
34
28
const itemId = `item-${ i } ` ;
35
29
return {
36
30
id : signal ( itemId ) ,
37
- element : signal ( document . createElement ( 'div' ) as HTMLElement ) ,
38
31
disabled : signal ( false ) ,
39
32
expandable : signal ( true ) ,
40
33
expansionId : signal ( itemId ) ,
@@ -44,39 +37,24 @@ function createItems(length: number): WritableSignal<TestItem[]> {
44
37
}
45
38
46
39
function getExpansion ( inputs : TestInputs = { } ) : {
47
- expansion : ListExpansion < TestItem > ;
40
+ expansion : ListExpansion ;
48
41
items : TestItem [ ] ;
49
- focusManager : ListFocus < TestItem > ;
50
42
} {
51
43
const numItems = inputs . numItems ?? 3 ;
52
44
const items = createItems ( numItems ) ;
53
45
54
- const listFocusManagerInputs : Partial < ListFocusInputs < TestItem > > & { items : Signal < TestItem [ ] > } = {
55
- items : items ,
56
- activeIndex : inputs . activeIndex ?? signal ( 0 ) ,
57
- disabled : inputs . disabled ?? signal ( false ) ,
58
- skipDisabled : inputs . skipDisabled ?? signal ( true ) ,
59
- focusMode : inputs . focusMode ?? signal ( 'roving' ) ,
60
- } ;
61
-
62
- const focusManager = getListFocusManager ( listFocusManagerInputs as any ) as ListFocus < TestItem > ;
63
-
64
- const expansion = new ListExpansion < TestItem > ( {
46
+ const expansion = new ListExpansion ( {
65
47
items : items ,
66
- activeIndex : focusManager . inputs . activeIndex ,
67
- disabled : focusManager . inputs . disabled ,
68
- skipDisabled : focusManager . inputs . skipDisabled ,
69
- focusMode : focusManager . inputs . focusMode ,
70
- multiExpandable : inputs . multiExpandable ?? signal ( false ) ,
71
- expandedIds : signal ( [ ] ) ,
72
- focusManager,
48
+ disabled : signal ( inputs . expansionDisabled ?? false ) ,
49
+ multiExpandable : signal ( inputs . multiExpandable ?.( ) ?? false ) ,
50
+ expandedIds : signal < string [ ] > ( [ ] ) ,
73
51
} ) ;
74
52
75
53
if ( inputs . initialExpandedIds ) {
76
54
expansion . expandedIds . set ( inputs . initialExpandedIds ) ;
77
55
}
78
56
79
- return { expansion, items : items ( ) , focusManager } ;
57
+ return { expansion, items : items ( ) } ;
80
58
}
81
59
82
60
describe ( 'Expansion' , ( ) => {
@@ -112,8 +90,8 @@ describe('Expansion', () => {
112
90
expect ( expansion . expandedIds ( ) ) . toEqual ( [ ] ) ;
113
91
} ) ;
114
92
115
- it ( 'should not open an item if it is not focusable ( disabled and skipDisabled is true) ' , ( ) => {
116
- const { expansion, items} = getExpansion ( { skipDisabled : signal ( true ) } ) ;
93
+ it ( 'should not open an item if it is disabled' , ( ) => {
94
+ const { expansion, items} = getExpansion ( ) ;
117
95
items [ 1 ] . disabled . set ( true ) ;
118
96
expansion . open ( items [ 1 ] ) ;
119
97
expect ( expansion . expandedIds ( ) ) . toEqual ( [ ] ) ;
@@ -134,11 +112,8 @@ describe('Expansion', () => {
134
112
expect ( expansion . expandedIds ( ) ) . toEqual ( [ 'item-0' ] ) ;
135
113
} ) ;
136
114
137
- it ( 'should not close an item if it is not focusable (disabled and skipDisabled is true)' , ( ) => {
138
- const { expansion, items} = getExpansion ( {
139
- initialExpandedIds : [ 'item-0' ] ,
140
- skipDisabled : signal ( true ) ,
141
- } ) ;
115
+ it ( 'should not close an item if it is disabled' , ( ) => {
116
+ const { expansion, items} = getExpansion ( { initialExpandedIds : [ 'item-0' ] } ) ;
142
117
items [ 0 ] . disabled . set ( true ) ;
143
118
expansion . close ( items [ 0 ] ) ;
144
119
expect ( expansion . expandedIds ( ) ) . toEqual ( [ 'item-0' ] ) ;
@@ -181,7 +156,7 @@ describe('Expansion', () => {
181
156
expect ( expansion . expandedIds ( ) ) . toEqual ( [ 'item-0' , 'item-2' ] ) ;
182
157
} ) ;
183
158
184
- it ( 'should not expand items that are not focusable ( disabled and skipDisabled is true) ' , ( ) => {
159
+ it ( 'should not expand items that are disabled' , ( ) => {
185
160
const { expansion, items} = getExpansion ( {
186
161
numItems : 3 ,
187
162
multiExpandable : signal ( true ) ,
@@ -222,9 +197,8 @@ describe('Expansion', () => {
222
197
expect ( expansion . expandedIds ( ) ) . toEqual ( [ 'item-1' ] ) ;
223
198
} ) ;
224
199
225
- it ( 'should not close items that are not focusable ( disabled and skipDisabled is true) ' , ( ) => {
200
+ it ( 'should not close items that are disabled' , ( ) => {
226
201
const { expansion, items} = getExpansion ( {
227
- skipDisabled : signal ( true ) ,
228
202
multiExpandable : signal ( true ) ,
229
203
initialExpandedIds : [ 'item-0' , 'item-1' , 'item-2' ] ,
230
204
} ) ;
@@ -235,22 +209,21 @@ describe('Expansion', () => {
235
209
} ) ;
236
210
237
211
describe ( '#isExpandable' , ( ) => {
238
- it ( 'should return true if an item is focusable and expandable is true' , ( ) => {
212
+ it ( 'should return true if an item is not disabled and expandable is true' , ( ) => {
239
213
const { expansion, items} = getExpansion ( ) ;
240
214
items [ 0 ] . expandable . set ( true ) ;
241
215
items [ 0 ] . disabled . set ( false ) ;
242
216
expect ( expansion . isExpandable ( items [ 0 ] ) ) . toBeTrue ( ) ;
243
217
} ) ;
244
218
245
- it ( 'should return false if an item is disabled and skipDisabled is false ' , ( ) => {
246
- const { expansion, items} = getExpansion ( { skipDisabled : signal ( false ) } ) ;
219
+ it ( 'should return false if an item is disabled' , ( ) => {
220
+ const { expansion, items} = getExpansion ( ) ;
247
221
items [ 0 ] . disabled . set ( true ) ;
248
222
expect ( expansion . isExpandable ( items [ 0 ] ) ) . toBeFalse ( ) ;
249
223
} ) ;
250
224
251
- it ( 'should return false if an item is disabled and skipDisabled is true' , ( ) => {
252
- const { expansion, items} = getExpansion ( { skipDisabled : signal ( true ) } ) ;
253
- items [ 0 ] . disabled . set ( true ) ;
225
+ it ( 'should return false if the expansion behavior is disabled' , ( ) => {
226
+ const { expansion, items} = getExpansion ( { expansionDisabled : true } ) ;
254
227
expect ( expansion . isExpandable ( items [ 0 ] ) ) . toBeFalse ( ) ;
255
228
} ) ;
256
229
0 commit comments