1
- import { SimpleEvent , ValueContext } from 'sequential-workflow-editor-model' ;
1
+ import { I18n , SimpleEvent , ValueContext } from 'sequential-workflow-editor-model' ;
2
2
import { Html } from '../core/html' ;
3
3
import { dynamicListComponent } from './dynamic-list-component' ;
4
4
5
5
interface TestItem {
6
6
id : number ;
7
7
}
8
8
9
- function testItemComponentFactory ( item : TestItem ) {
9
+ function testItemComponentFactory ( item : TestItem , _ : I18n , index : number ) {
10
+ const view = Html . element ( 'span' , {
11
+ class : `test-item-${ item . id } `
12
+ } ) ;
13
+ view . setAttribute ( 'data-index' , String ( index ) ) ;
10
14
return {
11
- view : Html . element ( 'span' , {
12
- class : `test-item-${ item . id } `
13
- } ) ,
15
+ view,
14
16
onItemChanged : new SimpleEvent < TestItem > ( ) ,
15
17
onDeleteClicked : new SimpleEvent < void > ( ) ,
16
18
validate : ( ) => {
@@ -32,7 +34,9 @@ describe('DynamicListComponent', () => {
32
34
33
35
expect ( children . length ) . toBe ( 3 ) ;
34
36
expect ( children [ 0 ] . className ) . toBe ( 'test-item-123' ) ;
37
+ expect ( children [ 0 ] . getAttribute ( 'data-index' ) ) . toBe ( '0' ) ;
35
38
expect ( children [ 1 ] . className ) . toBe ( 'test-item-456' ) ;
39
+ expect ( children [ 1 ] . getAttribute ( 'data-index' ) ) . toBe ( '1' ) ;
36
40
expect ( children [ 2 ] . className ) . toBe ( 'swe-validation-error' ) ;
37
41
} ) ;
38
42
@@ -47,13 +51,16 @@ describe('DynamicListComponent', () => {
47
51
48
52
expect ( children . length ) . toBe ( 2 ) ;
49
53
expect ( children [ 0 ] . className ) . toBe ( 'test-item-135' ) ;
54
+ expect ( children [ 0 ] . getAttribute ( 'data-index' ) ) . toBe ( '0' ) ;
50
55
expect ( children [ 1 ] . className ) . toBe ( 'swe-validation-error' ) ;
51
56
52
57
component . add ( { id : 246 } ) ;
53
58
54
59
expect ( children . length ) . toBe ( 3 ) ;
55
60
expect ( children [ 0 ] . className ) . toBe ( 'test-item-135' ) ;
61
+ expect ( children [ 0 ] . getAttribute ( 'data-index' ) ) . toBe ( '0' ) ;
56
62
expect ( children [ 1 ] . className ) . toBe ( 'test-item-246' ) ;
63
+ expect ( children [ 1 ] . getAttribute ( 'data-index' ) ) . toBe ( '1' ) ;
57
64
expect ( children [ 2 ] . className ) . toBe ( 'swe-validation-error' ) ;
58
65
} ) ;
59
66
0 commit comments