(core) When a checkbox is clicked on a new record, set default values determined by linking

Summary: Fixes a bug (reported in https://community.getgrist.com/t/bug-toggle-column-in-linking-widget-not-triggering-default-value/1657)

Test Plan: Added a test case that fails without this fix.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3699
This commit is contained in:
Dmitry S
2022-11-10 12:59:24 -05:00
parent 46148aa125
commit 5c67e12aa5
9 changed files with 185 additions and 98 deletions

View File

@@ -686,20 +686,20 @@ describe('MultiColumn', function() {
assert.isFalse(await widgetTypeDisabled());
// Test for mixed format.
await selectColumns('Left');
await widgetType('TextBox');
await gu.setFieldWidgetType('TextBox');
await selectColumns('Right');
await widgetType('CheckBox');
await gu.setFieldWidgetType('CheckBox');
await selectColumns('Left', 'Right');
assert.equal(await widgetType(), 'Mixed format');
assert.equal(await gu.getFieldWidgetType(), 'Mixed format');
// Test that both change when format is changed.
for (const mode of ['TextBox', 'CheckBox', 'Switch']) {
await widgetType(mode);
await gu.setFieldWidgetType(mode);
await selectColumns('Left');
assert.equal(await widgetType(), mode);
assert.equal(await gu.getFieldWidgetType(), mode);
await selectColumns('Right');
assert.equal(await widgetType(), mode);
assert.equal(await gu.getFieldWidgetType(), mode);
await selectColumns('Left', 'Right');
assert.equal(await widgetType(), mode);
assert.equal(await gu.getFieldWidgetType(), mode);
}
} else {
await selectColumns('Left', 'Right');
@@ -1127,15 +1127,6 @@ async function alignment(value?: 'left' | 'right' | 'center') {
}
async function widgetType(type?: string) {
if (!type) {
return await driver.find(".test-fbuilder-widget-select").getText();
}
await driver.find(".test-fbuilder-widget-select").click();
await driver.findContent('.test-select-menu li', gu.exactMatch(type)).click();
await gu.waitForServer();
}
async function dateFormatDisabled() {
const format = await driver.find('[data-test-id=Widget_dateFormat]');
return await format.matches(".disabled");

View File

@@ -0,0 +1,90 @@
import {assert, driver} from 'mocha-webdriver';
import * as gu from 'test/nbrowser/gristUtils';
import {Session} from 'test/nbrowser/gristUtils';
import {setupTestSuite} from 'test/nbrowser/testUtils';
describe('ToggleColumns', function() {
this.timeout(20000);
const cleanup = setupTestSuite({team: true});
let session: Session;
let docId: string;
before(async function() {
session = await gu.session().teamSite.login();
docId = await session.tempNewDoc(cleanup, 'ToggleColumns', {load: false});
// Set up a table Src, and table Items which links to Src and has a boolean column.
const api = session.createHomeApi();
await api.applyUserActions(docId, [
['AddTable', 'Src', [{id: 'A', type: 'Text'}]],
['BulkAddRecord', 'Src', [null, null, null], {A: ['a', 'b', 'c']}],
['AddTable', 'Items', [
{id: 'A', type: 'Ref:Src'},
{id: 'Chk', type: 'Bool'},
// An extra text column reflects the boolean for simpler checking of the values.
{id: 'Chk2', isFormula: true, formula: '$Chk'},
]],
['BulkAddRecord', 'Items', [null, null, null], {A: [1, 1, 3]}],
]);
await session.loadDoc(`/doc/${docId}`);
// Set up a page with linked widgets.
await gu.addNewPage('Table', 'Src');
await gu.addNewSection('Table', 'Items', {selectBy: /Src/i});
});
it('should fill in values determined by linking when checkbox is clicked', async function() {
// Test the behavior with a checkbox.
await verifyToggleBehavior();
});
it('should fill in values determined by linking when switch widget is clicked', async function() {
// Now switch the widget to the "Switch" widget, and test again.
await gu.toggleSidePanel('right', 'open');
await driver.find('.test-right-tab-field').click();
await gu.setFieldWidgetType("Switch");
await verifyToggleBehavior();
});
async function verifyToggleBehavior() {
// Selecting a cell in Src should show only linked values in Items.
await gu.getCell({section: 'Src', col: 'A', rowNum: 1}).click();
assert.deepEqual(await gu.getVisibleGridCells({section: 'Items', cols: ['A', 'Chk2'], rowNums: [1, 2, 3]}), [
'Src[1]', 'false',
'Src[1]', 'false',
'', '',
]);
// Click on the cell in the "Add Row" of Items. Because the checkbox is centered in the cell,
// the click should toggle it.
await gu.getCell({section: 'Items', col: 'Chk', rowNum: 3}).click();
await gu.waitForServer();
// Check that there is a new row, properly linked.
assert.deepEqual(await gu.getVisibleGridCells({section: 'Items', cols: ['A', 'Chk2'], rowNums: [1, 2, 3, 4]}), [
'Src[1]', 'false',
'Src[1]', 'false',
'Src[1]', 'true',
'', '',
]);
// Try another row of table Src. It should have its own Items (initially none).
await gu.getCell({section: 'Src', col: 'A', rowNum: 2}).click();
assert.deepEqual(await gu.getVisibleGridCells({section: 'Items', cols: ['A', 'Chk2'], rowNums: [1]}),
['', '']);
// Click checkbox in "Add Row" of Items again.
await gu.getCell({section: 'Items', col: 'Chk', rowNum: 1}).click();
await gu.waitForServer();
// Check that we see the new row, with the value determined by linking (column 'A') set correctly.
assert.deepEqual(await gu.getVisibleGridCells({section: 'Items', cols: ['A', 'Chk2'], rowNums: [1, 2]}), [
'Src[2]', 'true',
'', '',
]);
await gu.undo(2);
}
});

View File

@@ -1537,6 +1537,22 @@ export async function getType() {
return await driver.find('.test-fbuilder-type-select').getText();
}
/**
* Get the field's widget type (e.g. "CheckBox" for a Toggle column) in the creator panel.
*/
export async function getFieldWidgetType(): Promise<string> {
return await driver.find(".test-fbuilder-widget-select").getText();
}
/**
* Set the field's widget type (e.g. "CheckBox" for a Toggle column) in the creator panel.
*/
export async function setFieldWidgetType(type: string) {
await driver.find(".test-fbuilder-widget-select").click();
await driver.findContent('.test-select-menu li', exactMatch(type)).click();
await waitForServer();
}
export async function applyTypeTransform() {
await driver.findContent('.type_transform_prompt button', /Apply/).click();
}