Fix native menu tests more

This commit is contained in:
lee-at-zoo-corp
2025-04-04 13:51:44 -04:00
parent 7f18aef49b
commit 0af99af15e
2 changed files with 241 additions and 148 deletions

View File

@ -12,15 +12,21 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) { if (!app || !app.applicationMenu) {
fail() return false
} }
const newProject = const newProject =
app.applicationMenu.getMenuItemById('File.New project') app.applicationMenu.getMenuItemById('File.New project')
if (!newProject) fail() if (!newProject) return false
newProject.click() newProject.click()
return true
}) })
)
.toBe(true)
// Check that the command bar is opened // Check that the command bar is opened
await expect(cmdBar.cmdBarElement).toBeVisible() await expect(cmdBar.cmdBarElement).toBeVisible()
// Check the placeholder project name exists // Check the placeholder project name exists
@ -34,15 +40,21 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) fail() if (!app || !app.applicationMenu) return false
const openProject = const openProject =
app.applicationMenu.getMenuItemById('File.Open project') app.applicationMenu.getMenuItemById('File.Open project')
if (!openProject) { if (!openProject) {
fail() return false
} }
openProject.click() openProject.click()
return true
}) })
)
.toBe(true)
// Check that the command bar is opened // Check that the command bar is opened
await expect(cmdBar.cmdBarElement).toBeVisible() await expect(cmdBar.cmdBarElement).toBeVisible()
// Check the placeholder project name exists // Check the placeholder project name exists
@ -60,17 +72,23 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
console.log(app) console.log(app)
if (!app || !app.applicationMenu) { if (!app || !app.applicationMenu) {
fail() return false
} }
const userSettings = app.applicationMenu.getMenuItemById( const userSettings = app.applicationMenu.getMenuItemById(
'File.Preferences.User settings' 'File.Preferences.User settings'
) )
if (!userSettings) fail() if (!userSettings) return false
userSettings.click() userSettings.click()
return true
}) })
)
.toBe(true)
const settings = page.getByTestId('settings-dialog-panel') const settings = page.getByTestId('settings-dialog-panel')
await expect(settings).toBeVisible() await expect(settings).toBeVisible()
// You are viewing the user tab // You are viewing the user tab
@ -89,16 +107,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
} }
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) fail() if (!app || !app.applicationMenu) return false
const keybindings = app.applicationMenu.getMenuItemById( const keybindings = app.applicationMenu.getMenuItemById(
'File.Preferences.Keybindings' 'File.Preferences.Keybindings'
) )
if (!keybindings) { if (!keybindings) {
fail() return false
} }
keybindings.click() keybindings.click()
return true
}) })
)
.toBe(true)
const settings = page.getByTestId('settings-dialog-panel') const settings = page.getByTestId('settings-dialog-panel')
await expect(settings).toBeVisible() await expect(settings).toBeVisible()
// You are viewing the keybindings tab // You are viewing the keybindings tab
@ -113,16 +137,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) { if (!app || !app.applicationMenu) {
fail() return false
} }
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'File.Preferences.User default units' 'File.Preferences.User default units'
) )
if (!menu) fail() if (!menu) return false
menu.click() menu.click()
return true
}) })
)
.toBe(true)
const settings = page.getByTestId('settings-dialog-panel') const settings = page.getByTestId('settings-dialog-panel')
await expect(settings).toBeVisible() await expect(settings).toBeVisible()
const defaultUnit = settings.locator('#defaultUnit') const defaultUnit = settings.locator('#defaultUnit')
@ -132,16 +162,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) fail() if (!app || !app.applicationMenu) return false
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'File.Preferences.Theme' 'File.Preferences.Theme'
) )
if (!menu) { if (!menu) {
fail() return false
} }
menu.click() menu.click()
return true
}) })
)
.toBe(true)
// Check that the command bar is opened // Check that the command bar is opened
await expect(cmdBar.cmdBarElement).toBeVisible() await expect(cmdBar.cmdBarElement).toBeVisible()
// Check the placeholder project name exists // Check the placeholder project name exists
@ -159,16 +195,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) { if (!app || !app.applicationMenu) {
fail() return false
} }
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'File.Preferences.Theme color' 'File.Preferences.Theme color'
) )
if (!menu) fail() if (!menu) return false
menu.click() menu.click()
return true
}) })
)
.toBe(true)
const settings = page.getByTestId('settings-dialog-panel') const settings = page.getByTestId('settings-dialog-panel')
await expect(settings).toBeVisible() await expect(settings).toBeVisible()
const defaultUnit = settings.locator('#themeColor') const defaultUnit = settings.locator('#themeColor')
@ -182,15 +224,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) fail() if (!app || !app.applicationMenu) return false
const menu = app.applicationMenu.getMenuItemById('File.Sign out') const menu =
app.applicationMenu.getMenuItemById('File.Sign out')
if (!menu) { if (!menu) {
fail() return false
} }
// FIXME: Add back when you can actually sign out // FIXME: Add back when you can actually sign out
// menu.click() // menu.click()
// return true
}) })
)
.toBe(true)
// FIXME: When signing out during E2E the page is not bound correctly. // FIXME: When signing out during E2E the page is not bound correctly.
// It cannot find the button // It cannot find the button
// const signIn = page.getByTestId('sign-in-button') // const signIn = page.getByTestId('sign-in-button')
@ -203,16 +252,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) { if (!app || !app.applicationMenu) {
fail() return false
} }
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'Edit.Rename project' 'Edit.Rename project'
) )
if (!menu) fail() if (!menu) return false
menu.click() menu.click()
return true
}) })
)
.toBe(true)
// Check the placeholder project name exists // Check the placeholder project name exists
const actual = await cmdBar.cmdBarElement const actual = await cmdBar.cmdBarElement
.getByTestId('command-name') .getByTestId('command-name')
@ -224,16 +279,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) fail() if (!app || !app.applicationMenu) return false
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'Edit.Delete project' 'Edit.Delete project'
) )
if (!menu) { if (!menu) {
fail() return false
} }
menu.click() menu.click()
return true
}) })
)
.toBe(true)
// Check the placeholder project name exists // Check the placeholder project name exists
const actual = async () => const actual = async () =>
cmdBar.cmdBarElement.getByTestId('command-name').textContent() cmdBar.cmdBarElement.getByTestId('command-name').textContent()
@ -248,16 +309,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) { if (!app || !app.applicationMenu) {
fail() return false
} }
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'Edit.Change project directory' 'Edit.Change project directory'
) )
if (!menu) fail() if (!menu) return false
menu.click() menu.click()
return true
}) })
)
.toBe(true)
const settings = page.getByTestId('settings-dialog-panel') const settings = page.getByTestId('settings-dialog-panel')
await expect(settings).toBeVisible() await expect(settings).toBeVisible()
const projectDirectory = settings.locator('#projectDirectory') const projectDirectory = settings.locator('#projectDirectory')
@ -273,16 +340,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) fail() if (!app || !app.applicationMenu) return false
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'View.Command Palette...' 'View.Command Palette...'
) )
if (!menu) { if (!menu) {
fail() return false
} }
menu.click() menu.click()
return true
}) })
)
.toBe(true)
// Check the placeholder project name exists // Check the placeholder project name exists
const actual = cmdBar.cmdBarElement.getByTestId('cmd-bar-search') const actual = cmdBar.cmdBarElement.getByTestId('cmd-bar-search')
await expect(actual).toBeVisible() await expect(actual).toBeVisible()
@ -293,16 +366,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) { if (!app || !app.applicationMenu) {
fail() return false
} }
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'Help.Show all commands' 'Help.Show all commands'
) )
if (!menu) fail() if (!menu) return false
menu.click() menu.click()
return true
}) })
)
.toBe(true)
// Check the placeholder project name exists // Check the placeholder project name exists
const actual = cmdBar.cmdBarElement.getByTestId('cmd-bar-search') const actual = cmdBar.cmdBarElement.getByTestId('cmd-bar-search')
await expect(actual).toBeVisible() await expect(actual).toBeVisible()
@ -311,15 +390,21 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) fail() if (!app || !app.applicationMenu) return false
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'Help.KCL code samples' 'Help.KCL code samples'
) )
if (!menu) { if (!menu) {
fail() return false
} }
return true
}) })
)
.toBe(true)
}) })
test('Home.Help.Refresh and report a bug', async ({ test('Home.Help.Refresh and report a bug', async ({
tronApp, tronApp,
@ -329,16 +414,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) { if (!app || !app.applicationMenu) {
fail() return false
} }
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'Help.Refresh and report a bug' 'Help.Refresh and report a bug'
) )
if (!menu) fail() if (!menu) return false
menu.click() menu.click()
return true
}) })
)
.toBe(true)
// Core dump and refresh magic number timeout // Core dump and refresh magic number timeout
await page.waitForTimeout(7000) await page.waitForTimeout(7000)
const actual = page.getByText( const actual = page.getByText(
@ -350,16 +441,22 @@ test.describe('Native file menu', { tag: ['@electron'] }, () => {
if (!tronApp) fail() if (!tronApp) fail()
// Run electron snippet to find the Menu! // Run electron snippet to find the Menu!
await page.waitForTimeout(100) // wait for createModelingPageMenu() to run await page.waitForTimeout(100) // wait for createModelingPageMenu() to run
await expect
.poll(
async () =>
await tronApp.electron.evaluate(async ({ app }) => { await tronApp.electron.evaluate(async ({ app }) => {
if (!app || !app.applicationMenu) fail() if (!app || !app.applicationMenu) return false
const menu = app.applicationMenu.getMenuItemById( const menu = app.applicationMenu.getMenuItemById(
'Help.Reset onboarding' 'Help.Reset onboarding'
) )
if (!menu) { if (!menu) {
fail() return false
} }
menu.click() menu.click()
return true
}) })
)
.toBe(true)
const actual = page.getByText( const actual = page.getByText(
`This is a hardware design tool that lets you edit visually, with code, or both. It's powered by the KittyCAD Design API, the first API created for anyone to build hardware design tools.` `This is a hardware design tool that lets you edit visually, with code, or both. It's powered by the KittyCAD Design API, the first API created for anyone to build hardware design tools.`

View File

@ -419,7 +419,6 @@ test(
const PUR = 400 / 37.5 //pixeltoUnitRatio const PUR = 400 / 37.5 //pixeltoUnitRatio
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
const startXPx = 600 const startXPx = 600
const [endOfTangentClk, endOfTangentMv] = scene.makeMouseHelpers( const [endOfTangentClk, endOfTangentMv] = scene.makeMouseHelpers(
startXPx + PUR * 30, startXPx + PUR * 30,
@ -548,7 +547,6 @@ test(
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
// click on "Start Sketch" button // click on "Start Sketch" button
await u.doAndWaitForImageDiff( await u.doAndWaitForImageDiff(
() => page.getByRole('button', { name: 'Start Sketch' }).click(), () => page.getByRole('button', { name: 'Start Sketch' }).click(),
@ -594,7 +592,6 @@ test(
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
await u.doAndWaitForImageDiff( await u.doAndWaitForImageDiff(
() => page.getByRole('button', { name: 'Start Sketch' }).click(), () => page.getByRole('button', { name: 'Start Sketch' }).click(),
200 200
@ -645,7 +642,6 @@ test.describe(
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
await u.doAndWaitForImageDiff( await u.doAndWaitForImageDiff(
() => page.getByRole('button', { name: 'Start Sketch' }).click(), () => page.getByRole('button', { name: 'Start Sketch' }).click(),
200 200