From 53e0277acccac401b9bb55a36b545ba4842078ba Mon Sep 17 00:00:00 2001 From: Adam Sunderland Date: Fri, 16 Aug 2024 12:09:02 -0400 Subject: [PATCH] Adding projects folder change test (#3482) * Adding projects folder change test * Missed a bunch of promises that need awaited * Await on electronApp.evaluate too --- .gitignore | 3 +- e2e/playwright/projects.spec.ts | 107 ++++++++++++++++++++++++++++++++ e2e/playwright/test-utils.ts | 3 + flake.nix | 6 ++ playwright.config.ts | 7 +++ src/routes/Home.tsx | 1 + 6 files changed, 126 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 28f97c4de..189108e4a 100644 --- a/.gitignore +++ b/.gitignore @@ -68,4 +68,5 @@ venv out/ src-tauri/target -electron-test-projects-dir \ No newline at end of file +electron-test-projects-dir +electron-test-projects-dir-2 diff --git a/e2e/playwright/projects.spec.ts b/e2e/playwright/projects.spec.ts index 97af8f957..8e97999bd 100644 --- a/e2e/playwright/projects.spec.ts +++ b/e2e/playwright/projects.spec.ts @@ -605,3 +605,110 @@ test( await electronApp.close() } ) + +test( + 'You can change the root projects directory and nothing is lost', + { tag: '@electron' }, + async ({ browserName }, testInfo) => { + const { electronApp, page } = await setupElectron({ + testInfo, + folderSetupFn: async (dir) => { + await Promise.all([ + fsp.mkdir(`${dir}/router-template-slate`, { recursive: true }), + fsp.mkdir(`${dir}/bracket`, { recursive: true }), + ]) + await Promise.all([ + fsp.copyFile( + 'src/wasm-lib/tests/executor/inputs/router-template-slate.kcl', + `${dir}/router-template-slate/main.kcl` + ), + fsp.copyFile( + 'src/wasm-lib/tests/executor/inputs/focusrite_scarlett_mounting_braket.kcl', + `${dir}/bracket/main.kcl` + ), + ]) + }, + }) + await page.setViewportSize({ width: 1200, height: 500 }) + + page.on('console', console.log) + + // we'll grab this from the settings on screen before we switch + let originalProjectDirName: string + const newProjectDirName = testInfo.outputPath( + 'electron-test-projects-dir-2' + ) + if (fs.existsSync(newProjectDirName)) { + await fsp.rm(newProjectDirName, { recursive: true }) + } + + await test.step('We can change the root project directory', async () => { + // expect to see the project directory settings link + await expect( + page.getByTestId('project-directory-settings-link') + ).toBeVisible() + + await page.getByTestId('project-directory-settings-link').click() + + await expect(page.getByTestId('project-directory-button')).toBeVisible() + originalProjectDirName = await page + .locator('section#projectDirectory input') + .inputValue() + + // Can't use Playwright filechooser since this is happening in electron. + const handleFile = electronApp.evaluate( + async ({ dialog }, filePaths) => { + dialog.showOpenDialog = () => + Promise.resolve({ canceled: false, filePaths }) + }, + [newProjectDirName] + ) + await page.getByTestId('project-directory-button').click() + await handleFile + + await expect(page.locator('section#projectDirectory input')).toHaveValue( + newProjectDirName + ) + + await page.getByTestId('settings-close-button').click() + + await expect(page.getByText('No Projects found')).toBeVisible() + await page.getByRole('button', { name: 'New project' }).click() + await expect(page.getByText('Successfully created')).toBeVisible() + await expect(page.getByText('Successfully created')).not.toBeVisible() + + await expect(page.getByText(`project-000`)).toBeVisible() + }) + + await test.step('We can change back to the original root project directory', async () => { + await expect( + page.getByTestId('project-directory-settings-link') + ).toBeVisible() + + await page.getByTestId('project-directory-settings-link').click() + + const handleFile = electronApp.evaluate( + async ({ dialog }, filePaths) => { + dialog.showOpenDialog = () => + Promise.resolve({ canceled: false, filePaths }) + }, + [originalProjectDirName] + ) + await expect(page.getByTestId('project-directory-button')).toBeVisible() + + await page.getByTestId('project-directory-button').click() + await handleFile + + await expect(page.locator('section#projectDirectory input')).toHaveValue( + originalProjectDirName + ) + + await page.getByTestId('settings-close-button').click() + + await expect(page.getByText('bracket')).toBeVisible() + await expect(page.getByText('router-template-slate')).toBeVisible() + }) + + await electronApp.close() + } +) diff --git a/e2e/playwright/test-utils.ts b/e2e/playwright/test-utils.ts index ecfe68a99..3e1a04f7f 100644 --- a/e2e/playwright/test-utils.ts +++ b/e2e/playwright/test-utils.ts @@ -699,6 +699,9 @@ export async function setupElectron({ TEST_SETTINGS_FILE_KEY: projectDirName, IS_PLAYWRIGHT: 'true', }, + ...(process.env.ELECTRON_OVERRIDE_DIST_PATH + ? { executablePath: process.env.ELECTRON_OVERRIDE_DIST_PATH + 'electron' } + : {}), }) const context = electronApp.context() const page = await electronApp.firstWindow() diff --git a/flake.nix b/flake.nix index 9a2f6e533..833b10f12 100644 --- a/flake.nix +++ b/flake.nix @@ -58,7 +58,9 @@ nodejs_22 yarn + electron + playwright-driver.browsers ]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv darwin.apple_sdk.frameworks.Security @@ -67,6 +69,10 @@ TARGET_CC = "${pkgs.stdenv.cc}/bin/${pkgs.stdenv.cc.targetPrefix}cc"; LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; ELECTRON_OVERRIDE_DIST_PATH = "${pkgs.electron}/bin/"; + PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true; + PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH = "${pkgs.playwright-driver.browsers}/chromium-1091/chrome-linux/chrome"; + PLAYWRIGHT_BROWSERS_PATH = "${pkgs.playwright-driver.browsers}"; + NODE_ENV = "development"; }; }); }; diff --git a/playwright.config.ts b/playwright.config.ts index 779811d3c..8813281b6 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -48,6 +48,13 @@ export default defineConfig({ /* Chromium is the only one with these permission types */ permissions: ['clipboard-write', 'clipboard-read'], }, + launchOptions: { + ...(process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH + ? { + executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, + } + : {}), + }, }, // or 'chrome-beta' }, { diff --git a/src/routes/Home.tsx b/src/routes/Home.tsx index c16604474..d9a3c954f 100644 --- a/src/routes/Home.tsx +++ b/src/routes/Home.tsx @@ -280,6 +280,7 @@ const Home = () => {

Loaded from{' '}