gristlabs_grist-core/test/nbrowser/CopyWithHeaders.ts
Tim Newsome 755a742d6f
Add Copy With Headers to grid cell popup. (#1208)
* Add "Copy with headers" to grid cell popup.

This is what you want when you're going to paste into e.g. an email.

Tested just by manually trying copy and paste into an editor and an
email, and then again using the new variant to confirm the headers show
up.

https://github.com/gristlabs/grist-core/pull/1208
2024-09-30 11:20:22 +02:00

60 lines
2.0 KiB
TypeScript

/**
* Test for copying Grist data with headers.
*/
import {assert, driver, Key} from 'mocha-webdriver';
import * as gu from 'test/nbrowser/gristUtils';
import {setupTestSuite} from 'test/nbrowser/testUtils';
import {createDummyTextArea, removeDummyTextArea} from 'test/nbrowser/CopyPaste';
describe("CopyWithHeaders", function() {
this.timeout(90000);
const cleanup = setupTestSuite();
const clipboard = gu.getLockableClipboard();
afterEach(() => gu.checkForErrors());
gu.bigScreen();
after(async function() {
await driver.executeScript(removeDummyTextArea);
});
it('should copy headers', async function() {
const session = await gu.session().teamSite.login();
await session.tempDoc(cleanup, 'Hello.grist');
await driver.executeScript(createDummyTextArea);
await clipboard.lockAndPerform(async (cb) => {
// Select all
await gu.sendKeys(Key.chord(Key.CONTROL, 'a'));
await gu.rightClick(gu.getCell({rowNum: 1, col: 'A'}));
await driver.findContent('.grist-floating-menu li', 'Copy with headers').click();
await pasteAndCheck(cb, ["A", "B", "C", "D", "E"], 5);
});
await clipboard.lockAndPerform(async (cb) => {
// Select a single cell.
await gu.getCell({rowNum: 2, col: 'D'}).click();
await gu.rightClick(gu.getCell({rowNum: 2, col: 'D'}));
await driver.findContent('.grist-floating-menu li', 'Copy with headers').click();
await pasteAndCheck(cb, ["D"], 2);
});
});
});
async function pasteAndCheck(cb: gu.IClipboard, headers: string[], rows: number) {
// Paste into the dummy textarea.
await driver.find('#dummyText').click();
await gu.waitAppFocus(false);
await cb.paste();
const textarea = await driver.find('#dummyText');
const text = await textarea.getAttribute('value');
const lines = text.split('\n');
const regex = new RegExp(`^${headers.join('\\s+')}$`);
assert.match(lines[0], regex);
assert.equal(lines.length, rows);
await textarea.clear();
}