(core) Save choice config on focus loss

Summary: Changes to choices are now saved whenever focus leaves the editor.

Test Plan: Browser tests.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3879
This commit is contained in:
George Gevoian
2023-05-08 00:59:44 -04:00
parent ae7d964bf2
commit 9438f315e9
3 changed files with 136 additions and 57 deletions

View File

@@ -666,18 +666,26 @@ describe('ChoiceList', function() {
strikethrough, underline, bold}
]
);
});
// Open the editor again to make another change.
await driver.find('.test-choice-list-entry').click();
await gu.waitAppFocus(false);
it('should discard changes on cancel', async function() {
for (const method of ['button', 'shortcut']) {
// Open the editor.
await driver.find('.test-choice-list-entry').click();
await gu.waitAppFocus(false);
// Delete 'Apricot', then cancel the change by pressing Escape.
await gu.sendKeys(Key.BACK_SPACE);
assert.deepEqual(await getEditModeChoiceLabels(), ['Green', 'Blue', 'Black']);
await gu.sendKeys(Key.ESCAPE);
// Delete 'Apricot', then cancel the change.
await gu.sendKeys(Key.BACK_SPACE);
assert.deepEqual(await getEditModeChoiceLabels(), ['Green', 'Blue', 'Black']);
if (method === 'button') {
await driver.find('.test-choice-list-entry-cancel').click();
} else {
await gu.sendKeys(Key.ESCAPE);
}
// Check that 'Apricot' is still there and the change wasn't saved.
assert.deepEqual(await getChoiceLabels(), ['Green', 'Blue', 'Black', 'Apricot']);
// Check that 'Apricot' is still there and the change wasn't saved.
assert.deepEqual(await getChoiceLabels(), ['Green', 'Blue', 'Black', 'Apricot']);
}
});
it('should support undo/redo shortcuts in the choice config editor', async function() {
@@ -754,6 +762,17 @@ describe('ChoiceList', function() {
// workflow above would copy all the choice data as well, and use it for pasting in the editor.
});
it('should save and close the choice config editor on focusout', async function() {
// Click outside of the editor.
await driver.find('.test-gristdoc').click();
await gu.waitAppFocus(true);
// Check that the changes were saved.
assert.deepEqual(await getChoiceLabels(), ['Choice 1', 'Choice 2', 'Choice 3']);
await gu.undo();
});
it('should add a new element on a fresh ChoiceList column', async function() {
await gu.addColumn("ChoiceList");
await gu.setType(gu.exactMatch("Choice List"));