@@ -95,6 +95,50 @@ describe('Kanban view store', () => {
9595 expect ( store . state . kanban . stacks [ '1' ] . results [ 2 ] . id ) . toBe ( 11 )
9696 } )
9797
98+ test ( 'createdNewRow respects view sortings when placing the new row' , async ( ) => {
99+ // Stack '1' has 2 loaded rows out of 100. Rows are sorted by a number
100+ // field (field_2) ascending. The new row's field_2 value (10) falls
101+ // between the two loaded rows (5 and 15), so it must be inserted at
102+ // index 1, not appended to the end.
103+ const stacks = {
104+ null : { count : 0 , results : [ ] } ,
105+ 1 : {
106+ count : 100 ,
107+ results : [
108+ { id : 10 , order : '1.00' , field_1 : { id : 1 } , field_2 : 5 } ,
109+ { id : 11 , order : '2.00' , field_1 : { id : 1 } , field_2 : 15 } ,
110+ ] ,
111+ } ,
112+ }
113+ const state = Object . assign ( kanbanStore . state ( ) , {
114+ singleSelectFieldId : 1 ,
115+ stacks,
116+ } )
117+ store . replaceState ( { ...store . state , kanban : state } )
118+
119+ const fields = [ { id : 2 , type : 'number' , number_decimal_places : 0 } ]
120+ const sortedView = {
121+ filters : [ ] ,
122+ filters_disabled : false ,
123+ sortings : [ { field : 2 , order : 'ASC' , type : 'default' } ] ,
124+ }
125+
126+ // New row has order '3.00' (which would place it last without sortings),
127+ // but field_2=10 which is between 5 and 15, so with sortings it must land
128+ // at index 1.
129+ await store . dispatch ( 'kanban/createdNewRow' , {
130+ view : sortedView ,
131+ values : { id : 9 , order : '3.00' , field_1 : { id : 1 } , field_2 : 10 } ,
132+ fields,
133+ } )
134+
135+ expect ( store . state . kanban . stacks [ '1' ] . count ) . toBe ( 101 )
136+ expect ( store . state . kanban . stacks [ '1' ] . results . length ) . toBe ( 3 )
137+ expect ( store . state . kanban . stacks [ '1' ] . results [ 0 ] . id ) . toBe ( 10 )
138+ expect ( store . state . kanban . stacks [ '1' ] . results [ 1 ] . id ) . toBe ( 9 )
139+ expect ( store . state . kanban . stacks [ '1' ] . results [ 2 ] . id ) . toBe ( 11 )
140+ } )
141+
98142 test ( 'deletedExistingRow' , async ( ) => {
99143 const stacks = { }
100144 stacks . null = {
0 commit comments