mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
acc218398d
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
163 lines
6.0 KiB
TypeScript
163 lines
6.0 KiB
TypeScript
import { assert, driver, Key } from 'mocha-webdriver';
|
|
import * as gu from 'test/nbrowser/gristUtils';
|
|
import { server, setupTestSuite } from 'test/nbrowser/testUtils';
|
|
|
|
describe("saveViewSection", function() {
|
|
this.timeout(20000);
|
|
setupTestSuite();
|
|
|
|
it("should work correctly when turning a table to 'summary'", async () => {
|
|
// create a new document
|
|
const docId = await gu.createNewDoc('Chimpy', 'nasa', 'Horizon', 'test-updateViewSection');
|
|
|
|
// Login and open document
|
|
await server.simulateLogin('Chimpy', 'chimpy@getgrist.com', 'nasa');
|
|
await driver.get(`${server.getHost()}/o/nasa/doc/${docId}`);
|
|
|
|
// add new section
|
|
await gu.addNewSection(/Table/, /Table1/);
|
|
|
|
// change name and edit data of the 1st section (first found - both have the same name)
|
|
await gu.renameSection('TABLE1', 'Foo');
|
|
|
|
// open right panel
|
|
await gu.toggleSidePanel('right');
|
|
await driver.find('.test-config-data').click();
|
|
|
|
// check there is no groupedBy
|
|
assert.equal(await driver.find('.test-pwc-groupedBy').isDisplayed(), false);
|
|
|
|
// click edit table data
|
|
await driver.find('.test-pwc-editDataSelection').doClick();
|
|
|
|
// summarize table by 'A' and save
|
|
await driver.findContent('.test-wselect-table', /Table1/).find('.test-wselect-pivot').doClick();
|
|
await driver.findContent('.test-wselect-column', /A/).doClick();
|
|
await driver.find('.test-wselect-addBtn').doClick();
|
|
|
|
// wait for server
|
|
await gu.waitForServer();
|
|
|
|
// check that new table is summarized
|
|
assert.equal(await driver.findWait('.test-pwc-table', 2000).getText(), 'Table1');
|
|
assert.deepEqual(await driver.findAll('.test-pwc-groupedBy-col', (e) => e.getText()), ['A']);
|
|
|
|
// check sections name did not change
|
|
assert.deepEqual(await gu.getSectionTitles(), ['Foo', 'TABLE1']);
|
|
|
|
// check 1st section is active
|
|
assert(await driver.find('.viewsection_content').matches('.active_section'));
|
|
});
|
|
|
|
it('should work correctly when changing table', async () => {
|
|
// click edit table data
|
|
await driver.find('.test-pwc-editDataSelection').doClick();
|
|
|
|
// create a new table
|
|
await driver.findContent('.test-wselect-table', /New Table/).doClick();
|
|
await driver.find('.test-wselect-addBtn').doClick();
|
|
|
|
// wait for server
|
|
await gu.waitForServer();
|
|
|
|
// check that first section shows table2 with no grouped by cols
|
|
assert.equal(await driver.findWait('.test-pwc-table', 2000).getText(), 'Table2');
|
|
assert.equal(await driver.find('.test-pwc-groupedBy').isDisplayed(), false);
|
|
|
|
// check sections name did not change
|
|
assert.deepEqual(await gu.getSectionTitles(), ['Foo', 'TABLE1']);
|
|
|
|
// check 1st section is active
|
|
assert(await driver.find('.viewsection_content').matches('.active_section'));
|
|
|
|
// revert to what it was
|
|
await gu.undo();
|
|
});
|
|
|
|
it("should work correctly when changing type", async () => {
|
|
|
|
async function switchTypeAndAssert(t: string) {
|
|
// open page widget picker
|
|
await driver.find('.test-pwc-editDataSelection').doClick();
|
|
|
|
// select type t and save
|
|
await driver.findContent('.test-wselect-type', gu.exactMatch(t)).doClick();
|
|
await driver.find('.test-wselect-addBtn').doClick();
|
|
await gu.waitForServer();
|
|
|
|
// check section's type
|
|
await driver.find('.test-pwc-editDataSelection').doClick();
|
|
assert.equal(await driver.find('.test-wselect-type[class*=-selected]').getText(), t);
|
|
|
|
// close page widget picker
|
|
await driver.sendKeys(Key.ESCAPE);
|
|
await gu.checkForErrors();
|
|
}
|
|
|
|
// TODO: check what's shown by asserting data for each type
|
|
await switchTypeAndAssert('Card');
|
|
await switchTypeAndAssert('Table');
|
|
await switchTypeAndAssert('Chart');
|
|
|
|
});
|
|
|
|
it("should work correctly when changing grouped by column", async () => {
|
|
|
|
// open page widget picker
|
|
await driver.find('.test-pwc-editDataSelection').doClick();
|
|
|
|
// Select column B
|
|
await driver.findContent('.test-wselect-column', /B/).doClick();
|
|
await driver.find('.test-wselect-addBtn').doClick();
|
|
await gu.waitForServer();
|
|
|
|
// check grouped by is now A, B
|
|
assert.deepEqual(await driver.findAll('.test-pwc-groupedBy-col', (e) => e.getText()), ['A', 'B']);
|
|
|
|
await gu.undo();
|
|
});
|
|
|
|
it("should not hide any columns when changing to a summary table", async () => {
|
|
// Previously, a bug when changing data selection would sometimes cause columns to be hidden.
|
|
// This test replicates a scenario that was used to reproduce the bug, and checks that it no
|
|
// longer occurs.
|
|
|
|
async function assertActiveSectionColumns(...expected: string[]) {
|
|
const activeSection = await driver.find('.active_section');
|
|
const actual = (await activeSection.findAll('.column_name', el => el.getText()))
|
|
.filter(name => name !== '+');
|
|
assert.deepEqual(actual, expected);
|
|
}
|
|
|
|
// Create a Places table with a single Place column.
|
|
await gu.addNewTable('Places');
|
|
await gu.renameColumn({col: 0}, 'Place');
|
|
await gu.sendKeys(Key.ARROW_RIGHT);
|
|
await gu.sendKeys(Key.chord(Key.ALT, '-'));
|
|
await gu.waitForServer();
|
|
await gu.sendKeys(Key.chord(Key.ALT, '-'));
|
|
await gu.waitForServer();
|
|
|
|
// Create an Orders table, and rename the last column to Test.
|
|
await gu.addNewTable('Orders');
|
|
await gu.renameColumn({col: 2}, 'Test');
|
|
|
|
// Duplicate the Places page.
|
|
await gu.openPageMenu('Places');
|
|
await driver.find('.test-docpage-duplicate').click();
|
|
await driver.find('.test-modal-confirm').click();
|
|
await driver.findContentWait('.test-docpage-label', /copy/, 1000);
|
|
await gu.waitForServer();
|
|
|
|
// Change the duplicated page's data to summarize Orders, grouping by column Test.
|
|
await driver.find('.test-pwc-editDataSelection').doClick();
|
|
await driver.findContent('.test-wselect-table', /Orders/).find('.test-wselect-pivot').doClick();
|
|
await driver.findContent('.test-wselect-column', /Test/).doClick();
|
|
await driver.find('.test-wselect-addBtn').doClick();
|
|
await gu.waitForServer();
|
|
|
|
// Check all columns are visible.
|
|
await assertActiveSectionColumns('Test', 'count');
|
|
});
|
|
});
|