Skip to content

Commit

Permalink
playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mrgrsk authored and Irev-Dev committed Jul 15, 2024
1 parent ad54158 commit fbb86c5
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
81 changes: 81 additions & 0 deletions e2e/playwright/flow-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3099,6 +3099,49 @@ const sketch002 = startSketchOn(extrude001, $seg01)
).not.toBeDisabled()
})

test('Fillet button states test', async ({ page }) => {
const u = await getUtils(page)
await page.addInitScript(async () => {
localStorage.setItem(
'persistCode',
`const sketch001 = startSketchOn('XZ')
|> startProfileAt([-5, -5], %)
|> line([0, 10], %)
|> line([10, 0], %)
|> line([0, -10], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`
)
})

await page.setViewportSize({ width: 1000, height: 500 })
await u.waitForAuthSkipAppStart()
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()

const selectSegment = () => page.getByText(`line([10, 0], %)`).click()
const selectClose = () => page.getByText(`close(%)`).click()
const clickEmpty = () => page.mouse.click(950, 100)

// expect fillet button without any bodies in the scene
await selectSegment()
await expect(page.getByRole('button', { name: 'Fillet' })).toBeDisabled()
await clickEmpty()
await expect(page.getByRole('button', { name: 'Fillet' })).toBeDisabled()

// test fillet button with the body in the scene
const codeToAdd = `${await u.codeLocator.allInnerTexts()}
const extrude001 = extrude(10, sketch001)`
await u.codeLocator.fill(codeToAdd)
await selectSegment()
await expect(page.getByRole('button', { name: 'Fillet' })).toBeEnabled()
await selectClose()
await expect(page.getByRole('button', { name: 'Fillet' })).toBeDisabled()
await clickEmpty()
await expect(page.getByRole('button', { name: 'Fillet' })).toBeEnabled()
})

const removeAfterFirstParenthesis = (inputString: string) => {
const index = inputString.indexOf('(')
if (index !== -1) {
Expand Down Expand Up @@ -3500,6 +3543,44 @@ test.describe('Command bar tests', () => {
`const extrude001 = extrude(${KCL_DEFAULT_LENGTH}, sketch001)`
)
})

test('Fillet from command bar', async ({ page }) => {
await page.addInitScript(async () => {
localStorage.setItem(
'persistCode',
`const sketch001 = startSketchOn('XY')
|> startProfileAt([-5, -5], %)
|> line([0, 10], %)
|> line([10, 0], %)
|> line([0, -10], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-10, sketch001)`
)
})

const u = await getUtils(page)
await page.setViewportSize({ width: 1000, height: 500 })
await u.waitForAuthSkipAppStart()
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()

const selectSegment = () => page.getByText(`line([0, -10], %)`).click()

await selectSegment()
await page.waitForTimeout(100)
await page.getByRole('button', { name: 'Fillet' }).click()
await page.waitForTimeout(100)
await page.keyboard.press('Enter')
await page.waitForTimeout(100)
await page.keyboard.press('Enter')
await page.waitForTimeout(100)
await expect(page.locator('.cm-activeLine')).toContainText(
`fillet({ radius: ${KCL_DEFAULT_LENGTH}, tags: [seg01] }, %)`
)
})

test('Command bar can change a setting, and switch back and forth between arguments', async ({
page,
}) => {
Expand Down
4 changes: 2 additions & 2 deletions src/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function Toolbar({
() =>
commandBarSend({
type: 'Find and select command',
data: { name: 'Fillet', ownerMachine: 'modeling' },
data: { name: 'Fillet', groupId: 'modeling' },
}),
{ enabled: !disableAllButtons, scopes: ['modeling'] }
)
Expand Down Expand Up @@ -421,7 +421,7 @@ export function Toolbar({
onClick={() =>
commandBarSend({
type: 'Find and select command',
data: { name: 'Fillet', ownerMachine: 'modeling' },
data: { name: 'Fillet', groupId: 'modeling' },
})
}
disabled={!state.can('Fillet') || disableAllButtons}
Expand Down
7 changes: 4 additions & 3 deletions src/components/ModelingMachineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,10 @@ export const ModelingMachineProvider = ({
pathToSelectedNode,
'CallExpression'
)
if (err(segmentNode)) return false
if (segmentNode.node.type === 'CallExpression') {
// check wethe segment is in sketchLineHelperMap
if (
'node' in segmentNode &&
segmentNode.node.type === 'CallExpression'
) {
const segmentName = segmentNode.node.callee.name
if (segmentName in sketchLineHelperMap) {
return true
Expand Down

0 comments on commit fbb86c5

Please sign in to comment.