From fbf0d3d95320e9835ba744e27e5e8c59afbbd026 Mon Sep 17 00:00:00 2001 From: Kevin Nadro Date: Sat, 24 Aug 2024 18:51:50 -0500 Subject: [PATCH] Nadro/3581/change base unit test (#3621) * fix: Updating the playwright tests section * fix: cleaning up formatting for playwright test markdown * fix: autocomplete put a 3rd * * chore: e2e playwright for change of base unit in multiple scenarios * fix: fmt auto format * fix: fmt and clean up for PR * fix: removing typo * fix: added the ) formatting back * fix: linting errors + formatting * fix: removing unused testing code from previous logic --------- Co-authored-by: Jess Frazelle --- README.md | 30 ++++-- e2e/playwright/testing-settings.spec.ts | 126 ++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 76341cd631..e22dfd4611 100644 --- a/README.md +++ b/README.md @@ -189,12 +189,22 @@ For more information on fuzzing you can check out ### Playwright tests +You will need a `./e2e/playwright/playwright-secrets.env` file: + +```bash +$ touch ./e2e/playwright/playwright-secrets.env +$ cat ./e2e/playwright/playwright-secrets.env +token= +snapshottoken= +``` + For a portable way to run Playwright you'll need Docker. +#### Generic example After that, open a terminal and run: ```bash -docker run --network host --rm --init -it playwright/chrome:playwright-1.43.1 +docker run --network host --rm --init -it playwright/chrome:playwright-x.xx.x ``` and in another terminal, run: @@ -203,21 +213,27 @@ and in another terminal, run: PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:4444/ yarn playwright test --project="Google Chrome" ``` -An example of a `` is: `e2e/playwright/flow-tests.spec.ts` -YOU WILL NEED A PLAYWRIGHT-SECRETS.ENV FILE: +#### Specific example +open a terminal and run: ```bash -# ./e2e/playwright/playwright-secrets.env -token= -snapshottoken= +docker run --network host --rm --init -it playwright/chrome:playwright-1.46.0 +``` + +and in another terminal, run: + +```bash +PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:4444/ yarn playwright test --project="Google Chrome" e2e/playwright/command-bar-tests.spec.ts ``` -then replace "your-token" with a dev token from dev.zoo.dev/account/api-tokens run a specific test change the test from `test('...` to `test.only('...` (note if you commit this, the tests will instantly fail without running any of the tests) + +**Gotcha**: running the docker container with a mismatched image against your `./node_modules/playwright` will cause a failure. Make sure the versions are matched and up to date. + run headed ``` diff --git a/e2e/playwright/testing-settings.spec.ts b/e2e/playwright/testing-settings.spec.ts index c4a888894e..6ee51d3623 100644 --- a/e2e/playwright/testing-settings.spec.ts +++ b/e2e/playwright/testing-settings.spec.ts @@ -367,4 +367,130 @@ test.describe('Testing settings', () => { await electronApp.close() } ) + + test('Changing modeling default unit', async ({ page }) => { + const u = await getUtils(page) + await page.setViewportSize({ width: 1200, height: 500 }) + await u.waitForAuthSkipAppStart() + await page + .getByRole('button', { name: 'Start Sketch' }) + .waitFor({ state: 'visible' }) + + const userSettingsTab = page.getByRole('radio', { name: 'User' }) + + // Open the settings modal with lower-right button + await page.getByRole('link', { name: 'Settings' }).last().click() + await expect( + page.getByRole('heading', { name: 'Settings', exact: true }) + ).toBeVisible() + + const resetButton = page.getByRole('button', { + name: 'Restore default settings', + }) + // Default unit should be mm + await resetButton.click() + + await test.step('Change modeling default unit within project tab', async () => { + const changeUnitOfMeasureInProjectTab = async (unitOfMeasure: string) => { + await test.step(`Set modeling default unit to ${unitOfMeasure}`, async () => { + await page + .getByTestId('modeling-defaultUnit') + .selectOption(`${unitOfMeasure}`) + const toastMessage = page.getByText( + `Set default unit to "${unitOfMeasure}" for this project` + ) + await expect(toastMessage).toBeVisible() + }) + } + await changeUnitOfMeasureInProjectTab('in') + await changeUnitOfMeasureInProjectTab('ft') + await changeUnitOfMeasureInProjectTab('yd') + await changeUnitOfMeasureInProjectTab('mm') + await changeUnitOfMeasureInProjectTab('cm') + await changeUnitOfMeasureInProjectTab('m') + }) + + // Go to the user tab + await userSettingsTab.click() + await test.step('Change modeling default unit within user tab', async () => { + const changeUnitOfMeasureInUserTab = async (unitOfMeasure: string) => { + await test.step(`Set modeling default unit to ${unitOfMeasure}`, async () => { + await page + .getByTestId('modeling-defaultUnit') + .selectOption(`${unitOfMeasure}`) + const toastMessage = page.getByText( + `Set default unit to "${unitOfMeasure}" as a user default` + ) + await expect(toastMessage).toBeVisible() + }) + } + await changeUnitOfMeasureInUserTab('in') + await changeUnitOfMeasureInUserTab('ft') + await changeUnitOfMeasureInUserTab('yd') + await changeUnitOfMeasureInUserTab('mm') + await changeUnitOfMeasureInUserTab('cm') + await changeUnitOfMeasureInUserTab('m') + }) + + // Close settings + const settingsCloseButton = page.getByTestId('settings-close-button') + await settingsCloseButton.click() + + await test.step('Change modeling default unit within command bar', async () => { + const commands = page.getByRole('button', { name: 'Commands' }) + const changeUnitOfMeasureInCommandBar = async (unitOfMeasure: string) => { + // Open command bar + await commands.click() + const settingsModelingDefaultUnitCommand = page.getByText( + 'Settings · modeling · default unit' + ) + await settingsModelingDefaultUnitCommand.click() + + const commandOption = page.getByRole('option', { + name: unitOfMeasure, + exact: true, + }) + await commandOption.click() + + const toastMessage = page.getByText( + `Set default unit to "${unitOfMeasure}" for this project` + ) + await expect(toastMessage).toBeVisible() + } + await changeUnitOfMeasureInCommandBar('in') + await changeUnitOfMeasureInCommandBar('ft') + await changeUnitOfMeasureInCommandBar('yd') + await changeUnitOfMeasureInCommandBar('mm') + await changeUnitOfMeasureInCommandBar('cm') + await changeUnitOfMeasureInCommandBar('m') + }) + + await test.step('Change modeling default unit within gizmo', async () => { + const changeUnitOfMeasureInGizmo = async ( + unitOfMeasure: string, + copy: string + ) => { + const gizmo = page.getByRole('button', { + name: 'Current units are: ', + }) + await gizmo.click() + const button = page.getByRole('button', { + name: copy, + exact: true, + }) + await button.click() + const toastMessage = page.getByText( + `Set default unit to "${unitOfMeasure}" for this project` + ) + await expect(toastMessage).toBeVisible() + } + + await changeUnitOfMeasureInGizmo('in', 'Inches') + await changeUnitOfMeasureInGizmo('ft', 'Feet') + await changeUnitOfMeasureInGizmo('yd', 'Yards') + await changeUnitOfMeasureInGizmo('mm', 'Millimeters') + await changeUnitOfMeasureInGizmo('cm', 'Centimeters') + await changeUnitOfMeasureInGizmo('m', 'Meters') + }) + }) })