Skip to content

Commit

Permalink
Adding some further tests,
Browse files Browse the repository at this point in the history
Need to debug a few as the playwright tests are not coming out consistent.

(IE: running sqlite test by itself works 100% but when running with the others, it seems to fail ... )
  • Loading branch information
royendo committed Jan 6, 2025
1 parent 4acbf35 commit bdf8869
Show file tree
Hide file tree
Showing 12 changed files with 643 additions and 38 deletions.
Binary file added web-local/mydb.sqlite
Binary file not shown.
78 changes: 47 additions & 31 deletions web-local/tests/sources/source-blankFile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
import { test } from '@playwright/test';
import { test as RillTest } from '../utils/test';
import { addFileWithCheck, waitForTable } from '../utils/sourceHelpers';
import { renameFileUsingMenu, actionUsingMenu, checkExistInConnector } from '../utils/commonHelpers';
import { test } from "@playwright/test";
import { test as RillTest } from "../utils/test";
import { addFileWithCheck, waitForTable } from "../utils/sourceHelpers";
import {
renameFileUsingMenu,
actionUsingMenu,
checkExistInConnector,
} from "../utils/commonHelpers";

/// Blank File test
/// In this test we create a `untilted_file`, create a second one to ensure `_1` is appended
/// Following that we rename and modify the contents of a file to a source
/// Re-create a file to ensure it makes a `untitiled_file`, then duplicate it.

/// Need to add checks for the Sources

