From d58cb570ef442687df0dfcf20c4c504f67252eb1 Mon Sep 17 00:00:00 2001 From: Marie Idleman Date: Fri, 22 Nov 2024 09:59:07 -0600 Subject: [PATCH] cleanup --- .../src/positron/positronConnections.ts | 37 ++--- .../src/positron/positronVariables.ts | 5 + .../connections/connections-db.test.ts | 138 ++++++++---------- 3 files changed, 76 insertions(+), 104 deletions(-) diff --git a/test/automation/src/positron/positronConnections.ts b/test/automation/src/positron/positronConnections.ts index 45d3cb12546..32ba66e5061 100644 --- a/test/automation/src/positron/positronConnections.ts +++ b/test/automation/src/positron/positronConnections.ts @@ -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 @@ -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[]) { @@ -49,25 +35,20 @@ export class PositronConnections { async assertConnectionNodes(nodes: string[]): Promise { 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'); diff --git a/test/automation/src/positron/positronVariables.ts b/test/automation/src/positron/positronVariables.ts index e61f79aeb50..f937255ff3d 100644 --- a/test/automation/src/positron/positronVariables.ts +++ b/test/automation/src/positron/positronVariables.ts @@ -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(); + } } diff --git a/test/smoke/src/areas/positron/connections/connections-db.test.ts b/test/smoke/src/areas/positron/connections/connections-db.test.ts index a9a24ff856b..3cebe5be182 100644 --- a/test/smoke/src/areas/positron/connections/connections-db.test.ts +++ b/test/smoke/src/areas/positron/connections/connections-db.test.ts @@ -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'];