Fix the last tests and tsc errors

This commit is contained in:
49lf
2024-12-12 23:26:36 -05:00
parent 9249e62b63
commit 4a98e22164
14 changed files with 193 additions and 285 deletions

View File

@ -20,7 +20,7 @@ async function doBasicSketch(
await homePage.goToModelingScene() await homePage.goToModelingScene()
await u.waitForPageLoad() await u.waitForPageLoad()
await page.waitForTimeout() await page.waitForTimeout(1000)
await u.openDebugPanel() await u.openDebugPanel()
// If we have the code pane open, we should see the code. // If we have the code pane open, we should see the code.

View File

@ -80,7 +80,7 @@ test.describe('Command bar tests', () => {
await page.keyboard.press('Enter') // submit await page.keyboard.press('Enter') // submit
await page.waitForTimeout(100) await page.waitForTimeout(100)
await expect(page.locator('.cm-activeLine')).toContainText( await expect(page.locator('.cm-activeLine')).toContainText(
`fillet({ radius: ${KCL_DEFAULT_LENGTH}, tags: [seg01] }, %)` `fillet({ radius = ${KCL_DEFAULT_LENGTH}, tags = [seg01] }, %)`
) )
}) })

View File

@ -453,20 +453,22 @@ test.describe('Editor tests', () => {
homePage, homePage,
}) => { }) => {
const u = await getUtils(page) const u = await getUtils(page)
await page.setBodyDimensions({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
// check no error to begin with // check no error to begin with
await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible() await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible()
/* add the following code to the editor ($ error is not a valid line) /* add the following code to the editor (~ error is not a valid line)
$ error * the old check here used $ but this is for tags so it changed meaning.
* hopefully ~ doesnt change meaning
~ error
const topAng = 30 const topAng = 30
const bottomAng = 25 const bottomAng = 25
*/ */
await u.codeLocator.click() await u.codeLocator.click()
await page.keyboard.type('$ error') await page.keyboard.type('~ error')
// press arrows to clear autocomplete // press arrows to clear autocomplete
await page.keyboard.press('ArrowLeft') await page.keyboard.press('ArrowLeft')
@ -483,10 +485,12 @@ test.describe('Editor tests', () => {
// error text on hover // error text on hover
await page.hover('.cm-lint-marker-error') await page.hover('.cm-lint-marker-error')
await expect(page.getByText('Unexpected token: $').first()).toBeVisible() await expect(
page.getByText("found unknown token '~'").first()
).toBeVisible()
// select the line that's causing the error and delete it // select the line that's causing the error and delete it
await page.getByText('$ error').click() await page.getByText('~ error').click()
await page.keyboard.press('End') await page.keyboard.press('End')
await page.keyboard.down('Shift') await page.keyboard.down('Shift')
await page.keyboard.press('Home') await page.keyboard.press('Home')

View File

@ -21,6 +21,8 @@ export class AuthenticatedApp {
public readonly context: BrowserContext public readonly context: BrowserContext
public readonly testInfo: TestInfo public readonly testInfo: TestInfo
public readonly viewPortSize = { width: 1200, height: 500 } public readonly viewPortSize = { width: 1200, height: 500 }
public electronApp: undefined | ElectronApplication
public dir: string = ''
constructor(context: BrowserContext, page: Page, testInfo: TestInfo) { constructor(context: BrowserContext, page: Page, testInfo: TestInfo) {
this.context = context this.context = context
@ -61,7 +63,7 @@ export class AuthenticatedTronApp {
public page: Page public page: Page
public context: BrowserContext public context: BrowserContext
public readonly testInfo: TestInfo public readonly testInfo: TestInfo
public electronApp?: ElectronApplication public electronApp: ElectronApplication | undefined
public readonly viewPortSize = { width: 1200, height: 500 } public readonly viewPortSize = { width: 1200, height: 500 }
public dir: string = '' public dir: string = ''
@ -79,7 +81,7 @@ export class AuthenticatedTronApp {
appSettings?: Partial<SaveSettingsPayload> appSettings?: Partial<SaveSettingsPayload>
} = { fixtures: {} } } = { fixtures: {} }
) { ) {
const { electronApp, page, context, dir, options } = await setupElectron({ const { electronApp, page, context, dir } = await setupElectron({
testInfo: this.testInfo, testInfo: this.testInfo,
folderSetupFn: arg.folderSetupFn, folderSetupFn: arg.folderSetupFn,
cleanProjectDir: arg.cleanProjectDir, cleanProjectDir: arg.cleanProjectDir,

View File

@ -760,8 +760,9 @@ const loftPointAndClickCases = [
] ]
loftPointAndClickCases.forEach(({ shouldPreselect }) => { loftPointAndClickCases.forEach(({ shouldPreselect }) => {
test(`Loft point-and-click (preselected sketches: ${shouldPreselect})`, async ({ test(`Loft point-and-click (preselected sketches: ${shouldPreselect})`, async ({
app, context,
page, page,
homePage,
scene, scene,
editor, editor,
toolbar, toolbar,
@ -773,7 +774,11 @@ loftPointAndClickCases.forEach(({ shouldPreselect }) => {
sketch002 = startSketchOn(plane001) sketch002 = startSketchOn(plane001)
|> circle({ center = [0, 0], radius = 20 }, %) |> circle({ center = [0, 0], radius = 20 }, %)
` `
await app.initialise(initialCode) await context.addInitScript((initialCode) => {
localStorage.setItem('persistCode', initialCode)
}, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
// One dumb hardcoded screen pixel value // One dumb hardcoded screen pixel value
const testPoint = { x: 575, y: 200 } const testPoint = { x: 575, y: 200 }
@ -792,7 +797,7 @@ loftPointAndClickCases.forEach(({ shouldPreselect }) => {
await clickOnSketch1() await clickOnSketch1()
await page.keyboard.down('Shift') await page.keyboard.down('Shift')
await clickOnSketch2() await clickOnSketch2()
await app.page.waitForTimeout(500) await page.waitForTimeout(500)
await page.keyboard.up('Shift') await page.keyboard.up('Shift')
} }

View File

@ -342,10 +342,10 @@ test(
) )
test( test(
'xxxxx open a file in a project works and renders, open another file in the same project with errors, it should clear the scene', 'open a file in a project works and renders, open another file in the same project with errors, it should clear the scene',
{ tag: '@electron' }, { tag: '@electron' },
async ({ context, page }, testInfo) => { async ({ context, page }, testInfo) => {
const { dir } = await context.folderSetupFn(async (dir) => { await context.folderSetupFn(async (dir) => {
const bracketDir = path.join(dir, 'bracket') const bracketDir = path.join(dir, 'bracket')
await fsp.mkdir(bracketDir, { recursive: true }) await fsp.mkdir(bracketDir, { recursive: true })
await fsp.copyFile( await fsp.copyFile(

View File

@ -586,7 +586,7 @@ extrude001 = extrude(50, sketch001)
timeout: 5000, timeout: 5000,
message: 'Plane color is visible', message: 'Plane color is visible',
}) })
.toBeLessThan(15) .toBeLessThanOrEqual(15)
let maxZoomOuts = 10 let maxZoomOuts = 10
let middlePixelIsBackgroundColor = let middlePixelIsBackgroundColor =

View File

@ -3,6 +3,7 @@ import {
BrowserContext, BrowserContext,
TestInfo, TestInfo,
_electron as electron, _electron as electron,
ElectronApplication,
Locator, Locator,
} from '@playwright/test' } from '@playwright/test'
import { test, Page } from './zoo-test' import { test, Page } from './zoo-test'
@ -28,130 +29,6 @@ import { isErrorWhitelisted } from './lib/console-error-whitelist'
import { isArray } from 'lib/utils' import { isArray } from 'lib/utils'
import { reportRejection } from 'lib/trap' import { reportRejection } from 'lib/trap'
// The below is copied from playwright-core because it exports none of them :(
import { Env, BrowserContextOptions } from 'playwright-core'
import type * as channels from '@protocol/channels'
// Copied from playwright-core
function envObjectToArray(env: Env): { name: string; value: string }[] {
const result: { name: string; value: string }[] = []
for (const name in env) {
if (!Object.is(env[name], undefined))
result.push({ name, value: String(env[name]) })
}
return result
}
// Copied from playwright-core
export async function toClientCertificatesProtocol(
certs?: BrowserContextOptions['clientCertificates']
): Promise<channels.PlaywrightNewRequestParams['clientCertificates']> {
if (!certs) return undefined
const bufferizeContent = async (
value?: Buffer,
path?: string
): Promise<Buffer | undefined> => {
if (value) return value
if (path) return await fs.promises.readFile(path)
}
return await Promise.all(
certs.map(async (cert) => ({
origin: cert.origin,
cert: await bufferizeContent(cert.cert, cert.certPath),
key: await bufferizeContent(cert.key, cert.keyPath),
pfx: await bufferizeContent(cert.pfx, cert.pfxPath),
passphrase: cert.passphrase,
}))
)
}
// Copied from playwright-core
function toAcceptDownloadsProtocol(acceptDownloads?: boolean) {
if (acceptDownloads === undefined) return undefined
if (acceptDownloads) return 'accept'
return 'deny'
}
// Copied from playwright-core
function prepareRecordHarOptions(
options: BrowserContextOptions['recordHar']
): channels.RecordHarOptions | undefined {
if (!options) return
return {
path: options.path,
content: options.content || (options.omitContent ? 'omit' : undefined),
urlGlob: isString(options.urlFilter) ? options.urlFilter : undefined,
urlRegexSource: isRegExp(options.urlFilter)
? options.urlFilter.source
: undefined,
urlRegexFlags: isRegExp(options.urlFilter)
? options.urlFilter.flags
: undefined,
mode: options.mode,
}
}
// Copied from playwright-core
async function prepareStorageState(
options: BrowserContextOptions
): Promise<channels.BrowserNewContextParams['storageState']> {
if (typeof options.storageState !== 'string') return options.storageState
try {
return JSON.parse(await fs.promises.readFile(options.storageState, 'utf8'))
} catch (e) {
rewriteErrorMessage(
e,
`Error reading storage state from ${options.storageState}:\n` + e.message
)
throw e
}
}
// Copied from playwright-core
async function prepareBrowserContextParams(
options: BrowserContextOptions
): Promise<channels.BrowserNewContextParams> {
if (options.videoSize && !options.videosPath)
throw new Error(`"videoSize" option requires "videosPath" to be specified`)
if (options.extraHTTPHeaders)
network.validateHeaders(options.extraHTTPHeaders)
const contextParams: channels.BrowserNewContextParams = {
...options,
viewport: options.viewport === null ? undefined : options.viewport,
noDefaultViewport: options.viewport === null,
extraHTTPHeaders: options.extraHTTPHeaders
? headersObjectToArray(options.extraHTTPHeaders)
: undefined,
storageState: await prepareStorageState(options),
serviceWorkers: options.serviceWorkers,
recordHar: prepareRecordHarOptions(options.recordHar),
colorScheme:
options.colorScheme === null ? 'no-override' : options.colorScheme,
reducedMotion:
options.reducedMotion === null ? 'no-override' : options.reducedMotion,
forcedColors:
options.forcedColors === null ? 'no-override' : options.forcedColors,
acceptDownloads: toAcceptDownloadsProtocol(options.acceptDownloads),
clientCertificates: await toClientCertificatesProtocol(
options.clientCertificates
),
}
if (!contextParams.recordVideo && options.videosPath) {
contextParams.recordVideo = {
dir: options.videosPath,
size: options.videoSize,
}
}
if (contextParams.recordVideo && contextParams.recordVideo.dir)
contextParams.recordVideo.dir = path.resolve(
process.cwd(),
contextParams.recordVideo.dir
)
return contextParams
}
const toNormalizedCode = (text: string) => { const toNormalizedCode = (text: string) => {
return text.replace(/\s+/g, '') return text.replace(/\s+/g, '')
} }
@ -1042,9 +919,9 @@ export async function setup(
// await page.reload() // await page.reload()
} }
let electronApp = undefined let electronApp: ElectronApplication | undefined = undefined
let context = undefined let context: BrowserContext | undefined = undefined
let page = undefined let page: Page | undefined = undefined
export async function setupElectron({ export async function setupElectron({
testInfo, testInfo,
@ -1055,7 +932,12 @@ export async function setupElectron({
folderSetupFn?: (projectDirName: string) => Promise<void> folderSetupFn?: (projectDirName: string) => Promise<void>
cleanProjectDir?: boolean cleanProjectDir?: boolean
appSettings?: Partial<SaveSettingsPayload> appSettings?: Partial<SaveSettingsPayload>
}) { }): Promise<{
electronApp: ElectronApplication
context: BrowserContext
page: Page
dir: string
}> {
// create or otherwise clear the folder // create or otherwise clear the folder
const projectDirName = testInfo.outputPath('electron-test-projects-dir') const projectDirName = testInfo.outputPath('electron-test-projects-dir')
try { try {
@ -1122,7 +1004,7 @@ export async function setupElectron({
await fsp.writeFile(tempSettingsFilePath, settingsOverrides) await fsp.writeFile(tempSettingsFilePath, settingsOverrides)
} }
return { electronApp, page, context, dir: projectDirName, options } return { electronApp, page, context, dir: projectDirName }
} }
function failOnConsoleErrors(page: Page, testInfo?: TestInfo) { function failOnConsoleErrors(page: Page, testInfo?: TestInfo) {

View File

@ -23,7 +23,7 @@ test.describe('Testing constraints', () => {
const u = await getUtils(page) const u = await getUtils(page)
const PUR = 400 / 37.5 //pixeltoUnitRatio const PUR = 400 / 37.5 //pixeltoUnitRatio
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await u.waitForPageLoad() await u.waitForPageLoad()
@ -43,15 +43,16 @@ test.describe('Testing constraints', () => {
await page.waitForTimeout(1000) await page.waitForTimeout(1000)
const startXPx = 500 const startXPx = 500
await page.mouse.move(startXPx + PUR * 15, 250 - PUR * 10)
await page.keyboard.down('Shift')
await page.mouse.click(834, 244)
await page.keyboard.up('Shift')
await page.getByText(`line([0, 20], %)`).click()
await page.waitForTimeout(100)
await page.getByTestId('constraint-length').click()
await page.getByTestId('cmd-bar-arg-value').getByRole('textbox').fill('20')
await page await page
.getByRole('button', { name: 'dimension Length', exact: true }) .getByRole('button', {
name: 'arrow right Continue',
})
.click() .click()
await page.getByText('Add constraining value').click()
await expect(page.locator('.cm-content')).toHaveText( await expect(page.locator('.cm-content')).toHaveText(
`length001 = 20sketch001 = startSketchOn('XY') |> startProfileAt([-10, -10], %) |> line([20, 0], %) |> angledLine([90, length001], %) |> xLine(-20, %)` `length001 = 20sketch001 = startSketchOn('XY') |> startProfileAt([-10, -10], %) |> line([20, 0], %) |> angledLine([90, length001], %) |> xLine(-20, %)`
@ -71,7 +72,7 @@ test.describe('Testing constraints', () => {
await page.keyboard.press('Escape', { delay: 500 }) await page.keyboard.press('Escape', { delay: 500 })
return page.getByRole('button', { name: 'Exit Sketch' }).isVisible() return page.getByRole('button', { name: 'Exit Sketch' }).isVisible()
}) })
.toBe(true) .toBe(false)
}) })
test(`Remove constraints`, async ({ page, homePage }) => { test(`Remove constraints`, async ({ page, homePage }) => {
await page.addInitScript(async () => { await page.addInitScript(async () => {
@ -1013,7 +1014,7 @@ part002 = startSketchOn('XZ')
) )
}) })
const u = await getUtils(page) const u = await getUtils(page)
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await u.waitForPageLoad() await u.waitForPageLoad()
@ -1088,8 +1089,12 @@ part002 = startSketchOn('XZ')
// await page.getByRole('button', { name: 'length', exact: true }).click() // await page.getByRole('button', { name: 'length', exact: true }).click()
await page.getByTestId('dropdown-constraint-length').click() await page.getByTestId('dropdown-constraint-length').click()
await page.getByLabel('length Value').fill('10') await page.getByTestId('cmd-bar-arg-value').getByRole('textbox').fill('10')
await page.getByRole('button', { name: 'Add constraining value' }).click() await page
.getByRole('button', {
name: 'arrow right Continue',
})
.click()
await pollEditorLinesSelectedLength(page, 1) await pollEditorLinesSelectedLength(page, 1)
activeLinesContent = await page.locator('.cm-activeLine').all() activeLinesContent = await page.locator('.cm-activeLine').all()

View File

@ -299,9 +299,10 @@ test.describe('Testing segment overlays', () => {
hoverPos: { x: angledLine.x, y: angledLine.y }, hoverPos: { x: angledLine.x, y: angledLine.y },
constraintType: 'angle', constraintType: 'angle',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'angledLine({ angle: 3 + 0, length: 32 + 0 }, %)', 'angledLine({ angle = 3 + 0, length = 32 + 0 }, %)',
expectAfterUnconstrained: 'angledLine({ angle: 3, length: 32 + 0 }, %)', expectAfterUnconstrained:
expectFinal: 'angledLine({ angle: angle001, length: 32 + 0 }, %)', 'angledLine({ angle = 3, length = 32 + 0 }, %)',
expectFinal: 'angledLine({ angle = angle001, length = 32 + 0 }, %)',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="1"]', locator: '[data-overlay-toolbar-index="1"]',
}) })
@ -310,10 +311,10 @@ test.describe('Testing segment overlays', () => {
hoverPos: { x: angledLine.x, y: angledLine.y }, hoverPos: { x: angledLine.x, y: angledLine.y },
constraintType: 'length', constraintType: 'length',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'angledLine({ angle: angle001, length: 32 + 0 }, %)', 'angledLine({ angle = angle001, length = 32 + 0 }, %)',
expectAfterUnconstrained: expectAfterUnconstrained:
'angledLine({ angle: angle001, length: 32 }, %)', 'angledLine({ angle = angle001, length = 32 }, %)',
expectFinal: 'angledLine({ angle: angle001, length: len001 }, %)', expectFinal: 'angledLine({ angle = angle001, length = len001 }, %)',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="1"]', locator: '[data-overlay-toolbar-index="1"]',
}) })
@ -360,15 +361,15 @@ test.describe('Testing segment overlays', () => {
locator: '[data-overlay-toolbar-index="3"]', locator: '[data-overlay-toolbar-index="3"]',
}) })
}) })
test('for segments [yLineTo, xLine]', async ({
page, // Broken on main at time of writing!
editor, test.fixme(
homePage, 'for segments [yLineTo, xLine]',
}) => { async ({ page, editor, homePage }) => {
await page.addInitScript(async () => { await page.addInitScript(async () => {
localStorage.setItem( localStorage.setItem(
'persistCode', 'persistCode',
`yRel001 = -14 `yRel001 = -14
xRel001 = 0.5 xRel001 = 0.5
angle001 = 3 angle001 = 3
len001 = 32 len001 = 32
@ -386,59 +387,60 @@ test.describe('Testing segment overlays', () => {
|> yLine(21.14 + 0, %) |> yLine(21.14 + 0, %)
|> angledLineOfXLength({ angle = 181 + 0, length = 23.14 }, %) |> angledLineOfXLength({ angle = 181 + 0, length = 23.14 }, %)
` `
) )
}) })
const u = await getUtils(page) const u = await getUtils(page)
await page.setViewportSize({ width: 1200, height: 500 }) await page.setViewportSize({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
// wait for execution done // wait for execution done
await u.openDebugPanel() await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]') await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel() await u.closeDebugPanel()
await page.getByText('xLine(26.04, %)').click() await page.getByText('xLine(26.04, %)').click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.getByRole('button', { name: 'Edit Sketch' }).click() await page.getByRole('button', { name: 'Edit Sketch' }).click()
await page.waitForTimeout(500) await page.waitForTimeout(500)
await expect(page.getByTestId('segment-overlay')).toHaveCount(8) await expect(page.getByTestId('segment-overlay')).toHaveCount(8)
const clickUnconstrained = _clickUnconstrained(page, editor) const clickUnconstrained = _clickUnconstrained(page, editor)
await page.mouse.move(700, 250) await page.mouse.move(700, 250)
await page.waitForTimeout(100) await page.waitForTimeout(100)
let ang = 0 let ang = 0
const yLineTo = await u.getBoundingBox(`[data-overlay-index="4"]`) const yLineTo = await u.getBoundingBox(`[data-overlay-index="4"]`)
ang = await u.getAngle(`[data-overlay-index="4"]`) ang = await u.getAngle(`[data-overlay-index="4"]`)
console.log('ylineTo1') console.log('ylineTo1')
await clickUnconstrained({ await clickUnconstrained({
hoverPos: { x: yLineTo.x, y: yLineTo.y }, hoverPos: { x: yLineTo.x, y: yLineTo.y - 200 },
constraintType: 'yAbsolute', constraintType: 'yAbsolute',
expectBeforeUnconstrained: 'yLineTo(-10.77, %, $a)', expectBeforeUnconstrained: 'yLineTo(-10.77, %, $a)',
expectAfterUnconstrained: 'yLineTo(yAbs002, %, $a)', expectAfterUnconstrained: 'yLineTo(yAbs002, %, $a)',
expectFinal: 'yLineTo(-10.77, %, $a)', expectFinal: 'yLineTo(-10.77, %, $a)',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="4"]', locator: '[data-overlay-toolbar-index="4"]',
}) })
const xLine = await u.getBoundingBox(`[data-overlay-index="5"]`) const xLine = await u.getBoundingBox(`[data-overlay-index="5"]`)
ang = await u.getAngle(`[data-overlay-index="5"]`) ang = await u.getAngle(`[data-overlay-index="5"]`)
console.log('xline') console.log('xline')
await clickUnconstrained({ await clickUnconstrained({
hoverPos: { x: xLine.x, y: xLine.y }, hoverPos: { x: xLine.x, y: xLine.y },
constraintType: 'xRelative', constraintType: 'xRelative',
expectBeforeUnconstrained: 'xLine(26.04, %)', expectBeforeUnconstrained: 'xLine(26.04, %)',
expectAfterUnconstrained: 'xLine(xRel002, %)', expectAfterUnconstrained: 'xLine(xRel002, %)',
expectFinal: 'xLine(26.04, %)', expectFinal: 'xLine(26.04, %)',
steps: 10, steps: 10,
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="5"]', locator: '[data-overlay-toolbar-index="5"]',
}) })
}) }
)
test('for segments [yLine, angledLineOfXLength, angledLineOfYLength]', async ({ test('for segments [yLine, angledLineOfXLength, angledLineOfYLength]', async ({
page, page,
editor, editor,
@ -515,11 +517,11 @@ test.describe('Testing segment overlays', () => {
hoverPos: { x: angledLineOfXLength.x, y: angledLineOfXLength.y }, hoverPos: { x: angledLineOfXLength.x, y: angledLineOfXLength.y },
constraintType: 'angle', constraintType: 'angle',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'angledLineOfXLength({ angle: 181 + 0, length: 23.14 }, %)', 'angledLineOfXLength({ angle = 181 + 0, length = 23.14 }, %)',
expectAfterUnconstrained: expectAfterUnconstrained:
'angledLineOfXLength({ angle: -179, length: 23.14 }, %)', 'angledLineOfXLength({ angle = -179, length = 23.14 }, %)',
expectFinal: expectFinal:
'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)', 'angledLineOfXLength({ angle = angle001, length = 23.14 }, %)',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="7"]', locator: '[data-overlay-toolbar-index="7"]',
}) })
@ -528,11 +530,11 @@ test.describe('Testing segment overlays', () => {
hoverPos: { x: angledLineOfXLength.x, y: angledLineOfXLength.y }, hoverPos: { x: angledLineOfXLength.x, y: angledLineOfXLength.y },
constraintType: 'xRelative', constraintType: 'xRelative',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)', 'angledLineOfXLength({ angle = angle001, length = 23.14 }, %)',
expectAfterUnconstrained: expectAfterUnconstrained:
'angledLineOfXLength({ angle: angle001, length: xRel001 }, %)', 'angledLineOfXLength({ angle = angle001, length = xRel001 }, %)',
expectFinal: expectFinal:
'angledLineOfXLength({ angle: angle001, length: 23.14 }, %)', 'angledLineOfXLength({ angle = angle001, length = 23.14 }, %)',
steps: 7, steps: 7,
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="7"]', locator: '[data-overlay-toolbar-index="7"]',
@ -547,10 +549,10 @@ test.describe('Testing segment overlays', () => {
hoverPos: { x: angledLineOfYLength.x, y: angledLineOfYLength.y }, hoverPos: { x: angledLineOfYLength.x, y: angledLineOfYLength.y },
constraintType: 'angle', constraintType: 'angle',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', 'angledLineOfYLength({ angle = -91, length = 19 + 0 }, %)',
expectAfterUnconstrained: expectAfterUnconstrained:
'angledLineOfYLength({ angle: angle002, length: 19 + 0 }, %)', 'angledLineOfYLength({ angle = angle002, length = 19 + 0 }, %)',
expectFinal: 'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', expectFinal: 'angledLineOfYLength({ angle = -91, length = 19 + 0 }, %)',
ang: ang + 180, ang: ang + 180,
steps: 6, steps: 6,
locator: '[data-overlay-toolbar-index="8"]', locator: '[data-overlay-toolbar-index="8"]',
@ -560,10 +562,11 @@ test.describe('Testing segment overlays', () => {
hoverPos: { x: angledLineOfYLength.x, y: angledLineOfYLength.y }, hoverPos: { x: angledLineOfYLength.x, y: angledLineOfYLength.y },
constraintType: 'yRelative', constraintType: 'yRelative',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', 'angledLineOfYLength({ angle = -91, length = 19 + 0 }, %)',
expectAfterUnconstrained: expectAfterUnconstrained:
'angledLineOfYLength({ angle: -91, length: 19 }, %)', 'angledLineOfYLength({ angle = -91, length = 19 }, %)',
expectFinal: 'angledLineOfYLength({ angle: -91, length: yRel002 }, %)', expectFinal:
'angledLineOfYLength({ angle = -91, length = yRel002 }, %)',
ang: ang + 180, ang: ang + 180,
steps: 7, steps: 7,
locator: '[data-overlay-toolbar-index="8"]', locator: '[data-overlay-toolbar-index="8"]',
@ -628,9 +631,10 @@ test.describe('Testing segment overlays', () => {
await clickConstrained({ await clickConstrained({
hoverPos: { x: angledLineToX.x, y: angledLineToX.y }, hoverPos: { x: angledLineToX.x, y: angledLineToX.y },
constraintType: 'angle', constraintType: 'angle',
expectBeforeUnconstrained: 'angledLineToX({ angle: 3 + 0, to: 26 }, %)', expectBeforeUnconstrained:
expectAfterUnconstrained: 'angledLineToX({ angle: 3, to: 26 }, %)', 'angledLineToX({ angle = 3 + 0, to = 26 }, %)',
expectFinal: 'angledLineToX({ angle: angle001, to: 26 }, %)', expectAfterUnconstrained: 'angledLineToX({ angle = 3, to = 26 }, %)',
expectFinal: 'angledLineToX({ angle = angle001, to = 26 }, %)',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="9"]', locator: '[data-overlay-toolbar-index="9"]',
}) })
@ -639,10 +643,10 @@ test.describe('Testing segment overlays', () => {
hoverPos: { x: angledLineToX.x, y: angledLineToX.y }, hoverPos: { x: angledLineToX.x, y: angledLineToX.y },
constraintType: 'xAbsolute', constraintType: 'xAbsolute',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'angledLineToX({ angle: angle001, to: 26 }, %)', 'angledLineToX({ angle = angle001, to = 26 }, %)',
expectAfterUnconstrained: expectAfterUnconstrained:
'angledLineToX({ angle: angle001, to: xAbs001 }, %)', 'angledLineToX({ angle = angle001, to = xAbs001 }, %)',
expectFinal: 'angledLineToX({ angle: angle001, to: 26 }, %)', expectFinal: 'angledLineToX({ angle = angle001, to = 26 }, %)',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="9"]', locator: '[data-overlay-toolbar-index="9"]',
}) })
@ -654,10 +658,10 @@ test.describe('Testing segment overlays', () => {
hoverPos: { x: angledLineToY.x, y: angledLineToY.y }, hoverPos: { x: angledLineToY.x, y: angledLineToY.y },
constraintType: 'angle', constraintType: 'angle',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', 'angledLineToY({ angle = 89, to = 9.14 + 0 }, %)',
expectAfterUnconstrained: expectAfterUnconstrained:
'angledLineToY({ angle: angle002, to: 9.14 + 0 }, %)', 'angledLineToY({ angle = angle002, to = 9.14 + 0 }, %)',
expectFinal: 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', expectFinal: 'angledLineToY({ angle = 89, to = 9.14 + 0 }, %)',
steps: process.platform === 'darwin' ? 8 : 9, steps: process.platform === 'darwin' ? 8 : 9,
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="10"]', locator: '[data-overlay-toolbar-index="10"]',
@ -667,9 +671,9 @@ test.describe('Testing segment overlays', () => {
hoverPos: { x: angledLineToY.x, y: angledLineToY.y }, hoverPos: { x: angledLineToY.x, y: angledLineToY.y },
constraintType: 'yAbsolute', constraintType: 'yAbsolute',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', 'angledLineToY({ angle = 89, to = 9.14 + 0 }, %)',
expectAfterUnconstrained: 'angledLineToY({ angle: 89, to: 9.14 }, %)', expectAfterUnconstrained: 'angledLineToY({ angle = 89, to = 9.14 }, %)',
expectFinal: 'angledLineToY({ angle: 89, to: yAbs001 }, %)', expectFinal: 'angledLineToY({ angle = 89, to = yAbs001 }, %)',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="10"]', locator: '[data-overlay-toolbar-index="10"]',
}) })
@ -828,7 +832,7 @@ test.describe('Testing segment overlays', () => {
await u.closeDebugPanel() await u.closeDebugPanel()
await page await page
.getByText('circle({ center: [1 + 0, 0], radius: 8 }, %)') .getByText('circle({ center = [1 + 0, 0], radius = 8 }, %)')
.click() .click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.getByRole('button', { name: 'Edit Sketch' }).click() await page.getByRole('button', { name: 'Edit Sketch' }).click()
@ -847,9 +851,9 @@ test.describe('Testing segment overlays', () => {
hoverPos, hoverPos,
constraintType: 'xAbsolute', constraintType: 'xAbsolute',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'circle({ center: [1 + 0, 0], radius: 8 }, %)', 'circle({ center = [1 + 0, 0], radius = 8 }, %)',
expectAfterUnconstrained: 'circle({ center: [1, 0], radius: 8 }, %)', expectAfterUnconstrained: 'circle({ center = [1, 0], radius = 8 }, %)',
expectFinal: 'circle({ center: [xAbs001, 0], radius: 8 }, %)', expectFinal: 'circle({ center = [xAbs001, 0], radius = 8 }, %)',
ang: ang + 105, ang: ang + 105,
steps: 6, steps: 6,
locator: '[data-overlay-toolbar-index="0"]', locator: '[data-overlay-toolbar-index="0"]',
@ -859,7 +863,7 @@ test.describe('Testing segment overlays', () => {
hoverPos, hoverPos,
constraintType: 'yAbsolute', constraintType: 'yAbsolute',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'circle({ center: [xAbs001, 0], radius: 8 }, %)', 'circle({ center = [xAbs001, 0], radius = 8 }, %)',
expectAfterUnconstrained: expectAfterUnconstrained:
'circle({ center = [xAbs001, yAbs001], radius = 8 }, %)', 'circle({ center = [xAbs001, yAbs001], radius = 8 }, %)',
expectFinal: 'circle({ center = [xAbs001, 0], radius = 8 }, %)', expectFinal: 'circle({ center = [xAbs001, 0], radius = 8 }, %)',
@ -872,10 +876,10 @@ test.describe('Testing segment overlays', () => {
hoverPos, hoverPos,
constraintType: 'radius', constraintType: 'radius',
expectBeforeUnconstrained: expectBeforeUnconstrained:
'circle({ center: [xAbs001, 0], radius: 8 }, %)', 'circle({ center = [xAbs001, 0], radius = 8 }, %)',
expectAfterUnconstrained: expectAfterUnconstrained:
'circle({ center: [xAbs001, 0], radius: radius001 }, %)', 'circle({ center = [xAbs001, 0], radius = radius001 }, %)',
expectFinal: 'circle({ center: [xAbs001, 0], radius: 8 }, %)', expectFinal: 'circle({ center = [xAbs001, 0], radius = 8 }, %)',
ang: ang + 105, ang: ang + 105,
steps: 10, steps: 10,
locator: '[data-overlay-toolbar-index="0"]', locator: '[data-overlay-toolbar-index="0"]',
@ -1003,7 +1007,7 @@ test.describe('Testing segment overlays', () => {
ang = await u.getAngle(`[data-overlay-index="${10}"]`) ang = await u.getAngle(`[data-overlay-index="${10}"]`)
await deleteSegmentSequence({ await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y },
codeToBeDeleted: 'angledLineToY({ angle: 89, to: 9.14 + 0 }, %)', codeToBeDeleted: 'angledLineToY({ angle = 89, to = 9.14 + 0 }, %)',
stdLibFnName: 'angledLineToY', stdLibFnName: 'angledLineToY',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="10"]', locator: '[data-overlay-toolbar-index="10"]',
@ -1013,7 +1017,7 @@ test.describe('Testing segment overlays', () => {
ang = await u.getAngle(`[data-overlay-index="${9}"]`) ang = await u.getAngle(`[data-overlay-index="${9}"]`)
await deleteSegmentSequence({ await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y },
codeToBeDeleted: 'angledLineToX({ angle: 3 + 0, to: 26 }, %)', codeToBeDeleted: 'angledLineToX({ angle = 3 + 0, to = 26 }, %)',
stdLibFnName: 'angledLineToX', stdLibFnName: 'angledLineToX',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="9"]', locator: '[data-overlay-toolbar-index="9"]',
@ -1024,7 +1028,7 @@ test.describe('Testing segment overlays', () => {
await deleteSegmentSequence({ await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y },
codeToBeDeleted: codeToBeDeleted:
'angledLineOfYLength({ angle: -91, length: 19 + 0 }, %)', 'angledLineOfYLength({ angle = -91, length = 19 + 0 }, %)',
stdLibFnName: 'angledLineOfYLength', stdLibFnName: 'angledLineOfYLength',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="8"]', locator: '[data-overlay-toolbar-index="8"]',
@ -1035,7 +1039,7 @@ test.describe('Testing segment overlays', () => {
await deleteSegmentSequence({ await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y },
codeToBeDeleted: codeToBeDeleted:
'angledLineOfXLength({ angle: 181 + 0, length: 23.14 }, %)', 'angledLineOfXLength({ angle = 181 + 0, length = 23.14 }, %)',
stdLibFnName: 'angledLineOfXLength', stdLibFnName: 'angledLineOfXLength',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="7"]', locator: '[data-overlay-toolbar-index="7"]',
@ -1118,7 +1122,7 @@ test.describe('Testing segment overlays', () => {
ang = await u.getAngle(`[data-overlay-index="${1}"]`) ang = await u.getAngle(`[data-overlay-index="${1}"]`)
await deleteSegmentSequence({ await deleteSegmentSequence({
hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y }, hoverPos: { x: segmentToDelete.x, y: segmentToDelete.y },
codeToBeDeleted: 'angledLine({ angle: 3 + 0, length: 32 + 0 }, %)', codeToBeDeleted: 'angledLine({ angle = 3 + 0, length = 32 + 0 }, %)',
stdLibFnName: 'angledLine', stdLibFnName: 'angledLine',
ang: ang + 180, ang: ang + 180,
locator: '[data-overlay-toolbar-index="1"]', locator: '[data-overlay-toolbar-index="1"]',
@ -1301,7 +1305,7 @@ test.describe('Testing segment overlays', () => {
] ]
for (const { before, after } of cases) { for (const { before, after } of cases) {
const isObj = before.includes('{ angle: 3') const isObj = before.includes('{ angle = 3')
test(`${before.split('(')[0]}${isObj ? '-[obj-input]' : ''}`, async ({ test(`${before.split('(')[0]}${isObj ? '-[obj-input]' : ''}`, async ({
page, page,
editor, editor,

View File

@ -644,7 +644,7 @@ test.describe('Testing selections', () => {
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'flatExtrusionFace', 'flatExtrusionFace',
flatExtrusionFace, flatExtrusionFace,
`angledLineThatIntersects({angle:3.14,intersectTag:a,offset:0},%)extrude(5+7,%)`, `angledLineThatIntersects({angle=3.14,intersectTag=a,offset=0},%)extrude(5+7,%)`,
'}, %)' '}, %)'
) )
@ -701,19 +701,19 @@ test.describe('Testing selections', () => {
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'straightSegmentEdge', 'straightSegmentEdge',
straightSegmentEdge, straightSegmentEdge,
`angledLineToY({angle:30,to:11.14},%)`, `angledLineToY({angle=30,to=11.14},%)`,
'angledLineToY({ angle: 30, to: 11.14 }, %)' 'angledLineToY({ angle = 30, to = 11.14 }, %)'
) )
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'straightSegmentOppositeEdge', 'straightSegmentOppositeEdge',
straightSegmentOppositeEdge, straightSegmentOppositeEdge,
`angledLineToY({angle:30,to:11.14},%)`, `angledLineToY({angle=30,to=11.14},%)`,
'angledLineToY({ angle: 30, to: 11.14 }, %)' 'angledLineToY({ angle = 30, to = 11.14 }, %)'
) )
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'straightSegmentAdjacentEdge', 'straightSegmentAdjacentEdge',
straightSegmentAdjacentEdge, straightSegmentAdjacentEdge,
`angledLineThatIntersects({angle:3.14,intersectTag:a,offset:0},%)`, `angledLineThatIntersects({angle=3.14,intersectTag=a,offset=0},%)`,
'}, %)' '}, %)'
) )
@ -780,14 +780,14 @@ test.describe('Testing selections', () => {
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'oppositeChamfer', 'oppositeChamfer',
oppositeChamfer, oppositeChamfer,
`angledLine([segAng(rectangleSegmentA001)-90,217.26],%,$seg01)chamfer({length:30,tags:[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`, `angledLine([segAng(rectangleSegmentA001)-90,217.26],%,$seg01)chamfer({length=30,tags=[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`,
'}, %)' '}, %)'
) )
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'baseChamfer', 'baseChamfer',
baseChamfer, baseChamfer,
`angledLine([segAng(rectangleSegmentA001)-90,217.26],%,$seg01)chamfer({length:30,tags:[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`, `angledLine([segAng(rectangleSegmentA001)-90,217.26],%,$seg01)chamfer({length=30,tags=[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`,
'}, %)' '}, %)'
) )
@ -818,14 +818,14 @@ test.describe('Testing selections', () => {
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'adjacentChamfer1', 'adjacentChamfer1',
adjacentChamfer1, adjacentChamfer1,
`lineTo([profileStartX(%),profileStartY(%)],%,$seg02)chamfer({length:30,tags:[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`, `lineTo([profileStartX(%),profileStartY(%)],%,$seg02)chamfer({length=30,tags=[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`,
'}, %)' '}, %)'
) )
await checkCodeAtHoverPosition( await checkCodeAtHoverPosition(
'adjacentChamfer2', 'adjacentChamfer2',
adjacentChamfer2, adjacentChamfer2,
`angledLine([segAng(rectangleSegmentA001),-segLen(rectangleSegmentA001)],%,$yo)chamfer({length:30,tags:[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`, `angledLine([segAng(rectangleSegmentA001),-segLen(rectangleSegmentA001)],%,$yo)chamfer({length=30,tags=[seg01,getNextAdjacentEdge(yo),getNextAdjacentEdge(seg02),getOppositeEdge(seg01)]},%)`,
'}, %)' '}, %)'
) )
}) })

View File

@ -242,8 +242,8 @@ export const test = (
// return app.reuseWindowForTest(); // return app.reuseWindowForTest();
// }); // });
await tronApp.electronApp.evaluate(({ app }, projectDirName) => { await tronApp.electronApp?.evaluate(({ app }, projectDirName) => {
console.log('ABCDEFGHI', app.testProperty['TEST_SETTINGS_FILE_KEY']) // @ts-ignore can't declaration merge see main.ts
app.testProperty['TEST_SETTINGS_FILE_KEY'] = projectDirName app.testProperty['TEST_SETTINGS_FILE_KEY'] = projectDirName
}, tronApp.dir) }, tronApp.dir)

1
interface.d.ts vendored
View File

@ -80,6 +80,7 @@ export interface IElectronAPI {
onUpdateError: (callback: (value: { error: Error }) => void) => Electron onUpdateError: (callback: (value: { error: Error }) => void) => Electron
appRestart: () => void appRestart: () => void
getArgvParsed: () => any getArgvParsed: () => any
getAppTestProperty: (propertyName: string) => any
} }
declare global { declare global {

View File

@ -62,26 +62,29 @@ if (process.defaultApp) {
registerStartupListeners() registerStartupListeners()
const createWindow = (filePath?: string, reuse?: boolean): BrowserWindow => { const createWindow = (filePath?: string, reuse?: boolean): BrowserWindow => {
const newWindow = reuse let newWindow
? mainWindow
: new BrowserWindow({ if (reuse) {
autoHideMenuBar: true, newWindow = mainWindow
show: false, }
width: 1800, if (!newWindow) {
height: 1200, newWindow = new BrowserWindow({
webPreferences: { autoHideMenuBar: true,
nodeIntegration: false, // do not give the application implicit system access show: false,
contextIsolation: true, // expose system functions in preload width: 1800,
sandbox: false, // expose nodejs in preload height: 1200,
preload: path.join(__dirname, './preload.js'), webPreferences: {
}, nodeIntegration: false, // do not give the application implicit system access
icon: path.resolve(process.cwd(), 'assets', 'icon.png'), contextIsolation: true, // expose system functions in preload
frame: os.platform() !== 'darwin', sandbox: false, // expose nodejs in preload
titleBarStyle: 'hiddenInset', preload: path.join(__dirname, './preload.js'),
backgroundColor: nativeTheme.shouldUseDarkColors },
? '#1C1C1C' icon: path.resolve(process.cwd(), 'assets', 'icon.png'),
: '#FCFCFC', frame: os.platform() !== 'darwin',
}) titleBarStyle: 'hiddenInset',
backgroundColor: nativeTheme.shouldUseDarkColors ? '#1C1C1C' : '#FCFCFC',
})
}
// and load the index.html of the app. // and load the index.html of the app.
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) { if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
@ -147,9 +150,11 @@ app.resizeWindow = async (width: number, height: number) => {
return mainWindow?.setSize(width, height) return mainWindow?.setSize(width, height)
} }
// @ts-ignore can't declaration merge with App
app.testProperty = {} app.testProperty = {}
ipcMain.handle('app.testProperty', (event, propertyName) => { ipcMain.handle('app.testProperty', (event, propertyName) => {
// @ts-ignore can't declaration merge with App
return app.testProperty[propertyName] return app.testProperty[propertyName]
}) })