Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
midleman committed Nov 22, 2024
1 parent e428fbc commit d58cb57
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 104 deletions.
37 changes: 9 additions & 28 deletions test/automation/src/positron/positronConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@
import { expect, Locator } from '@playwright/test';
import { Code } from '../code';
import { QuickAccess } from '../quickaccess';
import { PositronBaseElement } from './positronBaseElement';

const REMOVE_CONNECTION_BUTTON = 'a[aria-label="Remove connection from history"]';

const PYTHON_CONNECTION_OPEN_STATE = 'div[aria-label="SQLite Connection"]';
const R_CONNECTION_OPEN_STATE = 'div[aria-label="SQLiteConnection"]:first-child';
const RECONNECT_BUTTON = 'a[aria-label="Execute connection code in the console"]';

const CONNECTIONS_TAB_LINK = 'a[aria-label="Connections"]';
const CONNECTION_ITEM = '.connections-items-container';
const CONNECTION_ICON = '.codicon-arrow-circle-right';

/*
* Reuseable Positron connections tab functionality for tests to leverage
Expand All @@ -25,19 +18,12 @@ export class PositronConnections {

deleteConnectionButton: Locator;
disconnectButton: Locator;
rConnectionOpenState: PositronBaseElement;
pythonConnectionOpenState: PositronBaseElement;
reconnectButton: PositronBaseElement;
connectionsTabLink: PositronBaseElement;
connectionIcon: Locator;

constructor(private code: Code, private quickaccess: QuickAccess) {

this.deleteConnectionButton = code.driver.page.getByLabel('Delete Connection');
this.disconnectButton = code.driver.page.getByLabel('Disconnect');
this.rConnectionOpenState = new PositronBaseElement(R_CONNECTION_OPEN_STATE, this.code);
this.pythonConnectionOpenState = new PositronBaseElement(PYTHON_CONNECTION_OPEN_STATE, this.code);
this.reconnectButton = new PositronBaseElement(RECONNECT_BUTTON, this.code);
this.connectionsTabLink = new PositronBaseElement(CONNECTIONS_TAB_LINK, this.code);
this.connectionIcon = code.driver.page.locator(CONNECTION_ICON);
}

async openConnectionsNodes(nodes: string[]) {
Expand All @@ -49,25 +35,20 @@ export class PositronConnections {

async assertConnectionNodes(nodes: string[]): Promise<void> {
const waits = nodes.map(async node => {
this.assertConnectionNode(node);
await expect(
this.code.driver.page.locator(CONNECTION_ITEM).getByText(node)
).toBeVisible();
});
await Promise.all(waits);
}

async assertConnectionNode(node: string) {
await expect(
this.code.driver.page.locator(CONNECTION_ITEM).getByText(node)
).toBeVisible();
}

async openConnectionPane() {
await this.quickaccess.runCommand('connections.focus');
// await this.connectionPaneIsOpen(); // waiting for the pane to open
}

// async connectionPaneIsOpen() {
// await this.code.wait(500);
// }
async viewConnection(name: string) {
await this.code.driver.page.locator('.connections-list-item').filter({ hasText: name }).locator('.col-action > .codicon').click();
}

async openTree() {
await this.quickaccess.runCommand('positron.connections.expandAll');
Expand Down
5 changes: 5 additions & 0 deletions test/automation/src/positron/positronVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,9 @@ export class PositronVariables {
await this.code.wait(500);
await this.code.driver.page.locator('a.action-menu-item', { hasText: name }).click();
}

async clickDatabaseIconForVariableRow(rowName: string) {
const DATABASE_ICON = '.codicon-database';
await this.code.driver.page.locator(VARIABLE_ITEMS).filter({ hasText: rowName }).locator(DATABASE_ICON).click();
}
}
138 changes: 62 additions & 76 deletions test/smoke/src/areas/positron/connections/connections-db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,95 +19,81 @@ test.describe('SQLite DB Connection', { tag: ['@web', '@win', '@pr'] }, () => {
});

test.afterEach(async function ({ app, page }) {
await app.workbench.positronConnections.disconnectButton.click();
await page.locator('.connections-list-item').click();
await expect(page.getByLabel('Delete Connection')).toBeVisible();
await app.workbench.positronConnections.deleteConnectionButton.click();
});

test('Python - SQLite DB Connection [C628636]', async function ({ app, page, logger, python }) {
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, 'workspaces', 'chinook-db-py', 'chinook-sqlite.py'));
await app.workbench.quickaccess.runCommand('python.execInConsole');

await page.locator('div:nth-child(4) > .details-column > .right-column > .viewer-icon').click();
await page.locator('.connections-list-item > .col-icon').click();
await page.locator('.col-action > .codicon').click(); // arrow on right
await page.locator('.expand-collapse-area > .codicon').click(); // caret on left

// click in reverse order to avoid scrolling issues
await app.workbench.positronConnections.assertConnectionNodes(['albums']);

// disconnect
await app.workbench.positronConnections.disconnectButton.click();
await page.getByText('SQLite Connection').click();

await test.step('Open a Python file and run it', async () => {
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, 'workspaces', 'chinook-db-py', 'chinook-sqlite.py'));
await app.workbench.quickaccess.runCommand('python.execInConsole');
});

await test.step('Open connections pane', async () => {
await app.workbench.positronVariables.clickDatabaseIconForVariableRow('conn');
await app.workbench.positronConnections.connectionIcon.click();
});

await test.step('Verify connection nodes', async () => {
await app.workbench.positronConnections.openConnectionsNodes(['main']);
await app.workbench.positronConnections.assertConnectionNodes(['albums']);
});
});


test('R - SQLite DB Connection [C628637]', async function ({ app, page, logger, r }) {
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, 'workspaces', 'chinook-db-r', 'chinook-sqlite.r'));
await app.workbench.quickaccess.runCommand('r.sourceCurrentFile');

// open connections pane
await app.workbench.positronConnections.openConnectionPane();
await page.locator('.col-action > .codicon').click(); // arrow on right
await page.locator('.expand-collapse-area > .codicon').click(); // caret on left

// click in reverse order to avoid scrolling issues
await app.workbench.positronConnections.openConnectionsNodes(['Default']);
await app.workbench.positronConnections.openConnectionsNodes(tables);

// disconnect icon appearance requires hover
// await app.workbench.positronConnections.rConnectionOpenState.hover();
// await app.workbench.positronConnections.disconnectButton.click();
// await app.workbench.positronConnections.reconnectButton.waitforVisible();
await app.workbench.positronConnections.disconnectButton.click();
await page.getByText('SQLiteConnection').click();
await test.step('Open an R file and run it', async () => {
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, 'workspaces', 'chinook-db-r', 'chinook-sqlite.r'));
await app.workbench.quickaccess.runCommand('r.sourceCurrentFile');
});

await test.step('Open connections pane', async () => {
await app.workbench.positronConnections.openConnectionPane();
await app.workbench.positronConnections.viewConnection('SQLiteConnection');
});

await test.step('Verify connection nodes', async () => {
await app.workbench.positronConnections.openConnectionsNodes(['SQLiteConnection', 'Default']);
await app.workbench.positronConnections.openConnectionsNodes(tables);
});
});

test('R - Connections are update after adding a database,[C663724]', async function ({ app, page, logger, r }) {
// open an empty connection
await app.workbench.positronConsole.executeCode(
'R',
`con <- connections::connection_open(RSQLite::SQLite(), tempfile())`,
'>'
);

// // should be able to see the new connection in the connections pane
// logger.log('Opening connections pane');
// await app.workbench.positronConnections.connectionsTabLink.click();

// await app.workbench.positronConnections.openTree();
// open connections pane
await app.workbench.positronConnections.openConnectionPane();
await page.locator('.col-action > .codicon').click(); // arrow on right
await page.locator('.expand-collapse-area > .codicon').click(); // caret on left



// mtcars node should not exist
await app.workbench.positronConnections.openConnectionsNodes(['Default']);
await expect(
page.locator('.connections-items-container').getByText('mtcars')
).not.toBeVisible();

// now we add a dataframe to that connection
await app.workbench.positronConsole.executeCode(
'R',
`DBI::dbWriteTable(con, "mtcars", mtcars)`,
'>'
);

await page.getByRole('button', { name: 'Refresh' }).click();
await app.workbench.positronConnections.openConnectionsNodes(["mtcars"]);

await app.workbench.positronConnections.disconnectButton.click();
await page.getByText('SQLiteConnection').click();
// disconnect icon appearance requires hover
// await app.workbench.positronConnections.rConnectionOpenState.hover();
// await app.workbench.positronConnections.disconnectButton.click();
// await app.workbench.positronConnections.reconnectButton.waitforVisible();
await test.step('Open an empty connection', async () => {
await app.workbench.positronConsole.executeCode(
'R',
`con <- connections::connection_open(RSQLite::SQLite(), tempfile())`,
'>'
);
});

await test.step('Open connections pane', async () => {
await app.workbench.positronConnections.openConnectionPane();
await app.workbench.positronConnections.viewConnection('SQLiteConnection');
await app.workbench.positronConnections.openConnectionsNodes(['SQLiteConnection', 'Default']);

// mtcars node should not exist
await expect(
page.locator('.connections-items-container').getByText('mtcars')
).not.toBeVisible();
});


await test.step('Add a dataframe to the connection', async () => {
await app.workbench.positronConsole.executeCode(
'R',
`DBI::dbWriteTable(con, 'mtcars', mtcars)`,
'>'
);

// refresh and mtcars should exist
await page.getByRole('button', { name: 'Refresh' }).click();
await app.workbench.positronConnections.openConnectionsNodes(['mtcars']);
});
});

});


// reverse order to avoid scrolling issues
const tables = ['tracks', 'playlist_track', 'playlists', 'media_types', 'invoice_items', 'invoices', 'genres', 'employees', 'customers', 'artists', 'albums'];

0 comments on commit d58cb57

Please sign in to comment.