From 8b8a2bc4e2b66f4a4c43c0ba1dbe832bb2ac4913 Mon Sep 17 00:00:00 2001 From: Frank Noirot Date: Fri, 10 Jan 2025 16:22:28 -0500 Subject: [PATCH] Add E2E test for "add to existing project" user flow --- e2e/playwright/command-bar-tests.spec.ts | 87 +++++++++++++++++++++++- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/e2e/playwright/command-bar-tests.spec.ts b/e2e/playwright/command-bar-tests.spec.ts index a8aaa2863..37ad8c557 100644 --- a/e2e/playwright/command-bar-tests.spec.ts +++ b/e2e/playwright/command-bar-tests.spec.ts @@ -1,8 +1,8 @@ import { test, expect } from './zoo-test' - -import { getUtils } from './test-utils' +import * as fsp from 'fs/promises' +import { executorInputPath, getUtils } from './test-utils' import { KCL_DEFAULT_LENGTH } from 'lib/constants' -import { url } from 'inspector' +import path from 'path' test.describe('Command bar tests', () => { test('Extrude from command bar selects extrude line after', async ({ @@ -393,4 +393,85 @@ test.describe('Command bar tests', () => { await editor.expectEditor.toContain('extrusionDistance = 12') }) }) + + test(`"import from URL" can add to existing project`, async ({ + page, + cmdBar, + editor, + homePage, + toolbar, + context, + }) => { + await context.folderSetupFn(async (dir) => { + const testProjectDir = path.join(dir, 'testProjectDir') + await Promise.all([fsp.mkdir(testProjectDir, { recursive: true })]) + await Promise.all([ + fsp.copyFile( + executorInputPath('cylinder.kcl'), + path.join(testProjectDir, 'main.kcl') + ), + ]) + }) + await test.step(`Prepare and navigate to home page with query params`, async () => { + const targetURL = `?create-file&name=test&units=mm&code=ZXh0cnVzaW9uRGlzdGFuY2UgPSAxMg%3D%3D&askToOpenInDesktop` + await homePage.expectState({ + projectCards: [ + { + fileCount: 1, + title: 'testProjectDir', + }, + ], + sortBy: 'last-modified-desc', + }) + await page.goto(page.url() + targetURL) + expect(page.url()).toContain(targetURL) + }) + + await test.step(`Submit the command`, async () => { + await cmdBar.expectState({ + stage: 'arguments', + commandName: 'Import file from URL', + currentArgKey: 'method', + currentArgValue: '', + headerArguments: { + Method: '', + Name: 'test', + Code: '1 line', + }, + highlightedHeaderArg: 'method', + }) + await cmdBar.selectOption({ name: 'Existing Project' }).click() + await cmdBar.expectState({ + stage: 'arguments', + commandName: 'Import file from URL', + currentArgKey: 'projectName', + currentArgValue: '', + headerArguments: { + Method: 'Existing project', + Name: 'test', + ProjectName: '', + Code: '1 line', + }, + highlightedHeaderArg: 'projectName', + }) + await cmdBar.selectOption({ name: 'testProjectDir' }).click() + await cmdBar.expectState({ + stage: 'review', + commandName: 'Import file from URL', + headerArguments: { + Method: 'Existing project', + ProjectName: 'testProjectDir', + Name: 'test', + Code: '1 line', + }, + }) + await cmdBar.progressCmdBar() + }) + + await test.step(`Ensure we created the project and are in the modeling scene`, async () => { + await editor.expectEditor.toContain('extrusionDistance = 12') + await toolbar.openPane('files') + await toolbar.expectFileTreeState(['main.kcl', 'test.kcl']) + }) + }) })