Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests broken due to widget gallery changes #144

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions test/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ describe('chart', function () {
await chooseColumnFromFieldDropdown(/Values/, /num/);
await chooseColumnFromFieldDropdown(/Labels/, /choice list/);

assert.equal(
await driver.find('.plotly_editor_plot').getText(),
const result =
// Percentages inside the pie chart
'55.6%\n44.4%\n' +
// Legend
'choice B\nchoice A',
'choice B\nchoice A';

assert.equal(
await driver.findContentWait('.plotly_editor_plot', result, 2000).getText(),
result
);
});
});
Expand Down
11 changes: 6 additions & 5 deletions test/getGrist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ChildProcess, execSync, spawn} from 'child_process';
import FormData from 'form-data';
import fs from 'fs';
import {driver} from 'mocha-webdriver';
import { driver, enableDebugCapture } from 'mocha-webdriver';
import fetch from 'node-fetch';

import {GristWebDriverUtils} from 'test/gristWebDriverUtils';
Expand All @@ -17,6 +17,8 @@ export function getGrist(): GristUtils {
const server = new GristTestServer();
const grist = new GristUtils(server);

enableDebugCapture()
Spoffy marked this conversation as resolved.
Show resolved Hide resolved

before(async function () {
// Server will have started up in a global fixture, we just
// need to make sure it is ready.
Expand Down Expand Up @@ -198,17 +200,16 @@ export class GristUtils extends GristWebDriverUtils {
await this.waitForServer();
}



public async clickWidgetPane() {
const elem = this.driver.find('.test-config-widget-select .test-select-open');
const elem = this.driver.find('.test-custom-widget-gallery-container');
if (await elem.isPresent()) {
await elem.click();
}
}

public async selectCustomWidget(text: string | RegExp) {
await this.driver.findContent('.test-select-menu li', text).click();
await this.driver.findContent('.test-custom-widget-gallery-widget', text).click();
await this.driver.find('.test-custom-widget-gallery-save').click();
await this.waitForServer();
}

Expand Down
22 changes: 19 additions & 3 deletions test/gristWebDriverUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ import escapeRegExp = require('lodash/escapeRegExp');
type SectionTypes = 'Table' | 'Card' | 'Card List' | 'Chart' | 'Custom';
type UserAction = Array<string | number | object | boolean | null | undefined>;

export async function ignoreMissingElementErrors<T>(callback: () => T): Promise<T | undefined> {
try {
return await callback()
} catch (e) {
if (e.name === 'NoSuchElementError' || e.name === 'StaleElementReferenceError') {
return;
}
throw e;
}
}

export class GristWebDriverUtils {
public constructor(public driver: WebDriver) {
}
Expand Down Expand Up @@ -145,7 +156,9 @@ export class GristWebDriverUtils {
if (options.dismissTips) { await this.dismissBehavioralPrompts(); }

if (tableRe) {
const tableEl = driver.findContent('.test-wselect-table', tableRe);
const tableEl = driver.findContentWait('.test-wselect-table', tableRe, 2000);

if (options.dismissTips) { await this.dismissBehavioralPrompts(); }

// unselect all selected columns
for (const col of (await driver.findAll('.test-wselect-column[class*=-selected]'))) {
Expand Down Expand Up @@ -210,8 +223,11 @@ export class GristWebDriverUtils {
const max = 10;

// Keep dismissing prompts until there are no more, up to a maximum of 10 times.
while (i < max && await this.driver.find('.test-behavioral-prompt').isPresent()) {
await this.driver.find('.test-behavioral-prompt-dismiss').click();
const getButton = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that this change isn't of much benefit, and my preference would be to keep it unchanged, since it's a copy of code from grist-core (which is much more exercised and reliable). For the same reason, ignoreMissingElementErrors doesn't seem needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rolled this back - totally agree it doesn't make sense making these changes, if we haven't updated gristWebDriverUtils.

return this.driver.find('.test-behavioral-prompt-dismiss')
}
while (i < max && await getButton().isPresent()) {
await ignoreMissingElementErrors(() => getButton().click());
await this.waitForServer();
i += 1;
}
Expand Down
2 changes: 1 addition & 1 deletion test/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('inspect', function() {
await grist.toggleSidePanel('right', 'open');
await grist.addNewSection(/Custom/, /School/, {dismissTips: true});
await grist.clickWidgetPane();
await grist.selectCustomWidget('Inspect Record');
await grist.selectCustomWidget('Inspect record');
await grist.setCustomWidgetAccess('full');
await grist.waitToPass(async () => {
const txt = await grist.getCustomWidgetBody();
Expand Down
Loading