From 50af681f47745806a657b6c406885b9ced9e67c4 Mon Sep 17 00:00:00 2001 From: George Gevoian Date: Mon, 29 Apr 2024 17:05:07 -0400 Subject: [PATCH] (core) Use correct empty value in ChoiceEditor.getCellValue Summary: The default value of Choice columns is empty string, but ChoiceEditor was saving nulls whenever a blank value was saved. This was causing unexpected updates to trigger values due to the cell value changing internally, even though null and empty string appear the same in the UI. Test Plan: Browser test. Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D4242 --- app/client/widgets/ChoiceEditor.js | 2 +- test/nbrowser/Choice.ts | 54 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/nbrowser/Choice.ts diff --git a/app/client/widgets/ChoiceEditor.js b/app/client/widgets/ChoiceEditor.js index 940c8d53..f01fdbfa 100644 --- a/app/client/widgets/ChoiceEditor.js +++ b/app/client/widgets/ChoiceEditor.js @@ -77,7 +77,7 @@ ChoiceEditor.prototype.getCellValue = function() { if (selectedItem) { return selectedItem.label; } else if (this.textInput.value.trim() === '') { - return null; + return ''; } else { return TextEditor.prototype.getCellValue.call(this); } diff --git a/test/nbrowser/Choice.ts b/test/nbrowser/Choice.ts new file mode 100644 index 00000000..52b68137 --- /dev/null +++ b/test/nbrowser/Choice.ts @@ -0,0 +1,54 @@ +import {DocAPI, UserAPI} from 'app/common/UserAPI'; +import {assert, Key} from 'mocha-webdriver'; +import * as gu from 'test/nbrowser/gristUtils'; +import {setupTestSuite} from 'test/nbrowser/testUtils'; + +describe('Choice', function() { + this.timeout(20000); + const cleanup = setupTestSuite(); + + let docId: string; + let api: UserAPI; + let docApi: DocAPI; + + before(async () => { + const session = await gu.session().teamSite.login(); + docId = await session.tempNewDoc(cleanup, 'Choice'); + api = session.createHomeApi(); + docApi = api.getDocAPI(docId); + }); + + afterEach(() => gu.checkForErrors()); + + it('should set cell value to empty string when editor text is blank', async () => { + // Add a few records to Table1. + await api.applyUserActions(docId, [ + ['BulkAddRecord', 'Table1', [null, null, null], {}], + ]); + + // Change column A's type to Choice and check its values default to empty string. + await api.applyUserActions(docId, [ + ['ModifyColumn', 'Table1', 'A', { + type: 'Choice', + }], + ]); + assert.deepEqual(await docApi.getRecords('Table1'), [ + {id: 1, fields: {A: '', C: null, B: null}}, + {id: 2, fields: {A: '', C: null, B: null}}, + {id: 3, fields: {A: '', C: null, B: null}}, + ]); + + // Start editing a cell in column A and click away to close the editor. + await gu.getCell({rowNum: 1, col: 'A'}).click(); + await gu.sendKeys(Key.ENTER); + await gu.getCell({rowNum: 1, col: 'C'}).click(); + await gu.waitForServer(); + + // Check that the values in column A are unchanged. + assert.deepEqual(await docApi.getRecords('Table1'), [ + {id: 1, fields: {A: '', C: null, B: null}}, + {id: 2, fields: {A: '', C: null, B: null}}, + {id: 3, fields: {A: '', C: null, B: null}}, + ]); + }); +});