2024-08-07 19:27:32 +10:00
|
|
|
import { test, expect, Page } from '@playwright/test'
|
|
|
|
import {
|
|
|
|
getUtils,
|
|
|
|
TEST_COLORS,
|
|
|
|
setup,
|
|
|
|
tearDown,
|
|
|
|
commonPoints,
|
|
|
|
PERSIST_MODELING_CONTEXT,
|
|
|
|
} from './test-utils'
|
|
|
|
|
2024-09-16 07:32:33 +10:00
|
|
|
test.beforeEach(async ({ context, page }, testInfo) => {
|
|
|
|
await setup(context, page, testInfo)
|
2024-08-07 19:27:32 +10:00
|
|
|
})
|
|
|
|
|
|
|
|
test.afterEach(async ({ page }, testInfo) => {
|
|
|
|
await tearDown(page, testInfo)
|
|
|
|
})
|
|
|
|
|
|
|
|
test.setTimeout(120000)
|
|
|
|
|
|
|
|
async function doBasicSketch(page: Page, openPanes: string[]) {
|
|
|
|
const u = await getUtils(page)
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
const PUR = 400 / 37.5 //pixeltoUnitRatio
|
|
|
|
|
|
|
|
await u.waitForAuthSkipAppStart()
|
|
|
|
await u.openDebugPanel()
|
|
|
|
|
|
|
|
// If we have the code pane open, we should see the code.
|
|
|
|
if (openPanes.includes('code')) {
|
|
|
|
await expect(u.codeLocator).toHaveText(``)
|
|
|
|
} else {
|
|
|
|
// Ensure we don't see the code.
|
|
|
|
await expect(u.codeLocator).not.toBeVisible()
|
|
|
|
}
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: 'Start Sketch' })
|
|
|
|
).not.toBeDisabled()
|
|
|
|
await expect(page.getByRole('button', { name: 'Start Sketch' })).toBeVisible()
|
|
|
|
|
|
|
|
// click on "Start Sketch" button
|
|
|
|
await u.clearCommandLogs()
|
|
|
|
await page.getByRole('button', { name: 'Start Sketch' }).click()
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
|
|
|
|
// select a plane
|
|
|
|
await page.mouse.click(700, 200)
|
|
|
|
|
|
|
|
if (openPanes.includes('code')) {
|
2024-10-02 14:19:40 -05:00
|
|
|
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')`)
|
2024-08-07 19:27:32 +10:00
|
|
|
}
|
|
|
|
await u.closeDebugPanel()
|
|
|
|
|
|
|
|
await page.waitForTimeout(1000) // TODO detect animation ending, or disable animation
|
|
|
|
|
|
|
|
const startXPx = 600
|
|
|
|
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
|
|
|
|
if (openPanes.includes('code')) {
|
2024-12-16 10:34:11 -05:00
|
|
|
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')
|
|
|
|
|> startProfileAt(${commonPoints.startAt}, %)`)
|
2024-08-07 19:27:32 +10:00
|
|
|
}
|
2024-08-07 21:10:58 +10:00
|
|
|
await page.waitForTimeout(500)
|
2024-08-07 19:27:32 +10:00
|
|
|
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
|
|
|
|
if (openPanes.includes('code')) {
|
2024-12-16 10:34:11 -05:00
|
|
|
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')
|
|
|
|
|> startProfileAt(${commonPoints.startAt}, %)
|
2024-11-13 09:41:27 -05:00
|
|
|
|> xLine(${commonPoints.num1}, %)`)
|
2024-08-07 19:27:32 +10:00
|
|
|
}
|
2024-08-07 21:10:58 +10:00
|
|
|
await page.waitForTimeout(500)
|
2024-08-07 19:27:32 +10:00
|
|
|
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
|
|
|
|
if (openPanes.includes('code')) {
|
2024-12-16 10:34:11 -05:00
|
|
|
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')
|
|
|
|
|> startProfileAt(${commonPoints.startAt}, %)
|
2024-11-13 09:41:27 -05:00
|
|
|
|> xLine(${commonPoints.num1}, %)
|
|
|
|
|> yLine(${commonPoints.num1 + 0.01}, %)`)
|
2024-08-07 19:27:32 +10:00
|
|
|
} else {
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
}
|
2024-08-16 07:15:42 -04:00
|
|
|
await page.waitForTimeout(200)
|
2024-08-07 19:27:32 +10:00
|
|
|
await page.mouse.click(startXPx, 500 - PUR * 20)
|
|
|
|
if (openPanes.includes('code')) {
|
2024-12-16 10:34:11 -05:00
|
|
|
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')
|
|
|
|
|> startProfileAt(${commonPoints.startAt}, %)
|
2024-11-13 09:41:27 -05:00
|
|
|
|> xLine(${commonPoints.num1}, %)
|
|
|
|
|> yLine(${commonPoints.num1 + 0.01}, %)
|
|
|
|
|> xLine(${commonPoints.num2 * -1}, %)`)
|
2024-08-07 19:27:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
// deselect line tool
|
2024-09-03 12:30:14 -04:00
|
|
|
const btnLine = page.getByTestId('line')
|
|
|
|
const btnLineAriaPressed = await btnLine.getAttribute('aria-pressed')
|
|
|
|
if (btnLineAriaPressed === 'true') {
|
|
|
|
await btnLine.click()
|
|
|
|
}
|
|
|
|
|
|
|
|
await page.waitForTimeout(100)
|
2024-08-07 19:27:32 +10:00
|
|
|
|
|
|
|
const line1 = await u.getSegmentBodyCoords(`[data-overlay-index="${0}"]`, 0)
|
|
|
|
if (openPanes.includes('code')) {
|
2024-08-16 07:15:42 -04:00
|
|
|
await expect
|
|
|
|
.poll(async () => u.getGreatestPixDiff(line1, TEST_COLORS.WHITE))
|
|
|
|
.toBeLessThan(3)
|
2024-09-03 12:30:14 -04:00
|
|
|
await page.waitForTimeout(100)
|
2024-08-16 07:15:42 -04:00
|
|
|
await expect
|
2024-09-03 12:30:14 -04:00
|
|
|
.poll(async () => u.getGreatestPixDiff(line1, [249, 249, 249]))
|
2024-08-16 07:15:42 -04:00
|
|
|
.toBeLessThan(3)
|
2024-09-03 12:30:14 -04:00
|
|
|
await page.waitForTimeout(100)
|
2024-08-07 19:27:32 +10:00
|
|
|
}
|
2024-09-03 12:30:14 -04:00
|
|
|
|
2024-08-07 19:27:32 +10:00
|
|
|
// click between first two clicks to get center of the line
|
|
|
|
await page.mouse.click(startXPx + PUR * 15, 500 - PUR * 10)
|
|
|
|
await page.waitForTimeout(100)
|
2024-09-03 12:30:14 -04:00
|
|
|
|
2024-08-07 19:27:32 +10:00
|
|
|
if (openPanes.includes('code')) {
|
2024-09-03 12:30:14 -04:00
|
|
|
await expect(
|
|
|
|
await u.getGreatestPixDiff(line1, TEST_COLORS.BLUE)
|
|
|
|
).toBeLessThan(3)
|
2024-08-07 19:27:32 +10:00
|
|
|
await expect(await u.getGreatestPixDiff(line1, [0, 0, 255])).toBeLessThan(3)
|
|
|
|
}
|
|
|
|
|
|
|
|
// hold down shift
|
|
|
|
await page.keyboard.down('Shift')
|
2024-09-03 12:30:14 -04:00
|
|
|
await page.waitForTimeout(100)
|
|
|
|
|
2024-08-07 19:27:32 +10:00
|
|
|
// click between the latest two clicks to get center of the line
|
|
|
|
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 20)
|
2024-09-03 12:30:14 -04:00
|
|
|
await page.waitForTimeout(100)
|
2024-08-07 19:27:32 +10:00
|
|
|
|
|
|
|
// selected two lines therefore there should be two cursors
|
|
|
|
if (openPanes.includes('code')) {
|
|
|
|
await expect(page.locator('.cm-cursor')).toHaveCount(2)
|
2024-09-03 12:30:14 -04:00
|
|
|
await page.waitForTimeout(100)
|
2024-08-07 19:27:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
await page.getByRole('button', { name: 'Length: open menu' }).click()
|
|
|
|
await page.getByRole('button', { name: 'Equal Length' }).click()
|
|
|
|
|
|
|
|
// Open the code pane.
|
|
|
|
await u.openKclCodePanel()
|
2024-12-16 10:34:11 -05:00
|
|
|
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ')
|
|
|
|
|> startProfileAt(${commonPoints.startAt}, %)
|
2024-11-13 09:41:27 -05:00
|
|
|
|> xLine(${commonPoints.num1}, %, $seg01)
|
|
|
|
|> yLine(${commonPoints.num1 + 0.01}, %)
|
|
|
|
|> xLine(-segLen(seg01), %)`)
|
2024-08-07 19:27:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
test.describe('Basic sketch', () => {
|
2024-10-02 11:58:17 -04:00
|
|
|
test('code pane open at start', { tag: ['@skipWin'] }, async ({ page }) => {
|
2024-08-17 14:15:11 -07:00
|
|
|
// Skip on windows it is being weird.
|
|
|
|
test.skip(process.platform === 'win32', 'Skip on windows')
|
2024-08-07 19:27:32 +10:00
|
|
|
await doBasicSketch(page, ['code'])
|
|
|
|
})
|
|
|
|
|
|
|
|
test('code pane closed at start', async ({ page }) => {
|
|
|
|
// Load the app with the code panes
|
|
|
|
await page.addInitScript(async (persistModelingContext) => {
|
|
|
|
localStorage.setItem(
|
|
|
|
persistModelingContext,
|
|
|
|
JSON.stringify({ openPanes: [] })
|
|
|
|
)
|
|
|
|
}, PERSIST_MODELING_CONTEXT)
|
|
|
|
await doBasicSketch(page, [])
|
|
|
|
})
|
|
|
|
})
|