diff --git a/packages/sheets-formula-ui/src/controllers/__tests__/update-formula.controller.spec.ts b/packages/sheets-formula-ui/src/controllers/__tests__/update-formula.controller.spec.ts index 6d0ea200f9f..7eac187a027 100644 --- a/packages/sheets-formula-ui/src/controllers/__tests__/update-formula.controller.spec.ts +++ b/packages/sheets-formula-ui/src/controllers/__tests__/update-formula.controller.spec.ts @@ -276,10 +276,61 @@ const TEST_WORKBOOK_DATA_DEMO = (): IWorkbookData => ({ }, name: 'Sheet2', }, + sheet3: { + id: 'sheet3', + cellData: { + 0: { + 0: { + v: 1, + t: 2, + }, + 1: { + f: '=A1', + v: 1, + t: 2, + }, + }, + 1: { + 0: { + v: 2, + t: 2, + }, + 1: { + f: '=A2', + si: 'W8Hdfc', + v: 2, + t: 2, + }, + }, + 2: { + 0: { + v: 3, + t: 2, + }, + 1: { + si: 'W8Hdfc', + v: 3, + t: 2, + }, + }, + 3: { + 0: { + v: 4, + t: 2, + }, + 1: { + si: 'W8Hdfc', + v: 4, + t: 2, + }, + }, + }, + name: 'Sheet3', + }, }, locale: LocaleType.ZH_CN, name: '', - sheetOrder: ['sheet1', 'sheet2'], + sheetOrder: ['sheet1', 'sheet2', 'sheet3'], styles: {}, resources: [ { @@ -467,6 +518,44 @@ describe('Test update formula ', () => { expect(valuesRedo).toStrictEqual([[{}, { f: '=SUM(A19)', t: 2, v: 1 }], [{}, { f: '=SUM(A20)', si: 'id1', t: 2, v: 2 }], [{}, { si: 'id1', t: 2, v: 3 }]]); }); + it('Move range, update reference, release si', async () => { + const workbook = get(IUniverInstanceService).getUnit('test'); + const sheet3 = workbook?.getSheetBySheetId('sheet3'); + if (!sheet3) { + throw new Error('sheet3 not found'); + } + workbook?.setActiveSheet(sheet3); + + const params: IMoveRangeCommandParams = { + fromRange: { + startRow: 0, + startColumn: 1, + endRow: 3, + endColumn: 1, + rangeType: 0, + }, + toRange: { + startRow: 2, + startColumn: 1, + endRow: 5, + endColumn: 1, + rangeType: 0, + }, + }; + + expect(await commandService.executeCommand(MoveRangeCommand.id, params)).toBeTruthy(); + const values = getValues(0, 1, 5, 1); + expect(values).toStrictEqual([[{}], [{}], [{ f: '=A1', v: 1 }], [{ f: '=A2', v: 2 }], [{ f: '=A3', v: 3 }], [{ f: '=A4', v: 4 }]]); + + expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy(); + const valuesUndo = getValues(0, 1, 5, 1); + expect(valuesUndo).toStrictEqual([[{ f: '=A1', v: 1 }], [{ f: '=A2', v: 2 }], [{ f: '=A3', v: 3 }], [{ f: '=A4', v: 4 }], [{}], [{}]]); + + expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy(); + const valuesRedo = getValues(0, 1, 5, 1); + expect(valuesRedo).toStrictEqual([[{}], [{}], [{ f: '=A1', v: 1 }], [{ f: '=A2', v: 2 }], [{ f: '=A3', v: 3 }], [{ f: '=A4', v: 4 }]]); + }); + it('Move rows, update reference', async () => { const selectionManager = get(SheetsSelectionsService);