gristlabs_grist-core/test/nbrowser/RowMenu.ts
George Gevoian acc218398d (core) Fix hidden columns bug when editing data selection
Summary:
Editing data selection would sometimes cause columns to be hidden in the updated view. A
missing conditional was the culprit: generally, field visibility shouldn't be modified after the view is
updated, but we make an exception for charts to keep certain fields visible or hidden between
updates, so that chart configuration doesn't change too significantly and cause unexpected
data to be displayed. This special behavior for charts was erroneously being applied to non-charts
as well.

Also, when no columns were visible in a view, opening the row menu would cause an error to be
thrown. A loop was inadvertently using null control variables - an explicit check for non-null loop
variables was added, which skips the loop when no columns are visible.

Test Plan: Browser tests.

Reviewers: jarek

Reviewed By: jarek

Subscribers: jarek

Differential Revision: https://phab.getgrist.com/D3650
2022-10-18 08:36:11 -07:00

83 lines
3.1 KiB
TypeScript

import * as gu from 'test/nbrowser/gristUtils';
import { setupTestSuite } from 'test/nbrowser/testUtils';
import { assert, driver, Key, WebElement } from 'mocha-webdriver';
describe('RowMenu', function() {
this.timeout(20000);
const cleanup = setupTestSuite();
async function rightClick(el: WebElement) {
await driver.withActions((actions) => actions.contextClick(el));
}
async function assertRowMenuOpensAndCloses() {
const firstRow = await gu.getRow(1);
// make sure that toggle is there
assert.isTrue(await firstRow.find(".test-row-menu-trigger").isPresent());
// but is hidden
assert.isFalse(await firstRow.find(".test-row-menu-trigger").isDisplayed());
// hover the row
await firstRow.mouseMove();
// make sure toggle is visible
assert.isTrue(await firstRow.find(".test-row-menu-trigger").isDisplayed());
// make sure that clicking on it opens up the menu
await firstRow.find(".test-row-menu-trigger").click();
assert.isTrue(await driver.findWait('.grist-floating-menu', 1000).isDisplayed());
// close the menu
await driver.sendKeys(Key.ESCAPE);
// make sure the menu is closed
assert.lengthOf(await driver.findAll('.grist-floating-menu'), 0);
}
async function assertRowMenuOpensWithRightClick() {
const firstRow = await gu.getRow(1);
// make sure right click opens up the menu
const toggle = await firstRow.find(".test-row-menu-trigger");
await rightClick(toggle);
assert.isTrue(await driver.findWait('.grist-floating-menu', 1000).isDisplayed());
// close the menu by clicking the toggle
await toggle.click();
// make sure the menu is closed
assert.lengthOf(await driver.findAll('.grist-floating-menu'), 0);
}
before(async () => {
const session = await gu.session().login();
await session.tempDoc(cleanup, "CardView.grist");
});
it('should show row toggle', async function() {
await assertRowMenuOpensAndCloses();
await assertRowMenuOpensWithRightClick();
});
it('should hide row toggle when mouse moves away', async function() {
const [firstRow, secondRow] = [await gu.getRow(1), await gu.getRow(2)];
await secondRow.mouseMove();
assert.isTrue(await firstRow.find(".test-row-menu-trigger").isPresent());
assert.isFalse(await firstRow.find(".test-row-menu-trigger").isDisplayed());
});
it('should support right click anywhere on the row', async function() {
// rigth click a cell in a row
await rightClick(await gu.getCell(0, 1));
// check that the context menu shows
assert.isTrue(await driver.findWait('.grist-floating-menu', 1000).isDisplayed());
// send ESC to close the menu
await driver.sendKeys(Key.ESCAPE);
// check that the context menu is gone
assert.isFalse(await driver.find('.grist-floating-menu').isPresent());
});
it('should work even when no columns are visible', async function() {
// Previously, a bug would cause an error to be thrown instead.
await gu.openColumnMenu('A', 'Hide column');
await gu.openColumnMenu('B', 'Hide column');
await assertRowMenuOpensAndCloses();
await assertRowMenuOpensWithRightClick();
});
});