* BROKEN: start of scopes for each setting * Clean up later: mostly-functional scoped settings! Broken command bar, unimplemented generated settings components * Working persisted project settings in-folder * Start working toward automatic commands and settings UI * Relatively stable, settings-menu-editable * Settings persistence tweaks after merge * Custom settings UI working properly, cleaner types * Allow boolean command types, create Settings UI for them * Add support for option and string Settings input types * Proof of concept settings from command bar * Add all settings to command bar * Allow settings to be hidden on a level * Better command titles for settings * Hide the settings the settings from the commands bar * Derive command defaultValue from *current* settingsMachine context * Fix generated settings UI for 'options' type settings * Pretty settings modal 💅 * Allow for rollback to parent level setting * fmt * Fix tsc errors not related to loading from localStorage * Better setting descriptions, better buttons * Make displayName searchable in command bar * Consolidate constants, get working in browser * Start fixing tests, better types for saved settings payloads * Fix playwright tests * Add a test for the settings modal * Add AtLeast to codespell ignore list * Goofed merge of codespellrc * Try fixing linux E2E tests * Make codespellrc word lowercase * fmt * Fix data-testid in Tauri test * Don't set text settings if nothing changed * Turn off unimplemented settings * Allow for multiple "execution-done" messages to have appeared in snapshot tests * Try fixing up snapshot tests * Switch from .json to .toml settings file format * Use a different method for overriding the default units * Try to force using the new common storage state in snapshot tests * Update tests to use TOML * fmt and remove console logs * Restore units to export * tsc errors, make snapshot tests use TOML * Ensure that snapshot tests use the basicStorageState * Re-organize use of test.use() * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Update snapshots one more time since lighting changed * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Fix broken "Show in folder" for project-level settings * Fire all relevant actions after settings reset * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Properly reset the default directory * Hide settings by platform * Actually honor showDebugPanel * Unify settings hiding logic * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * fix first extrusion snapshot * another attempt to fix extrustion snapshot * Rerun test suite * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * trigger CI * more extrusion stuff * Replace resetSettings console log with comment --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
168 lines
5.2 KiB
TypeScript
168 lines
5.2 KiB
TypeScript
import { expect, Page } from '@playwright/test'
|
|
import { EngineCommand } from '../../src/lang/std/engineConnection'
|
|
import fsp from 'fs/promises'
|
|
import pixelMatch from 'pixelmatch'
|
|
import { PNG } from 'pngjs'
|
|
|
|
async function waitForPageLoad(page: Page) {
|
|
// wait for 'Loading stream...' spinner
|
|
await page.getByTestId('loading-stream').waitFor()
|
|
// wait for all spinners to be gone
|
|
await page.getByTestId('loading').waitFor({ state: 'detached' })
|
|
|
|
await page.getByTestId('start-sketch').waitFor()
|
|
}
|
|
|
|
async function removeCurrentCode(page: Page) {
|
|
const hotkey = process.platform === 'darwin' ? 'Meta' : 'Control'
|
|
await page.click('.cm-content')
|
|
await page.keyboard.down(hotkey)
|
|
await page.keyboard.press('a')
|
|
await page.keyboard.up(hotkey)
|
|
await page.keyboard.press('Backspace')
|
|
await expect(page.locator('.cm-content')).toHaveText('')
|
|
}
|
|
|
|
async function sendCustomCmd(page: Page, cmd: EngineCommand) {
|
|
await page.fill('[data-testid="custom-cmd-input"]', JSON.stringify(cmd))
|
|
await page.click('[data-testid="custom-cmd-send-button"]')
|
|
}
|
|
|
|
async function clearCommandLogs(page: Page) {
|
|
await page.click('[data-testid="clear-commands"]')
|
|
}
|
|
|
|
async function expectCmdLog(page: Page, locatorStr: string) {
|
|
await expect(page.locator(locatorStr).last()).toBeVisible()
|
|
}
|
|
|
|
async function waitForDefaultPlanesToBeVisible(page: Page) {
|
|
await page.waitForFunction(
|
|
() =>
|
|
document.querySelectorAll('[data-receive-command-type="object_visible"]')
|
|
.length >= 3
|
|
)
|
|
}
|
|
|
|
async function openDebugPanel(page: Page) {
|
|
const isOpen =
|
|
(await page
|
|
.locator('[data-testid="debug-panel"]')
|
|
?.getAttribute('open')) === ''
|
|
|
|
if (!isOpen) {
|
|
await page.getByText('Debug').click()
|
|
await page.getByTestId('debug-panel').and(page.locator('[open]')).waitFor()
|
|
}
|
|
}
|
|
|
|
async function closeDebugPanel(page: Page) {
|
|
const isOpen =
|
|
(await page.getByTestId('debug-panel')?.getAttribute('open')) === ''
|
|
if (isOpen) {
|
|
await page.getByText('Debug').click()
|
|
await page
|
|
.getByTestId('debug-panel')
|
|
.and(page.locator(':not([open])'))
|
|
.waitFor()
|
|
}
|
|
}
|
|
|
|
async function waitForCmdReceive(page: Page, commandType: string) {
|
|
return page
|
|
.locator(`[data-receive-command-type="${commandType}"]`)
|
|
.first()
|
|
.waitFor()
|
|
}
|
|
|
|
export function getUtils(page: Page) {
|
|
return {
|
|
waitForAuthSkipAppStart: () => waitForPageLoad(page),
|
|
removeCurrentCode: () => removeCurrentCode(page),
|
|
sendCustomCmd: (cmd: EngineCommand) => sendCustomCmd(page, cmd),
|
|
updateCamPosition: async (xyz: [number, number, number]) => {
|
|
const fillInput = async () => {
|
|
await page.fill('[data-testid="cam-x-position"]', String(xyz[0]))
|
|
await page.fill('[data-testid="cam-y-position"]', String(xyz[1]))
|
|
await page.fill('[data-testid="cam-z-position"]', String(xyz[2]))
|
|
}
|
|
await fillInput()
|
|
await page.waitForTimeout(100)
|
|
await fillInput()
|
|
await page.waitForTimeout(100)
|
|
await fillInput()
|
|
await page.waitForTimeout(100)
|
|
},
|
|
clearCommandLogs: () => clearCommandLogs(page),
|
|
expectCmdLog: (locatorStr: string) => expectCmdLog(page, locatorStr),
|
|
openDebugPanel: () => openDebugPanel(page),
|
|
closeDebugPanel: () => closeDebugPanel(page),
|
|
openAndClearDebugPanel: async () => {
|
|
await openDebugPanel(page)
|
|
return clearCommandLogs(page)
|
|
},
|
|
clearAndCloseDebugPanel: async () => {
|
|
await clearCommandLogs(page)
|
|
return closeDebugPanel(page)
|
|
},
|
|
waitForCmdReceive: (commandType: string) =>
|
|
waitForCmdReceive(page, commandType),
|
|
doAndWaitForCmd: async (
|
|
fn: () => Promise<void>,
|
|
commandType: string,
|
|
endWithDebugPanelOpen = true
|
|
) => {
|
|
await openDebugPanel(page)
|
|
await clearCommandLogs(page)
|
|
await closeDebugPanel(page)
|
|
await fn()
|
|
await openDebugPanel(page)
|
|
await waitForCmdReceive(page, commandType)
|
|
if (!endWithDebugPanelOpen) {
|
|
await closeDebugPanel(page)
|
|
}
|
|
},
|
|
doAndWaitForImageDiff: (fn: () => Promise<any>, diffCount = 200) =>
|
|
new Promise(async (resolve) => {
|
|
await page.screenshot({
|
|
path: './e2e/playwright/temp1.png',
|
|
fullPage: true,
|
|
})
|
|
await fn()
|
|
const isImageDiff = async () => {
|
|
await page.screenshot({
|
|
path: './e2e/playwright/temp2.png',
|
|
fullPage: true,
|
|
})
|
|
const screenshot1 = PNG.sync.read(
|
|
await fsp.readFile('./e2e/playwright/temp1.png')
|
|
)
|
|
const screenshot2 = PNG.sync.read(
|
|
await fsp.readFile('./e2e/playwright/temp2.png')
|
|
)
|
|
const actualDiffCount = pixelMatch(
|
|
screenshot1.data,
|
|
screenshot2.data,
|
|
null,
|
|
screenshot1.width,
|
|
screenshot2.height
|
|
)
|
|
return actualDiffCount > diffCount
|
|
}
|
|
|
|
// run isImageDiff every 50ms until it returns true or 5 seconds have passed (100 times)
|
|
let count = 0
|
|
const interval = setInterval(async () => {
|
|
count++
|
|
if (await isImageDiff()) {
|
|
clearInterval(interval)
|
|
resolve(true)
|
|
} else if (count > 100) {
|
|
clearInterval(interval)
|
|
resolve(false)
|
|
}
|
|
}, 50)
|
|
}),
|
|
}
|
|
}
|