Skip to content

Commit

Permalink
sparklineTrend.test.ts: fix flakes (#4774)
Browse files Browse the repository at this point in the history
Making improvements to data explorer sparkline trend test to make it
easier to debug and prevent flakes.

### QA Notes
Ran locally and passed.
Ran in GHA and passed (multiple times).
  • Loading branch information
midleman authored Sep 23, 2024
1 parent 9b6f7c0 commit a72eef5
Showing 1 changed file with 46 additions and 68 deletions.
114 changes: 46 additions & 68 deletions test/smoke/src/areas/positron/dataexplorer/sparklinesTrend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { expect } from '@playwright/test';
import { Application, Logger, PositronPythonFixtures } from '../../../../../automation';
import { Application, Logger, PositronPythonFixtures, PositronRFixtures } from '../../../../../automation';
import { installAllHandlers } from '../../../utils';

export function setup(logger: Logger) {
Expand All @@ -13,98 +13,76 @@ export function setup(logger: Logger) {
installAllHandlers(logger);

describe('Sparklines', () => {
let app: Application;

beforeEach(async function () {
await this.app.workbench.positronLayouts.enterLayout('stacked');
await PositronPythonFixtures.SetupFixtures(this.app as Application);
app = this.app;
await app.workbench.positronLayouts.enterLayout('stacked');
});

async function openDataExplorerColumnProfile(app: Application) {
logger.log('Opening data grid');
await expect(async () => {
await app.workbench.positronVariables.doubleClickVariableRow('graphData');
await app.code.driver.getLocator('.label-name:has-text("Data: graphData")').innerText();
}).toPass();

logger.log('Expand column profile');
await app.workbench.positronSideBar.closeSecondarySideBar();
await app.workbench.positronDataExplorer.expandColumnProfile(0);
}

async function verifyGraphBarHeights(app: Application) {
// Get all graph graph bars/rectangles
await expect(async () => {
const rects = app.code.driver.getLocator('rect.count');

// Iterate over each rect and verify the height
const expectedHeights = ['50', '40', '30', '20', '10'];
for (let i = 0; i < expectedHeights.length; i++) {
const height = await rects.nth(i).getAttribute('height');
expect(height).toBe(expectedHeights[i]);
}
}).toPass({ timeout: 10000 });
}

it('Python Pandas - Verifies downward trending graph [C830552]', async function () {
const app = this.app as Application;

logger.log('[Python] Sending code to console');
await app.workbench.positronConsole.executeCode('Python', pythonScript, '>>>');
afterEach(async () => {
await app.workbench.quickaccess.runCommand('workbench.action.closeAllEditors', { keepOpen: false });
});

it('Python Pandas - Verifies downward trending graph [C830552]', async () => {
await PositronPythonFixtures.SetupFixtures(app);

await openDataExplorerColumnProfile(app);
await app.workbench.positronConsole.executeCode('Python', pythonScript, '>>>');
await openDataExplorerColumnProfile(app, 'pythonData');
await verifyGraphBarHeights(app);
});


it('R - Verifies downward trending graph [C830553]', async function () {
const app = this.app as Application;
it('R - Verifies downward trending graph [C830553]', async () => {
await PositronRFixtures.SetupFixtures(app);

logger.log('[R] Sending code to console');
await app.workbench.positronConsole.executeCode('R', rScript, '>');

await openDataExplorerColumnProfile(app);
await openDataExplorerColumnProfile(app, 'rData');
await verifyGraphBarHeights(app);
});
});

async function openDataExplorerColumnProfile(app: Application, variableName: string) {

await expect(async () => {
await app.workbench.positronVariables.doubleClickVariableRow(variableName);
await app.code.driver.getLocator(`.label-name:has-text("Data: ${variableName}")`).innerText();
}).toPass();

await app.workbench.positronDataExplorer.getDataExplorerTableData();
await app.workbench.positronSideBar.closeSecondarySideBar();
await app.workbench.positronDataExplorer.expandColumnProfile(0);
}

async function verifyGraphBarHeights(app: Application) {
// Get all graph graph bars/rectangles
await expect(async () => {
const rects = app.code.driver.getLocator('rect.count');

// Iterate over each rect and verify the height
const expectedHeights = ['50', '40', '30', '20', '10'];
for (let i = 0; i < expectedHeights.length; i++) {
const height = await rects.nth(i).getAttribute('height');
expect(height).toBe(expectedHeights[i]);
}
}).toPass({ timeout: 10000 });
}
});
}

const rScript = `library(ggplot2)
library(dplyr)
const rScript = `library(dplyr)
# Example data with multiple values for the same category
graphData <- tibble(
rData <- tibble(
category = c("A", "A", "A", "A", "B", "B", "B", "C", "C", "D", "E", "A", "B", "C", "D"),
values = c(1, 2, 3, 4, 5, 9, 10, 11, 13, 25, 7, 15, 20, 5, 6)
)
# Summarize data by summing values per category
summarized_data <- graphData %>%
group_by(category) %>%
summarise(total_values = sum(values))
# Create a bar graph
ggplot(summarized_data, aes(x = reorder(category, -total_values), y = total_values)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(x = "Category", y = "Total Values", title = "Bar Graph with Summed Values") +
theme_minimal()`;
)`;


const pythonScript = `import pandas as pd
import matplotlib.pyplot as plt
# Example data with multiple values for the same category
graphData = pd.DataFrame({
pythonData = pd.DataFrame({
'category': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'D', 'E', 'A', 'B', 'C', 'D'],
'values': [1, 2, 3, 4, 5, 9, 10, 11, 13, 25, 7, 15, 20, 5, 6]
})
# Summarize data by summing values per category
summarized_data = graphData.groupby('category', as_index=False).sum()
})`;

# Create a bar graph
plt.bar(summarized_data['category'], summarized_data['values'], color='steelblue')
plt.xlabel('Category')
plt.ylabel('Total Values')
plt.title('Bar Graph with Summed Values')
plt.show()`;

0 comments on commit a72eef5

Please sign in to comment.