test.describe('Creating a blank file... and making a source.', () => {
RillTest('Creating Blank file', async ({ page }) => {
test.describe("Creating a blank file... and making a source.", () => {
RillTest("Creating Blank file", async ({ page }) => {
// create blank file
await addFileWithCheck(page, 'untitled_file');
await addFileWithCheck(page, "untitled_file");
// Wait for the file `untitled_file` to be present on the page
await page.waitForSelector('li[aria-label="/untitled_file Nav Entry"]', { state: 'visible' });

//create another blank file and expected untitled_file_1
await addFileWithCheck(page, 'untitled_file_1');
await page.waitForSelector('li[aria-label="/untitled_file_1 Nav Entry"]', { state: 'visible' });
await page.waitForSelector('li[aria-label="/untitled_file Nav Entry"]', {
state: "visible",
});

//create another blank file and expected untitled_file_1
await addFileWithCheck(page, "untitled_file_1");
await page.waitForSelector('li[aria-label="/untitled_file_1 Nav Entry"]', {
state: "visible",
});

await renameFileUsingMenu(page, '/untitled_file', 'source.yaml')
await renameFileUsingMenu(page, "/untitled_file", "source.yaml");

await page.waitForSelector('li[aria-label="/source.yaml Nav Entry"]', { state: 'visible' });
console.log('File renamed successfully to source.yaml!');
await page.waitForSelector('li[aria-label="/source.yaml Nav Entry"]', {
state: "visible",
});
console.log("File renamed successfully to source.yaml!");

const textBox = page
.getByLabel('Code editor') // Locate the labeled parent
.getByRole('textbox'); // Find the inner textbox
.getByLabel("Code editor") // Locate the labeled parent
.getByRole("textbox"); // Find the inner textbox

// Wait for the textbox to be visible
await textBox.waitFor({ state: 'visible' });
await textBox.waitFor({ state: "visible" });

// Rewrite the contents of the textbox
await textBox.fill(`# Testing manual file creation
Expand All @@ -42,27 +49,36 @@ test.describe('Creating a blank file... and making a source.', () => {
connector: "duckdb"
sql: "select * from read_csv('gs://playwright-gcs-qa/AdBids_csv.csv', auto_detect=true, ignore_errors=1, header=true)"`);

console.log('Successfully Modified Contents. Checking for data.');
console.log("Successfully Modified Contents. Checking for data.");

await waitForTable(page, "/source.yaml", [
"timestamp",
"id",
"bid_price",
"domain",
"publisher",
]);

await waitForTable(page, '/source.yaml', ['timestamp', 'id', 'bid_price', 'domain', 'publisher']);
// CREATING A NEW BLANK FILE, EXPECT IT TO BE `untitled_file` as we modified the original

//CREATING A NEW BLANK FILE, EXPECT IT TO BE `untitled_file` as we modified the original

console.log("Creating a new file, expecting `untitled_file`")
console.log("Creating a new file, expecting `untitled_file`");
// create new blank file
await addFileWithCheck(page, 'untitled_file');
await page.waitForSelector('li[aria-label="/untitled_file Nav Entry"]', { state: 'visible' });

await addFileWithCheck(page, "untitled_file");
await page.waitForSelector('li[aria-label="/untitled_file Nav Entry"]', {
state: "visible",
});

// TEST FOR DUPLICATES and refresh

// Locate and click the ellipsis menu button for `untitled_file`
await actionUsingMenu(page, "/source.yaml", "Duplicate")
await actionUsingMenu(page, "/source.yaml", "Duplicate");
await page.getByText("View this source").click();

// checks?
await page.waitForSelector('li[aria-label="/source (copy).yaml Nav Entry"]', { state: 'visible' });
// checks that the file exists in the duckdb connector
await page.waitForSelector(
'li[aria-label="/source (copy).yaml Nav Entry"]',
{ state: "visible" },
);
await checkExistInConnector(page, "duckdb", "main_db", "source (copy)");
});
});
126 changes: 126 additions & 0 deletions web-local/tests/sources/source-duckdb.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { test, expect } from "@playwright/test";
import { execSync, spawn } from "child_process";
import { test as RillTest } from "../utils/test";

import path from "node:path";
import { DuckDB, waitForTable } from "../utils/sourceHelpers";

//DuckDB requires 1 worker as it doesnt allow concurrency, will fail otherwise.

test.describe("Read DuckDB Table, then read into Rill", () => {
async function ensureDuckDBInstalled() {
try {
// Check if DuckDB is installed
execSync("duckdb --version", { stdio: "ignore" });
console.log("DuckDB is already installed.");
} catch (err) {

Check failure on line 16 in web-local/tests/sources/source-duckdb.spec.ts

View workflow job for this annotation

GitHub Actions / build

'err' is defined but never used
console.log("DuckDB not found. Installing...");
// Install DuckDB (example for macOS/Linux using wget)
// https://github.com/duckdb/duckdb/releases/latest/download/duckdb_cli-linux-amd64.zip
try {
execSync(
`
wget https://github.com/duckdb/duckdb/releases/download/v1.1.3/duckdb_cli-osx-universal.zip &&
unzip duckdb_cli-osx-universal.zip &&
chmod +x duckdb &&
sudo mv duckdb /usr/local/bin/
`,
{ stdio: "inherit" },
);

console.log("DuckDB installed successfully.");
} catch (error) {
console.error("DuckDB installation failed:", error);
}
console.log("DuckDB installed successfully.");
}
}

test.beforeAll(async () => {
await ensureDuckDBInstalled();
const currentDir = process.cwd();
const dbPath = path.resolve(currentDir, "test/data/playwright.db");
const commands = [
`.open ${dbPath}`,
"select count(*) from sales;",
"select count(*) from customer_data;",
".exit",
];
console.log(`Running DuckDB commands against: ${dbPath}`);

await new Promise((resolve, reject) => {
const cli = spawn("duckdb", [], { shell: true });

let output = "";
cli.stdout.on("data", (data) => {
output += data.toString();
});

cli.stderr.on("data", (data) => {
console.error(`Error: ${data}`);
});

cli.on("close", (code) => {
if (code === 0) {
console.log("DuckDB CLI execution completed successfully.");
const salesCountMatch = output.match(/100000/); // Expected count for sales
const customerCountMatch = output.match(/10000/); // Expected count for customer_data

expect(salesCountMatch).not.toBeNull();
expect(customerCountMatch).not.toBeNull();
resolve();
} else {
reject(new Error(`DuckDB CLI exited with code ${code}`));
}
});

// Write commands to DuckDB CLI
commands.forEach((cmd) => cli.stdin.write(`${cmd}\n`));
cli.stdin.end();
});
});

test("Validate data in DuckDB", async () => {
console.log("Validation complete in beforeAll.");
});

console.log("Checked DuckDB with sales and customer_data tables.");
console.log("Starting Rill Developer...");

RillTest("Reading Source into Rill", async ({ page }) => {
// Test loading the 'sales' table
await Promise.all([
waitForTable(page, "sources/sales.yaml", [
"sale_date",
"sale_id",
"duration_ms",
"customer_id",
"sales_amount_usd",
"products",
"discounts",
"region",
"is_online",
]),
DuckDB(page, "sales"), // Ensure the `sales` dataset is loaded
]);

console.log("Sales table validated.");

// Test loading the 'customer_data' table
await Promise.all([
waitForTable(page, "sources/customer_data.yaml", [
"customer_id",
"name",
"email",
"signup_date",
"preferences",
"total_spent_usd",
"loyalty_tier",
"is_active",
]),
DuckDB(page, "customer_data"), // Ensure the `customer_data` dataset is loaded
]);

console.log("Customer data table validated.");
});
});
40 changes: 40 additions & 0 deletions web-local/tests/sources/source-folders.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { test } from "@playwright/test";
import { test as RillTest } from "../utils/test";
import { addFolderWithCheck } from "../utils/sourceHelpers";

/// Blank Folder test
/// In this test we create a `untilted_file`, create a second one to ensure `_1` is appended

test.describe("Creating a Folder... and making a source.", () => {
RillTest("Creating Folder", async ({ page }) => {
// create folder file
await Promise.all([addFolderWithCheck(page, "untitled_folder_3")]);
await Promise.all([addFolderWithCheck(page, "untitled_folder_1")]);
await Promise.all([addFolderWithCheck(page, "untitled_folder_")]);
// create folder in subfolder
await page.locator('span:has-text("untitled_folder_2")').last().hover();
await page.getByLabel("untitled_folder_2 actions menu trigger").click();
await page.getByRole("menuitem", { name: "New Folder" }).first().click();

// check that the folder exists,
await page.waitForSelector("#nav-\\/untitled_folder_2\\/untitled_folder", {
timeout: 5000,
});
await page
.locator('[aria-label="/untitled_folder_2/untitled_folder"]')
.isVisible();

// create another for proper "_1" append
await page.locator('span:has-text("untitled_folder_2")').last().hover();
await page.getByLabel("untitled_folder_2 actions menu trigger").click();
await page.getByRole("menuitem", { name: "New Folder" }).first().click();

await page.waitForSelector(
"#nav-\\/untitled_folder_2\\/untitled_folder_1",
{ timeout: 5000 },
);
await page
.locator('[aria-label="/untitled_folder_2/untitled_folder_1"]')
.isVisible();
});
});
Loading

0 comments on commit bdf8869

Please sign in to comment.