Skip to content

Commit

Permalink
extended e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Karch committed May 15, 2024
1 parent 4b5933e commit 5e30237
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 54 deletions.
2 changes: 1 addition & 1 deletion dev/compile_restart_dev.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
recompile_front <- T # nolint
release <- TRUE
release <- T

if (recompile_front) {
# Compile Svelte front end
Expand Down
13 changes: 1 addition & 12 deletions dev/start_for_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ if (!requireNamespace("pkgload", quietly = TRUE)) {
}

golem::detach_all_attached()

print("hallo")
# Document and reload your package
# roxygen2::roxygenise()
pkgload::load_all()
library(lavaan)
HS.model <- " visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 "

fit <- cfa(HS.model, data = HolzingerSwineford1939)
options(shiny.port = 3245)
print("Starting server...")
start_gui(fit)
start_gui()
Binary file renamed frontend/e2e/cfa.zip → frontend/e2e/cfa.lvd
Binary file not shown.
61 changes: 28 additions & 33 deletions frontend/e2e/example.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ console.log(__dirname);

//File menu

test.beforeEach(async ({ page }) => {
const fileChooserPromise = page.waitForEvent("filechooser");
await page.goto("/");
await page.getByRole("button", { name: "File" }).click();
await page.waitForTimeout(500);
await page.getByRole("link", { name: "Load Model and Data", exact: true }).click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(path.join(__dirname, "cfa.lvd"));
});


test("new model", async ({ page }) => {
await page.goto('/');
await page.getByRole("button", { name: "File" }).click();
await page.waitForTimeout(500);
await page.getByRole("link", { name: "New Model" }).click();
await page.getByText("OK").click();
// @ts-expect-error
Expand All @@ -21,10 +32,11 @@ test("new model", async ({ page }) => {
await expect(page.getByTestId("result-text")).toContainText("Command");
});


test("Load Data", async ({ page }) => {
const fileChooserPromise = page.waitForEvent("filechooser");
await page.goto("/");
await page.getByRole("button", { name: "File" }).click();
await page.waitForTimeout(500);
await page.getByRole("link", { name: "Load Data", exact: true }).click();

const fileChooser = await fileChooserPromise;
Expand All @@ -33,60 +45,46 @@ test("Load Data", async ({ page }) => {
await expect(heading).toBeVisible();
});

test("Load Model and Data", async ({ page }) => {
const fileChooserPromise = page.waitForEvent("filechooser");
await page.goto("/");
await page.getByRole("button", { name: "File" }).click();
await page
.getByRole("link", { name: "Load Model and Data", exact: true })
.click();
await page.getByText("OK").click();

const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(path.join(__dirname, "cfa.zip"));
});

test("Download Model", async ({ page }) => {
await page.goto("/");
await page.getByRole("button", { name: "File" }).click();
await page.waitForTimeout(500);
const downloadPromise = page.waitForEvent("download");
await page.getByRole("link", { name: "Download Model", exact: true }).click();
const download = await downloadPromise;
expect(download.suggestedFilename()).toBe("diagram.json");
expect(download.suggestedFilename()).toBe("model.lvm");
});

test("Remove Data", async ({ page }) => {
await page.goto("/");
await page.getByRole("button", { name: "File" }).click();
await page.waitForTimeout(500);
await page.getByRole("link", { name: "Remove Data" }).click();
const button = await page.getByRole('button', { name: 'Show Data' });
expect(await button.isDisabled()).toBe(true);
});

test("Download Model Data", async ({ page }) => {
await page.goto("/");
await page.waitForTimeout(3000);
await page.getByRole("button", { name: "File" }).click();
await page.waitForTimeout(500);
const downloadPromise = page.waitForEvent("download");
await page
.getByRole("link", { name: "Download Model and Data", exact: true })
.click();
const download = await downloadPromise;
expect(download.suggestedFilename()).toMatch(/^lavaangui.*\.zip$/);
expect(download.suggestedFilename()).toMatch(/^lavaangui.*\.lvd$/);
});

test("Export PNG", async ({ page }) => {
await page.goto("/");
await page.getByRole("button", { name: "File" }).click();
await page.waitForTimeout(500);
const downloadPromise = page.waitForEvent("download");
await page.getByRole("link", { name: "PNG", exact: false }).click();
const download = await downloadPromise;
expect(download.suggestedFilename()).toBe("model.png");
});

test("Export JPG", async ({ page }) => {
await page.goto("/");
await page.getByRole("button", { name: "File" }).click();
await page.waitForTimeout(500);
const downloadPromise = page.waitForEvent("download");
await page.getByRole("link", { name: "JPG", exact: false }).click();
const download = await downloadPromise;
Expand All @@ -95,7 +93,6 @@ test("Export JPG", async ({ page }) => {

//View Menu
test("Default options View", async ({ page }) => {
await page.goto("/");
await page.getByRole("button", { name: "Estimates" }).click();
await page.waitForTimeout(1500);

Expand Down Expand Up @@ -130,8 +127,7 @@ test("Default options View", async ({ page }) => {
});

test("Show Script", async ({ page }) => {
await page.goto("/");

await page.waitForTimeout(500);
await expect(page.getByTestId("result-text")).toContainText(
"library(lavaan)"
);
Expand All @@ -152,9 +148,9 @@ test("Show Script", async ({ page }) => {
});

test("Show Full Model", async ({ page }) => {
await page.goto("/");
await page.getByRole("button", { name: "Full Model" }).click();

await page.waitForTimeout(500);
await page.getByRole("button", { name: "Lavaan Model" }).click();
await page.waitForTimeout(500);
await expect(page.getByTestId("result-text")).toContainText("library(lavaan)");
const lavEdges = await page.evaluate(() =>
// @ts-expect-error
Expand All @@ -173,7 +169,6 @@ test("Show Full Model", async ({ page }) => {
});

test("Fit Model", async ({ page }) => {
await page.goto("/");
await page.getByRole("button", { name: "Estimates" }).click();

await page.waitForTimeout(2000);
Expand Down Expand Up @@ -219,7 +214,6 @@ test("Fit Model", async ({ page }) => {
// });

test("Remove data", async ({ page }) => {
await page.goto("http://127.0.0.1:3245/");
await page.getByRole("button", { name: "File" }).click();
await page.getByRole("link", { name: "Remove Data" }).click();
const fitButton = await page.getByRole("button", { name: "Estimates" });
Expand All @@ -228,12 +222,13 @@ test("Remove data", async ({ page }) => {

test("Not Identified", async ({ page }) => {
const fileChooserPromise = page.waitForEvent("filechooser");
await page.goto("http://127.0.0.1:3245/");
await page.getByRole("button", { name: "File" }).click();
await page.waitForTimeout(500);
await page.getByRole("link", { name: "Load Model", exact: true }).click();
await page.getByText("OK").click();
await page.waitForTimeout(500);
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(path.join(__dirname, "not_identified.json"));
await fileChooser.setFiles(path.join(__dirname, "not_identified.lvm"));
const fitButton = await page.getByRole("button", { name: "Estimates" });
fitButton.click();
await page.waitForTimeout(500);
Expand Down
File renamed without changes.
34 changes: 27 additions & 7 deletions frontend/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,45 @@ export default defineConfig({
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.shinyapps ? 'http://lavaangui.org/' : 'http://127.0.0.1:3245',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
name: "chromium local",
use: {
...devices["Desktop Chrome"], baseURL: 'http://127.0.0.1:3245'
},
},

{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
name: "firefox local",
use: { ...devices["Desktop Firefox"], baseURL: 'http://127.0.0.1:3245' },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
name: 'webkit local',
use: {
...devices['Desktop Safari'], baseURL: 'http://127.0.0.1:3245'
},
},
{
name: "chromium global",
use: {
...devices["Desktop Chrome"], baseURL: 'https://lavaangui.org/'
},
},

{
name: "firefox local",
use: { ...devices["Desktop Firefox"], baseURL: 'https://lavaangui.org/' },
},
{
name: 'webkit local',
use: {
...devices['Desktop Safari'], baseURL: 'https://lavaangui.org/'
},
},

/* Test against mobile viewports. */
Expand Down
2 changes: 1 addition & 1 deletion rsconnect/shinyapps.io/solo-fsw/lavaangui.dcf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ account: solo-fsw
server: shinyapps.io
hostUrl: https://api.shinyapps.io/v1
appId: 10373658
bundleId: 8527026
bundleId: 8620648
url: https://solo-fsw.shinyapps.io/lavaangui/

0 comments on commit 5e30237

Please sign in to comment.