fix ABS XY constraint (#2560)
* fix source rangen for abs x y constraints * fix abs bug * add e2e test
This commit is contained in:
		@ -2440,6 +2440,113 @@ test('Extrude from command bar selects extrude line after', async ({
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test.describe('Testing constraints', () => {
 | 
			
		||||
  test.describe('Test ABS distance constraint', () => {
 | 
			
		||||
    const cases = [
 | 
			
		||||
      {
 | 
			
		||||
        testName: 'Add variable',
 | 
			
		||||
        addVariable: true,
 | 
			
		||||
        constraint: 'ABS X',
 | 
			
		||||
        value: 'xDis001, 61.34',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        testName: 'No variable',
 | 
			
		||||
        addVariable: false,
 | 
			
		||||
        constraint: 'ABS X',
 | 
			
		||||
        value: '154.9, 61.34',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        testName: 'Add variable',
 | 
			
		||||
        addVariable: true,
 | 
			
		||||
        constraint: 'ABS Y',
 | 
			
		||||
        value: '154.9, yDis001',
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        testName: 'No variable',
 | 
			
		||||
        addVariable: false,
 | 
			
		||||
        constraint: 'ABS Y',
 | 
			
		||||
        value: '154.9, 61.34',
 | 
			
		||||
      },
 | 
			
		||||
    ] as const
 | 
			
		||||
    for (const { testName, addVariable, value, constraint } of cases) {
 | 
			
		||||
      test(`${constraint} - ${testName}`, async ({ page }) => {
 | 
			
		||||
        await page.addInitScript(async () => {
 | 
			
		||||
          localStorage.setItem(
 | 
			
		||||
            'persistCode',
 | 
			
		||||
            `const yo = 5
 | 
			
		||||
const part001 = startSketchOn('XZ')
 | 
			
		||||
  |> startProfileAt([-7.54, -26.74], %)
 | 
			
		||||
  |> line([74.36, 130.4], %)
 | 
			
		||||
  |> line([78.92, -120.11], %)
 | 
			
		||||
  |> line([9.16, 77.79], %)
 | 
			
		||||
  |> line([41.19, 28.97], %)
 | 
			
		||||
const part002 = startSketchOn('XZ')
 | 
			
		||||
  |> startProfileAt([299.05, 231.45], %)
 | 
			
		||||
  |> xLine(-425.34, %, 'seg-what')
 | 
			
		||||
  |> yLine(-264.06, %)
 | 
			
		||||
  |> xLine(segLen('seg-what', %), %)
 | 
			
		||||
  |> lineTo([profileStartX(%), profileStartY(%)], %)`
 | 
			
		||||
          )
 | 
			
		||||
        })
 | 
			
		||||
        const u = await getUtils(page)
 | 
			
		||||
        await page.setViewportSize({ width: 1200, height: 500 })
 | 
			
		||||
        await page.goto('/')
 | 
			
		||||
        await u.waitForAuthSkipAppStart()
 | 
			
		||||
 | 
			
		||||
        await page.getByText('line([74.36, 130.4], %)').click()
 | 
			
		||||
        await page.getByRole('button', { name: 'Edit Sketch' }).click()
 | 
			
		||||
 | 
			
		||||
        const [line3] = await Promise.all([
 | 
			
		||||
          u.getSegmentBodyCoords(`[data-overlay-index="${2}"]`),
 | 
			
		||||
        ])
 | 
			
		||||
 | 
			
		||||
        if (constraint === 'ABS X') {
 | 
			
		||||
          await page.mouse.click(600, 130)
 | 
			
		||||
        } else {
 | 
			
		||||
          await page.mouse.click(900, 250)
 | 
			
		||||
        }
 | 
			
		||||
        await page.keyboard.down('Shift')
 | 
			
		||||
        await page.mouse.click(line3.x, line3.y)
 | 
			
		||||
        await page.waitForTimeout(100) // this wait is needed for webkit - not sure why
 | 
			
		||||
        await page.keyboard.up('Shift')
 | 
			
		||||
        await page
 | 
			
		||||
          .getByRole('button', {
 | 
			
		||||
            name: 'Constrain',
 | 
			
		||||
          })
 | 
			
		||||
          .click()
 | 
			
		||||
        await page
 | 
			
		||||
          .getByRole('button', { name: constraint, exact: true })
 | 
			
		||||
          .click()
 | 
			
		||||
 | 
			
		||||
        const createNewVariableCheckbox = page.getByTestId(
 | 
			
		||||
          'create-new-variable-checkbox'
 | 
			
		||||
        )
 | 
			
		||||
        const isChecked = await createNewVariableCheckbox.isChecked()
 | 
			
		||||
        ;((isChecked && !addVariable) || (!isChecked && addVariable)) &&
 | 
			
		||||
          (await createNewVariableCheckbox.click())
 | 
			
		||||
 | 
			
		||||
        await page
 | 
			
		||||
          .getByRole('button', { name: 'Add constraining value' })
 | 
			
		||||
          .click()
 | 
			
		||||
 | 
			
		||||
        // checking activeLines assures the cursors are where they should be
 | 
			
		||||
        const codeAfter = [`|> lineTo([${value}], %)`]
 | 
			
		||||
 | 
			
		||||
        const activeLinesContent = await page.locator('.cm-activeLine').all()
 | 
			
		||||
        await Promise.all(
 | 
			
		||||
          activeLinesContent.map(async (line, i) => {
 | 
			
		||||
            await expect(page.locator('.cm-content')).toContainText(
 | 
			
		||||
              codeAfter[i]
 | 
			
		||||
            )
 | 
			
		||||
            // if the code is an active line then the cursor should be on that line
 | 
			
		||||
            await expect(line).toHaveText(codeAfter[i])
 | 
			
		||||
          })
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        // checking the count of the overlays is a good proxy check that the client sketch scene is in a good state
 | 
			
		||||
        await expect(page.getByTestId('segment-overlay')).toHaveCount(4)
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
  test.describe('Test Angle constraint double segment selection', () => {
 | 
			
		||||
    const cases = [
 | 
			
		||||
      {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user