Skip to content

Commit

Permalink
openFileQuickAccessAndWait improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
midleman committed Dec 17, 2024
1 parent 90fdbdf commit f3c9328
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class PositronUserSettingsFixtures {
]);

// Close the settings editor
await this.app.workbench.quickaccess.runCommand('workbench.action.closeActiveEditor');
await this.app.workbench.positronQuickaccess.runCommand('workbench.action.closeActiveEditor');

// Restart the application if requested, to apply the settings
if (restartApp) {
Expand Down
125 changes: 44 additions & 81 deletions test/automation/src/positron/positronQuickaccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,97 +35,60 @@ export class PositronQuickAccess {
await this.quickInput.selectQuickInputElement(0);
}



async openFileQuickAccessAndWait(searchValue: string, expectedFirstElementNameOrExpectedResultCount: string | number): Promise<void> {

// make sure the file quick access is not "polluted"
// with entries from the editor history when opening
async openFileQuickAccessAndWait(
searchValue: string,
expectedFirstElementNameOrExpectedResultCount: string | number
): Promise<void> {
// Clear editor history to ensure Quick Access is not "polluted"
await this.runCommand('workbench.action.clearEditorHistory');

const PollingStrategy = {
Stop: true,
Continue: false
};

let retries = 0;
let success = false;

while (++retries < 10) {
let retry = false;

try {
await this.openQuickAccessWithRetry(QuickAccessKind.Files, searchValue);
await this.quickInput.waitForQuickInputElements(elementNames => {
this.code.logger.log('QuickAccess: resulting elements: ', elementNames);

// Quick access seems to be still running -> retry
if (elementNames.length === 0) {
this.code.logger.log('QuickAccess: file search returned 0 elements, will continue polling...');

return PollingStrategy.Continue;
}

// Quick access does not seem healthy/ready -> retry
const firstElementName = elementNames[0];
if (firstElementName === 'No matching results') {
this.code.logger.log(`QuickAccess: file search returned "No matching results", will retry...`);

retry = true;

return PollingStrategy.Stop;
}

// Expected: number of results
if (typeof expectedFirstElementNameOrExpectedResultCount === 'number') {
if (elementNames.length === expectedFirstElementNameOrExpectedResultCount) {
success = true;

return PollingStrategy.Stop;
}

this.code.logger.log(`QuickAccess: file search returned ${elementNames.length} results but was expecting ${expectedFirstElementNameOrExpectedResultCount}, will retry...`);

retry = true;
await expect(async () => {
// Open Quick Access and wait for the elements to appear
await this.openQuickAccessWithRetry(QuickAccessKind.Files, searchValue);

return PollingStrategy.Stop;
}

// Expected: string
else {
if (firstElementName === expectedFirstElementNameOrExpectedResultCount) {
success = true;
await this.quickInput.waitForQuickInputElements((elementNames) => {
this.code.logger.log('QuickAccess: resulting elements:', elementNames);

return PollingStrategy.Stop;
}
if (elementNames.length === 0) {
this.code.logger.log('QuickAccess: No elements found, retrying...');
return false; // Retry polling
}

this.code.logger.log(`QuickAccess: file search returned ${firstElementName} as first result but was expecting ${expectedFirstElementNameOrExpectedResultCount}, will retry...`);
const firstElementName = elementNames[0];

retry = true;
// Check if "No matching results" appears
if (firstElementName === 'No matching results') {
this.code.logger.log(`QuickAccess: File search returned "No matching results", retrying...`);
return false; // Retry polling
}

return PollingStrategy.Stop;
// Handle expected result count
if (typeof expectedFirstElementNameOrExpectedResultCount === 'number') {
if (elementNames.length === expectedFirstElementNameOrExpectedResultCount) {
return true; // Condition met
}
});
} catch (error) {
this.code.logger.log(`QuickAccess: file search waitForQuickInputElements threw an error ${error}, will retry...`);

retry = true;
}

if (!retry) {
break;
}

await this.quickInput.closeQuickInput();
}
this.code.logger.log(
`QuickAccess: Expected ${expectedFirstElementNameOrExpectedResultCount} results, got ${elementNames.length}, retrying...`
);
return false;
}

// Handle expected first element name
if (firstElementName === expectedFirstElementNameOrExpectedResultCount) {
return true; // Condition met
}

this.code.logger.log(
`QuickAccess: Expected first result '${expectedFirstElementNameOrExpectedResultCount}', got '${firstElementName}', retrying...`
);
return false;
});
}).toPass({
timeout: 15000,
});

if (!success) {
if (typeof expectedFirstElementNameOrExpectedResultCount === 'string') {
throw new Error(`Quick open file search was unable to find '${expectedFirstElementNameOrExpectedResultCount}' after 10 attempts, giving up.`);
} else {
throw new Error(`Quick open file search was unable to find ${expectedFirstElementNameOrExpectedResultCount} result items after 10 attempts, giving up.`);
}
}
this.code.logger.log('QuickAccess: File search succeeded.');
}

async openFile(path: string): Promise<void> {
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/areas/apps/shiny.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ test.use({
});

test.describe('Shiny Application', { tag: [tags.APPS, tags.VIEWER, tags.WIN] }, () => {
// test.beforeAll(async function ({ app }) {
// try {
// await app.workbench.extensions.installExtension('posit.shiny', true);
// await app.workbench.extensions.closeExtension('Shiny');
// } catch (e) {
// app.code.driver.takeScreenshot('shinySetup');
// throw e;
// }
// });
test.beforeAll(async function ({ app }) {
try {
await app.workbench.extensions.installExtension('posit.shiny', true);
await app.workbench.extensions.closeExtension('Shiny');
} catch (e) {
app.code.driver.takeScreenshot('shinySetup');
throw e;
}
});

test.afterEach(async function ({ app }) {
await app.workbench.positronTerminal.sendKeysToTerminal('Control+C');
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/areas/data-explorer/data-explorer-r.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test.describe('Data Explorer - R ', {
logger.log('Opening data grid');
await expect(async () => {
await app.workbench.positronVariables.doubleClickVariableRow('Data_Frame');
await expect(app.code.driver.getLocator('.label-name:has-text("Data: Data_Frame")')).not.toHaveText('');
await app.code.driver.getLocator('.label-name:has-text("Data: Data_Frame")').innerText();
}).toPass();

await app.workbench.positronDataExplorer.maximizeDataExplorer(true);
Expand Down Expand Up @@ -94,7 +94,10 @@ test.describe('Data Explorer - R ', {
await app.workbench.editors.newUntitledFile();
await app.workbench.positronQuickaccess.runCommand('workbench.panel.positronVariables.focus');
await app.workbench.positronVariables.doubleClickVariableRow('Data_Frame');
await app.code.driver.getLocator('.label-name:has-text("Data: Data_Frame")').innerText();

await expect(async () => {
await app.code.driver.getLocator('.label-name:has-text("Data: Data_Frame")').innerText();
}).toPass();

await app.workbench.positronDataExplorer.closeDataExplorer();
await app.workbench.positronQuickaccess.runCommand('workbench.panel.positronVariables.focus');
Expand All @@ -106,7 +109,7 @@ test.describe('Data Explorer - R ', {

await expect(async () => {
await app.workbench.positronVariables.doubleClickVariableRow('df');
await expect(app.code.driver.page.locator('.label-name:has-text("Data: df")')).not.toHaveText('');
await app.code.driver.getLocator('.label-name:has-text("Data: df")').innerText();
}).toPass();

await expect(async () => {
Expand Down

0 comments on commit f3c9328

Please sign in to comment.