You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gristlabs_grist-core/test/nbrowser/DeleteColumnsUndo.ts

34 lines
1.3 KiB

(core) Fix error in sandbox when removing multiple summary source columns Summary: Fixes a very specific bug reported here: https://grist.slack.com/archives/C069RUP71/p1694630242765769 The error occurred when: 1. Removing multiple columns simultaneously 2. Those columns were sources of groupby columns for a summary table (so removing them meant recreating the summary table and thus deleting its columns) 3. There was a display column for one of the columns that got deleted (either directly or indirectly) which was set to be automatically removed since it was no longer needed, but this failed because the column was already deleted as part of earlier table removal. I fixed this by making `apply_auto_removes` remove table records last, so removing the display column wouldn't be a problem. That fixed the original error, but then I noticed that trying to undo the removal could lead to another error (under even more specific circumstances). It's hard to see exactly why, but I can see that just 3 `RemoveColumn` user actions generated over 100 doc actions and corresponding undo actions, hence the difficulty in narrowing the problem down. This is partly because removing a single column would recreate a summary table, only for that table to be immediately replaced again when another column was removed. Making the frontend send a single `[BulkRemoveRecord, _grist_Tables_column, ...] ` leads to a more efficient and sensible process with about half as many doc actions and no undo error. I think this alone would also solve the original error, but the data engine change seems more generally helpful and worth keeping. Test Plan: Added a Python test and an nbrowser test Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D4052
8 months ago
import {assert, driver, Key} from 'mocha-webdriver';
import * as gu from 'test/nbrowser/gristUtils';
import {server, setupTestSuite} from "test/nbrowser/testUtils";
describe('DeleteColumnsUndo', function () {
this.timeout(20000);
setupTestSuite();
before(async function () {
await server.simulateLogin("Chimpy", "chimpy@getgrist.com", 'nasa');
const doc = await gu.importFixturesDoc('chimpy', 'nasa', 'Horizon', 'DeleteColumnsUndo.grist', false);
await driver.get(`${server.getHost()}/o/nasa/doc/${doc.id}/p/2`);
await gu.waitForDocToLoad();
});
it('should be able to delete multiple columns and undo without errors', async function () {
const revert = await gu.begin();
assert.deepEqual(await gu.getColumnNames(), ['A', 'B', 'C', 'D']);
await gu.getColumnHeader({col: 'A'}).click();
await gu.sendKeys(Key.chord(Key.SHIFT, Key.RIGHT));
await gu.sendKeys(Key.chord(Key.SHIFT, Key.RIGHT));
const selectedCols = await driver.findAll(".column_name.selected");
assert.lengthOf(selectedCols, 3);
await gu.openColumnMenu('A', 'Delete 3 columns');
await gu.waitForServer();
assert.deepEqual(await gu.getColumnNames(), ['D']);
await revert();
await gu.checkForErrors();
assert.deepEqual(await gu.getColumnNames(), ['A', 'B', 'C', 'D']);
});
});