| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  | import { _test, _expect } from './playwright-deprecated' | 
					
						
							|  |  |  | import { test } from './fixtures/fixtureSetup' | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  | import { getUtils, setup, tearDown } from './test-utils' | 
					
						
							|  |  |  | import { uuidv4 } from 'lib/utils' | 
					
						
							|  |  |  | import { TEST_CODE_GIZMO } from './storageStates' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  | _test.beforeEach(async ({ context, page }, testInfo) => { | 
					
						
							| 
									
										
										
										
											2024-09-16 07:32:33 +10:00
										 |  |  |   await setup(context, page, testInfo) | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  | _test.afterEach(async ({ page }, testInfo) => { | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |   await tearDown(page, testInfo) | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  | _test.describe('Testing Gizmo', () => { | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |   const cases = [ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       testDescription: 'top view', | 
					
						
							| 
									
										
										
										
											2024-09-30 11:40:00 -04:00
										 |  |  |       clickPosition: { x: 951, y: 347 }, | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |       expectedCameraPosition: { x: 800, y: -152, z: 4886.02 }, | 
					
						
							|  |  |  |       expectedCameraTarget: { x: 800, y: -152, z: 26 }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       testDescription: 'bottom view', | 
					
						
							| 
									
										
										
										
											2024-09-30 11:40:00 -04:00
										 |  |  |       clickPosition: { x: 951, y: 391 }, | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |       expectedCameraPosition: { x: 800, y: -152, z: -4834.02 }, | 
					
						
							|  |  |  |       expectedCameraTarget: { x: 800, y: -152, z: 26 }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       testDescription: 'right view', | 
					
						
							| 
									
										
										
										
											2024-09-30 11:40:00 -04:00
										 |  |  |       clickPosition: { x: 929, y: 379 }, | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |       expectedCameraPosition: { x: 5660.02, y: -152, z: 26 }, | 
					
						
							|  |  |  |       expectedCameraTarget: { x: 800, y: -152, z: 26 }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       testDescription: 'left view', | 
					
						
							| 
									
										
										
										
											2024-09-30 11:40:00 -04:00
										 |  |  |       clickPosition: { x: 974, y: 359 }, | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |       expectedCameraPosition: { x: -4060.02, y: -152, z: 26 }, | 
					
						
							|  |  |  |       expectedCameraTarget: { x: 800, y: -152, z: 26 }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       testDescription: 'back view', | 
					
						
							| 
									
										
										
										
											2024-09-30 11:40:00 -04:00
										 |  |  |       clickPosition: { x: 967, y: 383 }, | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |       expectedCameraPosition: { x: 800, y: 4708.02, z: 26 }, | 
					
						
							|  |  |  |       expectedCameraTarget: { x: 800, y: -152, z: 26 }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       testDescription: 'front view', | 
					
						
							| 
									
										
										
										
											2024-09-30 11:40:00 -04:00
										 |  |  |       clickPosition: { x: 935, y: 355 }, | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |       expectedCameraPosition: { x: 800, y: -5012.02, z: 26 }, | 
					
						
							|  |  |  |       expectedCameraTarget: { x: 800, y: -152, z: 26 }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   ] as const | 
					
						
							|  |  |  |   for (const { | 
					
						
							|  |  |  |     clickPosition, | 
					
						
							|  |  |  |     expectedCameraPosition, | 
					
						
							|  |  |  |     expectedCameraTarget, | 
					
						
							|  |  |  |     testDescription, | 
					
						
							|  |  |  |   } of cases) { | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |     _test(`check ${testDescription}`, async ({ page, browserName }) => { | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |       const u = await getUtils(page) | 
					
						
							|  |  |  |       await page.addInitScript((TEST_CODE_GIZMO) => { | 
					
						
							|  |  |  |         localStorage.setItem('persistCode', TEST_CODE_GIZMO) | 
					
						
							|  |  |  |       }, TEST_CODE_GIZMO) | 
					
						
							|  |  |  |       await page.setViewportSize({ width: 1000, height: 500 }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await u.waitForAuthSkipAppStart() | 
					
						
							|  |  |  |       await page.waitForTimeout(100) | 
					
						
							|  |  |  |       // wait for execution done
 | 
					
						
							|  |  |  |       await u.openDebugPanel() | 
					
						
							|  |  |  |       await u.expectCmdLog('[data-message-type="execution-done"]') | 
					
						
							|  |  |  |       await u.sendCustomCmd({ | 
					
						
							|  |  |  |         type: 'modeling_cmd_req', | 
					
						
							|  |  |  |         cmd_id: uuidv4(), | 
					
						
							|  |  |  |         cmd: { | 
					
						
							|  |  |  |           type: 'default_camera_look_at', | 
					
						
							|  |  |  |           vantage: { | 
					
						
							|  |  |  |             x: 3000, | 
					
						
							|  |  |  |             y: 3000, | 
					
						
							|  |  |  |             z: 3000, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           center: { | 
					
						
							|  |  |  |             x: 800, | 
					
						
							|  |  |  |             y: -152, | 
					
						
							|  |  |  |             z: 26, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           up: { x: 0, y: 0, z: 1 }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       await page.waitForTimeout(100) | 
					
						
							|  |  |  |       await u.clearCommandLogs() | 
					
						
							|  |  |  |       await u.sendCustomCmd({ | 
					
						
							|  |  |  |         type: 'modeling_cmd_req', | 
					
						
							|  |  |  |         cmd_id: uuidv4(), | 
					
						
							|  |  |  |         cmd: { | 
					
						
							|  |  |  |           type: 'default_camera_get_settings', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       await u.waitForCmdReceive('default_camera_get_settings') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await u.clearCommandLogs() | 
					
						
							|  |  |  |       await page.mouse.move(clickPosition.x, clickPosition.y) | 
					
						
							|  |  |  |       await page.waitForTimeout(100) | 
					
						
							|  |  |  |       await page.mouse.click(clickPosition.x, clickPosition.y) | 
					
						
							|  |  |  |       await page.mouse.move(0, 0) | 
					
						
							|  |  |  |       await u.waitForCmdReceive('default_camera_look_at') | 
					
						
							|  |  |  |       await u.clearCommandLogs() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await u.sendCustomCmd({ | 
					
						
							|  |  |  |         type: 'modeling_cmd_req', | 
					
						
							|  |  |  |         cmd_id: uuidv4(), | 
					
						
							|  |  |  |         cmd: { | 
					
						
							|  |  |  |           type: 'default_camera_get_settings', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       await u.waitForCmdReceive('default_camera_get_settings') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await Promise.all([ | 
					
						
							|  |  |  |         // position
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |         _expect(page.getByTestId('cam-x-position')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |           expectedCameraPosition.x.toString() | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |         _expect(page.getByTestId('cam-y-position')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |           expectedCameraPosition.y.toString() | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |         _expect(page.getByTestId('cam-z-position')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |           expectedCameraPosition.z.toString() | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         // target
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |         _expect(page.getByTestId('cam-x-target')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |           expectedCameraTarget.x.toString() | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |         _expect(page.getByTestId('cam-y-target')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |           expectedCameraTarget.y.toString() | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |         _expect(page.getByTestId('cam-z-target')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |           expectedCameraTarget.z.toString() | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |       ]) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |   _test('Context menu and popover menu', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |     const testCase = { | 
					
						
							|  |  |  |       testDescription: 'Right view', | 
					
						
							|  |  |  |       expectedCameraPosition: { x: 5660.02, y: -152, z: 26 }, | 
					
						
							|  |  |  |       expectedCameraTarget: { x: 800, y: -152, z: 26 }, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Test prelude taken from the above test
 | 
					
						
							|  |  |  |     const u = await getUtils(page) | 
					
						
							|  |  |  |     await page.addInitScript((TEST_CODE_GIZMO) => { | 
					
						
							|  |  |  |       localStorage.setItem('persistCode', TEST_CODE_GIZMO) | 
					
						
							|  |  |  |     }, TEST_CODE_GIZMO) | 
					
						
							|  |  |  |     await page.setViewportSize({ width: 1000, height: 500 }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await u.waitForAuthSkipAppStart() | 
					
						
							|  |  |  |     await page.waitForTimeout(100) | 
					
						
							|  |  |  |     // wait for execution done
 | 
					
						
							|  |  |  |     await u.openDebugPanel() | 
					
						
							|  |  |  |     await u.expectCmdLog('[data-message-type="execution-done"]') | 
					
						
							|  |  |  |     await u.sendCustomCmd({ | 
					
						
							|  |  |  |       type: 'modeling_cmd_req', | 
					
						
							|  |  |  |       cmd_id: uuidv4(), | 
					
						
							|  |  |  |       cmd: { | 
					
						
							|  |  |  |         type: 'default_camera_look_at', | 
					
						
							|  |  |  |         vantage: { | 
					
						
							|  |  |  |           x: 3000, | 
					
						
							|  |  |  |           y: 3000, | 
					
						
							|  |  |  |           z: 3000, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         center: { | 
					
						
							|  |  |  |           x: 800, | 
					
						
							|  |  |  |           y: -152, | 
					
						
							|  |  |  |           z: 26, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         up: { x: 0, y: 0, z: 1 }, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     await page.waitForTimeout(100) | 
					
						
							|  |  |  |     await u.clearCommandLogs() | 
					
						
							|  |  |  |     await u.sendCustomCmd({ | 
					
						
							|  |  |  |       type: 'modeling_cmd_req', | 
					
						
							|  |  |  |       cmd_id: uuidv4(), | 
					
						
							|  |  |  |       cmd: { | 
					
						
							|  |  |  |         type: 'default_camera_get_settings', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     await u.waitForCmdReceive('default_camera_get_settings') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Now find and select the correct
 | 
					
						
							|  |  |  |     // view from the context menu
 | 
					
						
							|  |  |  |     await u.clearCommandLogs() | 
					
						
							|  |  |  |     const gizmo = page.locator('[aria-label*=gizmo]') | 
					
						
							|  |  |  |     await gizmo.click({ button: 'right' }) | 
					
						
							|  |  |  |     const buttonToTest = page.getByRole('button', { | 
					
						
							|  |  |  |       name: testCase.testDescription, | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |     await _expect(buttonToTest).toBeVisible() | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |     await buttonToTest.click() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Now assert we've moved to the correct view
 | 
					
						
							|  |  |  |     // Taken from the above test
 | 
					
						
							|  |  |  |     await u.waitForCmdReceive('default_camera_look_at') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await u.sendCustomCmd({ | 
					
						
							|  |  |  |       type: 'modeling_cmd_req', | 
					
						
							|  |  |  |       cmd_id: uuidv4(), | 
					
						
							|  |  |  |       cmd: { | 
					
						
							|  |  |  |         type: 'default_camera_get_settings', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     await u.waitForCmdReceive('default_camera_get_settings') | 
					
						
							|  |  |  |     await page.waitForTimeout(400) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await Promise.all([ | 
					
						
							|  |  |  |       // position
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |       _expect(page.getByTestId('cam-x-position')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |         testCase.expectedCameraPosition.x.toString() | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |       _expect(page.getByTestId('cam-y-position')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |         testCase.expectedCameraPosition.y.toString() | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |       _expect(page.getByTestId('cam-z-position')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |         testCase.expectedCameraPosition.z.toString() | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       // target
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |       _expect(page.getByTestId('cam-x-target')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |         testCase.expectedCameraTarget.x.toString() | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |       _expect(page.getByTestId('cam-y-target')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |         testCase.expectedCameraTarget.y.toString() | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |       _expect(page.getByTestId('cam-z-target')).toHaveValue( | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |         testCase.expectedCameraTarget.z.toString() | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Now test the popover menu.
 | 
					
						
							|  |  |  |     // It has the same click handlers, so we can just
 | 
					
						
							|  |  |  |     // test that it opens and contains the same content.
 | 
					
						
							|  |  |  |     const gizmoPopoverButton = page.getByRole('button', { | 
					
						
							|  |  |  |       name: 'view settings', | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |     await _expect(gizmoPopoverButton).toBeVisible() | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |     await gizmoPopoverButton.click() | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |     await _expect(buttonToTest).toBeVisible() | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test.describe(`Testing gizmo, fixture-based`, () => { | 
					
						
							|  |  |  |   test('Center on selection from menu', async ({ | 
					
						
							|  |  |  |     app, | 
					
						
							|  |  |  |     cmdBar, | 
					
						
							|  |  |  |     editor, | 
					
						
							|  |  |  |     toolbar, | 
					
						
							|  |  |  |     scene, | 
					
						
							|  |  |  |   }) => { | 
					
						
							|  |  |  |     test.skip( | 
					
						
							|  |  |  |       process.platform === 'win32', | 
					
						
							|  |  |  |       'Fails on windows in CI, can not be replicated locally on windows.' | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await test.step(`Setup`, async () => { | 
					
						
							|  |  |  |       const file = await app.getInputFile('test-circle-extrude.kcl') | 
					
						
							|  |  |  |       await app.initialise(file) | 
					
						
							|  |  |  |       await scene.expectState({ | 
					
						
							|  |  |  |         camera: { | 
					
						
							|  |  |  |           position: [4982.21, -23865.37, 13810.64], | 
					
						
							|  |  |  |           target: [4982.21, 0, 2737.1], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     const [clickCircle, moveToCircle] = scene.makeMouseHelpers(582, 217) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await test.step(`Select an edge of this circle`, async () => { | 
					
						
							|  |  |  |       const circleSnippet = | 
					
						
							|  |  |  |         'circle({ center: [318.33, 168.1], radius: 182.8 }, %)' | 
					
						
							|  |  |  |       await moveToCircle() | 
					
						
							|  |  |  |       await clickCircle() | 
					
						
							|  |  |  |       await editor.expectState({ | 
					
						
							|  |  |  |         activeLines: [circleSnippet.slice(-5)], | 
					
						
							|  |  |  |         highlightedCode: circleSnippet, | 
					
						
							|  |  |  |         diagnostics: [], | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await test.step(`Center on selection from menu`, async () => { | 
					
						
							|  |  |  |       await scene.clickGizmoMenuItem('Center view on selection') | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await test.step(`Verify the camera moved`, async () => { | 
					
						
							|  |  |  |       await scene.expectState({ | 
					
						
							|  |  |  |         camera: { | 
					
						
							| 
									
										
										
										
											2024-10-22 20:22:52 -04:00
										 |  |  |           position: [0, -23865.37, 11073.53], | 
					
						
							| 
									
										
										
										
											2024-10-04 13:47:44 -07:00
										 |  |  |           target: [0, 0, 0], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2024-08-07 19:27:32 +10:00
										 |  |  |   }) | 
					
						
							|  |  |  | }) |