forked from gristlabs/grist-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3e6d3d
commit 938dd9f
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Test for pasting into a linked GridView. | ||
* | ||
* In particular, when multiple rows are selected in GridView, on switching to a different linked | ||
* record, the selection should be cleared, or else paste will misbehave. | ||
*/ | ||
import {assert, Key, WebElement} from 'mocha-webdriver'; | ||
import * as gu from 'test/nbrowser/gristUtils'; | ||
import {setupTestSuite} from 'test/nbrowser/testUtils'; | ||
|
||
describe('CopyPasteLinked', function() { | ||
this.timeout(30000); | ||
const cleanup = setupTestSuite(); | ||
|
||
it('should clear internal selection when link record changes', async function() { | ||
const mainSession = await gu.session().login(); | ||
await mainSession.tempDoc(cleanup, 'Landlord.grist'); | ||
await gu.getPageItem(/Current Signers/).click(); | ||
await gu.waitForServer(); | ||
|
||
let cell: WebElement; | ||
|
||
// Select a cell. | ||
cell = await gu.getCell({section: 'Tenants', col: 'Tenant', rowNum: 1}); | ||
await cell.click(); | ||
assert.equal(await cell.getText(), 'John Malik'); | ||
|
||
await gu.withSafeClipboard(async (cb) => { | ||
// Copy the cell's value to the clipboard. | ||
await cb.copy(); | ||
|
||
// Now select multiple cells. | ||
await gu.sendKeys(Key.chord(Key.SHIFT, Key.DOWN), Key.chord(Key.SHIFT, Key.DOWN)); | ||
|
||
// Check that 3 cells are indeed selected. | ||
assert.deepEqual(await gu.getVisibleGridCells({col: 'Tenant', rowNums: [1, 2, 3, 4], | ||
mapper: (el) => el.matches('.selected')}), | ||
[true, true, true, false]); | ||
|
||
// Switch to a different Apartments row that drives the filtering in the Tenants section. | ||
await gu.getCell({section: 'Apartments', col: 0, rowNum: 2}).click(); | ||
cell = await gu.getCell({section: 'Tenants', col: 'Tenant', rowNum: 1}); | ||
await cell.click(); | ||
assert.equal(await cell.getText(), 'Fred Brown'); | ||
|
||
// Paste the copied value. It doesn't work reliably in a test, so try until it works. (The | ||
// reasons seems to be that 'body' has focus briefly, rather than Clipboard component.) | ||
await gu.waitAppFocus(); | ||
await cb.paste(); | ||
}); | ||
await gu.waitForServer(); | ||
|
||
// Check that only one value was copied, and that there are not multiple cells selected. | ||
assert.deepEqual(await gu.getVisibleGridCells({col: 'Tenant', rowNums: [1, 2, 3, 4]}), | ||
['John Malik', 'Fred Brown', 'Susan Sharp', 'Owen Sharp']); | ||
assert.deepEqual(await gu.getVisibleGridCells({col: 'Tenant', rowNums: [1, 2, 3, 4], | ||
mapper: (el) => el.matches('.selected')}), | ||
[false, false, false, false]); | ||
|
||
await gu.checkForErrors(); | ||
await gu.undo(); | ||
}); | ||
}); |