Add point-and-click Insert from local project files (#6129)
* WIP: Add point-and-click Import for geometry Will eventually fix #6120 Right now the whole loop is there but the codemod doesn't work yet * Better pathToNOde, log on non-working cm dispatch call * Add workaround to updateModelingState not working * Back to updateModelingState with a skip flag * Better todo * Change working from Import to Insert, cleanups * Sister command in kclCommands to populate file options * Improve path selector * Unsure: move importAstMod to kclCommands onSubmit 😶 * Add e2e test * Clean up for review * Add native file menu entry and test * No await yo lint said so * @lrev-Dev's suggestion to remove a comment Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch> * Update to scene.settled(cmdBar) * Lint --------- Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit is contained in:
		
							
								
								
									
										115
									
								
								e2e/playwright/point-click-assemblies.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								e2e/playwright/point-click-assemblies.spec.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,115 @@
 | 
			
		||||
import * as fsp from 'fs/promises'
 | 
			
		||||
import path from 'path'
 | 
			
		||||
 | 
			
		||||
import { executorInputPath } from '@e2e/playwright/test-utils'
 | 
			
		||||
import { test } from '@e2e/playwright/zoo-test'
 | 
			
		||||
 | 
			
		||||
// test file is for testing point an click code gen functionality that's assemblies related
 | 
			
		||||
test.describe('Point-and-click assemblies tests', () => {
 | 
			
		||||
  test(
 | 
			
		||||
    `Insert kcl part into assembly as whole module import`,
 | 
			
		||||
    { tag: ['@electron'] },
 | 
			
		||||
    async ({
 | 
			
		||||
      context,
 | 
			
		||||
      page,
 | 
			
		||||
      homePage,
 | 
			
		||||
      scene,
 | 
			
		||||
      editor,
 | 
			
		||||
      toolbar,
 | 
			
		||||
      cmdBar,
 | 
			
		||||
      tronApp,
 | 
			
		||||
    }) => {
 | 
			
		||||
      if (!tronApp) {
 | 
			
		||||
        fail()
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      // One dumb hardcoded screen pixel value
 | 
			
		||||
      const testPoint = { x: 575, y: 200 }
 | 
			
		||||
      const initialColor: [number, number, number] = [50, 50, 50]
 | 
			
		||||
      const partColor: [number, number, number] = [150, 150, 150]
 | 
			
		||||
      const tolerance = 50
 | 
			
		||||
 | 
			
		||||
      await test.step('Setup parts and expect empty assembly scene', async () => {
 | 
			
		||||
        const projectName = 'assembly'
 | 
			
		||||
        await context.folderSetupFn(async (dir) => {
 | 
			
		||||
          const bracketDir = path.join(dir, projectName)
 | 
			
		||||
          await fsp.mkdir(bracketDir, { recursive: true })
 | 
			
		||||
          await Promise.all([
 | 
			
		||||
            fsp.copyFile(
 | 
			
		||||
              executorInputPath('cylinder-inches.kcl'),
 | 
			
		||||
              path.join(bracketDir, 'cylinder.kcl')
 | 
			
		||||
            ),
 | 
			
		||||
            fsp.copyFile(
 | 
			
		||||
              executorInputPath('e2e-can-sketch-on-chamfer.kcl'),
 | 
			
		||||
              path.join(bracketDir, 'bracket.kcl')
 | 
			
		||||
            ),
 | 
			
		||||
            fsp.writeFile(path.join(bracketDir, 'main.kcl'), ''),
 | 
			
		||||
          ])
 | 
			
		||||
        })
 | 
			
		||||
        await page.setBodyDimensions({ width: 1000, height: 500 })
 | 
			
		||||
        await homePage.openProject(projectName)
 | 
			
		||||
        await scene.settled(cmdBar)
 | 
			
		||||
        await scene.expectPixelColor(initialColor, testPoint, tolerance)
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
      await test.step('Insert first part into the assembly', async () => {
 | 
			
		||||
        await toolbar.insertButton.click()
 | 
			
		||||
        await cmdBar.selectOption({ name: 'cylinder.kcl' }).click()
 | 
			
		||||
        await cmdBar.expectState({
 | 
			
		||||
          stage: 'arguments',
 | 
			
		||||
          currentArgKey: 'localName',
 | 
			
		||||
          currentArgValue: '',
 | 
			
		||||
          headerArguments: { Path: 'cylinder.kcl', LocalName: '' },
 | 
			
		||||
          highlightedHeaderArg: 'localName',
 | 
			
		||||
          commandName: 'Insert',
 | 
			
		||||
        })
 | 
			
		||||
        await page.keyboard.insertText('cylinder')
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await cmdBar.expectState({
 | 
			
		||||
          stage: 'review',
 | 
			
		||||
          headerArguments: { Path: 'cylinder.kcl', LocalName: 'cylinder' },
 | 
			
		||||
          commandName: 'Insert',
 | 
			
		||||
        })
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await editor.expectEditor.toContain(
 | 
			
		||||
          `
 | 
			
		||||
        import "cylinder.kcl" as cylinder
 | 
			
		||||
        cylinder
 | 
			
		||||
      `,
 | 
			
		||||
          { shouldNormalise: true }
 | 
			
		||||
        )
 | 
			
		||||
        await scene.expectPixelColor(partColor, testPoint, tolerance)
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
      await test.step('Insert second part into the assembly', async () => {
 | 
			
		||||
        await toolbar.insertButton.click()
 | 
			
		||||
        await cmdBar.selectOption({ name: 'bracket.kcl' }).click()
 | 
			
		||||
        await cmdBar.expectState({
 | 
			
		||||
          stage: 'arguments',
 | 
			
		||||
          currentArgKey: 'localName',
 | 
			
		||||
          currentArgValue: '',
 | 
			
		||||
          headerArguments: { Path: 'bracket.kcl', LocalName: '' },
 | 
			
		||||
          highlightedHeaderArg: 'localName',
 | 
			
		||||
          commandName: 'Insert',
 | 
			
		||||
        })
 | 
			
		||||
        await page.keyboard.insertText('bracket')
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await cmdBar.expectState({
 | 
			
		||||
          stage: 'review',
 | 
			
		||||
          headerArguments: { Path: 'bracket.kcl', LocalName: 'bracket' },
 | 
			
		||||
          commandName: 'Insert',
 | 
			
		||||
        })
 | 
			
		||||
        await cmdBar.progressCmdBar()
 | 
			
		||||
        await editor.expectEditor.toContain(
 | 
			
		||||
          `
 | 
			
		||||
        import "cylinder.kcl" as cylinder
 | 
			
		||||
        import "bracket.kcl" as bracket
 | 
			
		||||
        cylinder
 | 
			
		||||
        bracket
 | 
			
		||||
      `,
 | 
			
		||||
          { shouldNormalise: true }
 | 
			
		||||
        )
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
  )
 | 
			
		||||
})
 | 
			
		||||
		Reference in New Issue
	
	Block a user