Skip to content

Commit d4441ec

Browse files
committed
(kb) first try at updating tests
- sometimes when we want to return on the "app focus", it won't mean the clipboard element anymore - normalize all the waitAppFocus() and waitAppFocus(true) calls to find them quicker in the codebase when doing searches
1 parent 44db7cf commit d4441ec

12 files changed

+28
-22
lines changed

test/nbrowser/AccessRules1.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ describe('AccessRules1', function() {
451451
"Add Widget to Page",
452452
]);
453453
await driver.sendKeys(Key.ESCAPE);
454-
await gu.waitAppFocus();
454+
await gu.waitForFocus('body');
455455
});
456456

457457
it('should support dollar syntax in the editor', async function() {

test/nbrowser/CellColor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ describe('CellColor', function() {
305305
// Empty cell to clear error from converting toggle to date
306306
await cell.click();
307307
await driver.sendKeys(Key.DELETE);
308-
await gu.waitAppFocus(true);
308+
await gu.waitAppFocus();
309309

310310
const clip = cell.find('.field_clip');
311311

test/nbrowser/ChoiceList.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ describe('ChoiceList', function() {
771771
it('should save and close the choice config editor on focusout', async function() {
772772
// Click outside of the editor.
773773
await driver.find('.test-gristdoc').click();
774-
await gu.waitAppFocus(true);
774+
await gu.waitAppFocus();
775775

776776
// Check that the changes were saved.
777777
assert.deepEqual(await getChoiceLabels(), ['Choice 1', 'Choice 2', 'Choice 3']);

test/nbrowser/ColumnFilterMenu.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ describe('ColumnFilterMenu', function() {
523523
// set min to '2019-07-16'
524524
await gu.setRangeFilterBound('min', '2019-07-16');
525525
await driver.find('.test-filter-menu-apply-btn').click();
526-
await gu.waitAppFocus(true);
526+
await gu.waitAppFocus();
527527

528528
// check values
529529
assert.deepEqual(
@@ -541,7 +541,7 @@ describe('ColumnFilterMenu', function() {
541541
// set max to '2019-07-17'
542542
await gu.setRangeFilterBound('max', '2019-07-17');
543543
await driver.find('.test-filter-menu-apply-btn').click();
544-
await gu.waitAppFocus(true);
544+
await gu.waitAppFocus();
545545

546546
assert.deepEqual(
547547
await gu.getVisibleGridCells({cols: ['Name', colId], rowNums: [1, 2, 3, 4]}),
@@ -557,7 +557,7 @@ describe('ColumnFilterMenu', function() {
557557
await gu.setRangeFilterBound('min', null);
558558
await gu.setRangeFilterBound('max', null);
559559
await driver.find('.test-filter-menu-apply-btn').click();
560-
await gu.waitAppFocus(true);
560+
await gu.waitAppFocus();
561561

562562
// check all values are there
563563
assert.deepEqual(

test/nbrowser/ColumnOps.ntest.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('ColumnOps.ntest', function() {
3030
await gu.waitForServer();
3131
await gu.userActionsVerify([]);
3232
await gu.userActionsCollect(false);
33-
await gu.waitAppFocus(true);
33+
await gu.waitAppFocus();
3434
await shouldHaveColumnHeader('A');
3535
await assert.isPresent(gu.getOpenEditingLabel(gu.getColumnHeader('A')), false);
3636

@@ -53,7 +53,7 @@ describe('ColumnOps.ntest', function() {
5353
["AddRecord", "_grist_Views_section_field", null,
5454
{"colRef":43, "parentId":4, "parentPos":null}]]);
5555
await gu.userActionsCollect(false);
56-
await gu.waitAppFocus(true);
56+
await gu.waitAppFocus();
5757
await shouldHaveColumnHeader('A');
5858
await assert.isPresent(gu.getOpenEditingLabel(gu.getColumnHeader('A')), false);
5959
assert.deepEqual(await gu.getGridLabels('City'),
@@ -102,7 +102,7 @@ describe('ColumnOps.ntest', function() {
102102
await gu.waitToPass(() => gu.getColumnHeader('B'));
103103
await gu.getOpenEditingLabel(await gu.getColumnHeader('B')).wait().sendKeys($.ENTER);
104104
await gu.waitForServer();
105-
await gu.waitAppFocus(true);
105+
await gu.waitAppFocus();
106106
await shouldHaveColumnHeader('B');
107107
});
108108

@@ -169,7 +169,7 @@ describe('ColumnOps.ntest', function() {
169169
await gu.userActionsVerify([]);
170170
await gu.userActionsCollect(false);
171171
await assert.isPresent(gu.getOpenEditingLabel(gu.getColumnHeader('foo')), false);
172-
await gu.waitAppFocus(true);
172+
await gu.waitAppFocus();
173173

174174
// Bug T384: Should save the column name after cancelling a rename earlier.
175175
await shouldHaveColumnHeader('A');

test/nbrowser/Dates.ntest.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ describe('Dates.ntest', function() {
179179
await gu.sendKeys($.DELETE);
180180
await gu.waitForServer();
181181
await gu.getCellRC(0, 2).click();
182-
await gu.waitAppFocus(true);
182+
await gu.waitAppFocus();
183183
await gu.sendKeys('=');
184184
await $('.test-editor-tooltip-convert').click();
185185
await gu.sendKeys('$A', $.ENTER);
186186
await gu.waitForServer();
187-
await gu.waitAppFocus(true);
187+
await gu.waitAppFocus();
188188
await gu.getCellRC(0, 3).click();
189189
await gu.sendKeys('=');
190190
await gu.waitAppFocus(false);

test/nbrowser/Formulas.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ return [
270270
await driver.sendKeys(Key.ENTER);
271271
await driver.findContentWait('.ace_content', /^MEDIAN\($/, 1000);
272272
await driver.sendKeys(Key.ESCAPE);
273-
await gu.waitAppFocus(true);
273+
await gu.waitAppFocus();
274274

275275
// Check that this works also for table names ("fri" finds "Friends")
276276
await driver.sendKeys('=');
@@ -301,7 +301,7 @@ return [
301301
await driver.sendKeys(Key.DOWN, Key.DOWN, Key.ENTER);
302302
await driver.findContentWait('.ace_content', /^Friends\.lookupOne\($/, 1000);
303303
await driver.sendKeys(Key.ESCAPE, Key.ESCAPE);
304-
await gu.waitAppFocus(true);
304+
await gu.waitAppFocus();
305305

306306
// Check that some built-in values are recognized in lowercase.
307307
async function testBuiltin(typedText: string, expectedCompletion: string) {
@@ -311,7 +311,7 @@ return [
311311
await gu.waitToPass(async () =>
312312
assert.include(await driver.findAll('.ace_autocomplete .ace_line', el => el.getText()), expectedCompletion));
313313
await driver.sendKeys(Key.ESCAPE, Key.ESCAPE);
314-
await gu.waitAppFocus(true);
314+
await gu.waitAppFocus();
315315
}
316316
await testBuiltin('tr', 'Tr\nue\n ');
317317
await testBuiltin('fa', 'Fa\nlse\n ');
@@ -349,7 +349,7 @@ return [
349349
await driver.findContent('.ace_autocomplete .ace_line span', /value/).click();
350350
await driver.findContentWait('.ace_content', /^MEDIAN\($/, 1000);
351351
await driver.sendKeys(Key.ESCAPE);
352-
await gu.waitAppFocus(true);
352+
await gu.waitAppFocus();
353353

354354
// Check that this works also for table names ("fri" finds "Friends")
355355
await driver.sendKeys('=');
@@ -391,6 +391,6 @@ return [
391391
await driver.findContent('.ace_autocomplete .ace_line', /lookupRecords/).findContent('span', /Friends/).click();
392392
await driver.findContentWait('.ace_content', /^Friends\.lookupRecords\($/, 1000);
393393
await driver.sendKeys(Key.ESCAPE, Key.ESCAPE);
394-
await gu.waitAppFocus(true);
394+
await gu.waitAppFocus();
395395
});
396396
});

test/nbrowser/NumericEditor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('NumericEditor', function() {
140140
// separator would open with a "." decimal separator, and get saved back incorrectly).
141141
await gu.sendKeys(Key.ENTER);
142142
await gu.waitForServer();
143-
await gu.waitAppFocus(true);
143+
await gu.waitAppFocus();
144144
assert.equal(await gu.getCell({rowNum: 1, col: Number(i)}).getText(), entry.expect);
145145
}
146146
});

test/nbrowser/TextEditor.ntest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('TextEditor.ntest', function() {
111111
await autoCompleteSelect({input: 'foobar3', keys: [$.UP]});
112112
await gu.sendKeys($.ESCAPE);
113113
await gu.waitForServer();
114-
await gu.waitAppFocus(true);
114+
await gu.waitAppFocus();
115115
await $(".viewsection_title:contains(TABLE1)").click();
116116
assert.equal(await gu.getCellRC(6, 0).text(), "");
117117

test/nbrowser/TypeChange.ntest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('TypeChange.ntest', function() {
148148
// Change type to reference column
149149
await gu.actions.viewSection('Table1').selectSection();
150150
await gu.getCellRC(0, 3).click();
151-
await gu.waitAppFocus(true);
151+
await gu.waitAppFocus();
152152
await gu.sendKeys('blue', $.ENTER);
153153
await gu.getCellRC(1, 3).click();
154154
await gu.sendKeys('green', $.ENTER);

test/nbrowser/gristUtil-nbrowser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ const gu = {
373373
await driver.sleep(1000);
374374
// For each value, type it, followed by Tab.
375375
for (const [i, value] of values.entries()) {
376-
await gu.waitAppFocus(true);
376+
await gu.waitAppFocus();
377377
await gu.sendKeys(value, $.TAB);
378378
await gu.waitForServer();
379379
if (i === 0) {

test/nbrowser/gristUtils.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,6 @@ export async function docMenuImport(filePath: string) {
11241124
});
11251125
}
11261126

1127-
11281127
/**
11291128
* Wait for the focus to return to the main application, i.e. the special .copypaste element that
11301129
* normally has it (as opposed to an open cell editor, or a focus in some input or menu). Specify
@@ -1134,6 +1133,13 @@ export async function waitAppFocus(yesNo: boolean = true): Promise<void> {
11341133
await driver.wait(async () => (await driver.find('.copypaste').hasFocus()) === yesNo, 5000);
11351134
}
11361135

1136+
/**
1137+
* Wait for the focus to be on the first element matching given selector.
1138+
*/
1139+
export async function waitForFocus(selector: string): Promise<void> {
1140+
await driver.wait(async () => (await driver.find(selector).hasFocus()), 1000);
1141+
}
1142+
11371143
export async function waitForLabelInput(): Promise<void> {
11381144
await driver.wait(async () => (await driver.findWait('.test-column-title-label', 100).hasFocus()), 300);
11391145
}

0 commit comments

Comments
 (0)