2024-08-07 19:27:32 +10:00
|
|
|
import { test, expect } from '@playwright/test'
|
2024-08-19 10:23:43 -04:00
|
|
|
import * as fsp from 'fs/promises'
|
2024-08-23 10:50:40 -04:00
|
|
|
import { join } from 'path'
|
|
|
|
import {
|
|
|
|
getUtils,
|
|
|
|
setup,
|
|
|
|
setupElectron,
|
|
|
|
tearDown,
|
|
|
|
executorInputPath,
|
|
|
|
} from './test-utils'
|
2024-09-11 09:39:10 -04:00
|
|
|
import { SaveSettingsPayload, SettingsLevel } from 'lib/settings/settingsTypes'
|
2024-09-13 14:49:33 -04:00
|
|
|
import {
|
|
|
|
TEST_SETTINGS_KEY,
|
|
|
|
TEST_SETTINGS_CORRUPTED,
|
|
|
|
TEST_SETTINGS,
|
|
|
|
} from './storageStates'
|
2024-08-07 19:27:32 +10:00
|
|
|
import * as TOML from '@iarna/toml'
|
|
|
|
|
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.describe('Testing settings', () => {
|
|
|
|
test('Stored settings are validated and fall back to defaults', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
const u = await getUtils(page)
|
|
|
|
|
|
|
|
// Override beforeEach test setup
|
|
|
|
// with corrupted settings
|
|
|
|
await page.addInitScript(
|
|
|
|
async ({ settingsKey, settings }) => {
|
|
|
|
localStorage.setItem(settingsKey, settings)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
settingsKey: TEST_SETTINGS_KEY,
|
|
|
|
settings: TOML.stringify({ settings: TEST_SETTINGS_CORRUPTED }),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
|
|
|
|
await u.waitForAuthSkipAppStart()
|
|
|
|
|
|
|
|
// Check the settings were reset
|
|
|
|
const storedSettings = TOML.parse(
|
|
|
|
await page.evaluate(
|
|
|
|
({ settingsKey }) => localStorage.getItem(settingsKey) || '',
|
|
|
|
{ settingsKey: TEST_SETTINGS_KEY }
|
|
|
|
)
|
|
|
|
) as { settings: SaveSettingsPayload }
|
|
|
|
|
|
|
|
expect(storedSettings.settings?.app?.theme).toBe(undefined)
|
|
|
|
|
|
|
|
// Check that the invalid settings were removed
|
|
|
|
expect(storedSettings.settings?.modeling?.defaultUnit).toBe(undefined)
|
|
|
|
expect(storedSettings.settings?.modeling?.mouseControls).toBe(undefined)
|
|
|
|
expect(storedSettings.settings?.app?.projectDirectory).toBe(undefined)
|
|
|
|
expect(storedSettings.settings?.projects?.defaultProjectName).toBe(
|
|
|
|
undefined
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Project settings can be set and override user settings', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
const u = await getUtils(page)
|
2024-09-20 12:04:36 -04:00
|
|
|
await test.step(`Setup`, async () => {
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
await u.waitForAuthSkipAppStart()
|
|
|
|
await page
|
|
|
|
.getByRole('button', { name: 'Start Sketch' })
|
|
|
|
.waitFor({ state: 'visible' })
|
|
|
|
})
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2024-09-20 12:04:36 -04:00
|
|
|
// Selectors and constants
|
2024-08-12 15:18:33 -04:00
|
|
|
const paneButtonLocator = page.getByTestId('debug-pane-button')
|
|
|
|
const headingLocator = page.getByRole('heading', {
|
|
|
|
name: 'Settings',
|
|
|
|
exact: true,
|
|
|
|
})
|
|
|
|
const inputLocator = page.locator('input[name="modeling-showDebugPanel"]')
|
|
|
|
|
2024-09-20 12:04:36 -04:00
|
|
|
await test.step('Open settings dialog and set "Show debug panel" to on', async () => {
|
|
|
|
await page.keyboard.press('ControlOrMeta+Shift+,')
|
|
|
|
await expect(headingLocator).toBeVisible()
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2024-09-20 12:04:36 -04:00
|
|
|
/** Test to close https://github.com/KittyCAD/modeling-app/issues/2713 */
|
|
|
|
await test.step(`Confirm that this dialog has a solid background`, async () => {
|
|
|
|
await expect
|
|
|
|
.poll(() => u.getGreatestPixDiff({ x: 600, y: 250 }, [28, 28, 28]), {
|
|
|
|
timeout: 1000,
|
|
|
|
message:
|
|
|
|
'Checking for solid background, should not see default plane colors',
|
|
|
|
})
|
|
|
|
.toBeLessThan(15)
|
|
|
|
})
|
|
|
|
|
|
|
|
await page.locator('#showDebugPanel').getByText('OffOn').click()
|
|
|
|
})
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2024-08-12 15:18:33 -04:00
|
|
|
// Close it and open again with keyboard shortcut, while KCL editor is focused
|
2024-08-07 19:27:32 +10:00
|
|
|
// Put the cursor in the editor
|
2024-08-12 15:18:33 -04:00
|
|
|
await test.step('Open settings with keyboard shortcut', async () => {
|
|
|
|
await page.getByTestId('settings-close-button').click()
|
|
|
|
await page.locator('.cm-content').click()
|
2024-08-22 19:13:27 -04:00
|
|
|
await page.keyboard.press('ControlOrMeta+Shift+,')
|
2024-08-12 15:18:33 -04:00
|
|
|
await expect(headingLocator).toBeVisible()
|
|
|
|
})
|
2024-08-07 19:27:32 +10:00
|
|
|
|
|
|
|
// Verify the toast appeared
|
|
|
|
await expect(
|
2024-08-12 15:18:33 -04:00
|
|
|
page.getByText(`Set show debug panel to "false" for this project`)
|
2024-08-07 19:27:32 +10:00
|
|
|
).toBeVisible()
|
|
|
|
// Check that the theme changed
|
2024-08-12 15:18:33 -04:00
|
|
|
await expect(paneButtonLocator).not.toBeVisible()
|
2024-08-07 19:27:32 +10:00
|
|
|
|
|
|
|
// Check that the user setting was not changed
|
|
|
|
await page.getByRole('radio', { name: 'User' }).click()
|
2024-08-12 15:18:33 -04:00
|
|
|
await expect(inputLocator).toBeChecked()
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2024-08-12 15:18:33 -04:00
|
|
|
// Roll back to default of "off"
|
|
|
|
await await page
|
|
|
|
.getByText('show debug panelRoll back show debug panelRoll back to match')
|
2024-08-07 19:27:32 +10:00
|
|
|
.hover()
|
|
|
|
await page
|
|
|
|
.getByRole('button', {
|
2024-08-12 15:18:33 -04:00
|
|
|
name: 'Roll back show debug panel',
|
2024-08-07 19:27:32 +10:00
|
|
|
})
|
|
|
|
.click()
|
2024-08-12 15:18:33 -04:00
|
|
|
await expect(inputLocator).not.toBeChecked()
|
2024-08-07 19:27:32 +10:00
|
|
|
|
|
|
|
// Check that the project setting did not change
|
|
|
|
await page.getByRole('radio', { name: 'Project' }).click()
|
2024-08-12 15:18:33 -04:00
|
|
|
await expect(
|
|
|
|
page.locator('input[name="modeling-showDebugPanel"]')
|
|
|
|
).not.toBeChecked()
|
2024-08-07 19:27:32 +10:00
|
|
|
})
|
|
|
|
|
2024-08-23 16:20:22 -04:00
|
|
|
test('Keybindings display the correct hotkey for Command Palette', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
const u = await getUtils(page)
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
await u.waitForAuthSkipAppStart()
|
|
|
|
|
|
|
|
await test.step('Open keybindings settings', async () => {
|
|
|
|
// Open the settings modal with the browser keyboard shortcut
|
|
|
|
await page.keyboard.press('ControlOrMeta+Shift+,')
|
|
|
|
|
|
|
|
// Go to Keybindings tab.
|
|
|
|
const keybindingsTab = page.getByRole('radio', { name: 'Keybindings' })
|
|
|
|
await keybindingsTab.click()
|
|
|
|
})
|
|
|
|
|
|
|
|
// Go to the hotkey for Command Palette.
|
|
|
|
const commandPalette = page.getByText('Toggle Command Palette')
|
|
|
|
await commandPalette.scrollIntoViewIfNeeded()
|
|
|
|
|
|
|
|
// The heading is above it and should be in view now.
|
|
|
|
const commandPaletteHeading = page.getByRole('heading', {
|
|
|
|
name: 'Command Palette',
|
|
|
|
})
|
|
|
|
// The hotkey is in a kbd element next to the heading.
|
|
|
|
const hotkey = commandPaletteHeading.locator('+ div kbd')
|
|
|
|
const text = process.platform === 'darwin' ? 'Command+K' : 'Control+K'
|
|
|
|
await expect(hotkey).toHaveText(text)
|
|
|
|
})
|
|
|
|
|
2024-08-20 14:06:39 -04:00
|
|
|
test('Project and user settings can be reset', async ({ page }) => {
|
2024-08-07 19:27:32 +10:00
|
|
|
const u = await getUtils(page)
|
2024-09-11 09:39:10 -04:00
|
|
|
await test.step(`Setup`, async () => {
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
await u.waitForAuthSkipAppStart()
|
|
|
|
})
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2024-09-11 09:39:10 -04:00
|
|
|
// Selectors and constants
|
2024-08-12 15:18:33 -04:00
|
|
|
const projectSettingsTab = page.getByRole('radio', { name: 'Project' })
|
|
|
|
const userSettingsTab = page.getByRole('radio', { name: 'User' })
|
2024-09-11 09:39:10 -04:00
|
|
|
const resetButton = (level: SettingsLevel) =>
|
|
|
|
page.getByRole('button', {
|
|
|
|
name: `Reset ${level}-level settings`,
|
|
|
|
})
|
2024-08-12 15:18:33 -04:00
|
|
|
const themeColorSetting = page.locator('#themeColor').getByRole('slider')
|
|
|
|
const settingValues = {
|
|
|
|
default: '259',
|
|
|
|
user: '120',
|
|
|
|
project: '50',
|
|
|
|
}
|
2024-09-11 09:39:10 -04:00
|
|
|
const resetToast = (level: SettingsLevel) =>
|
|
|
|
page.getByText(`${level}-level settings were reset`)
|
2024-08-12 15:18:33 -04:00
|
|
|
|
2024-09-11 09:39:10 -04:00
|
|
|
await test.step(`Open the settings modal`, async () => {
|
|
|
|
await page.getByRole('link', { name: 'Settings' }).last().click()
|
|
|
|
await expect(
|
|
|
|
page.getByRole('heading', { name: 'Settings', exact: true })
|
|
|
|
).toBeVisible()
|
|
|
|
})
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2024-08-12 15:18:33 -04:00
|
|
|
await test.step('Set up theme color', async () => {
|
|
|
|
// Verify we're looking at the project-level settings,
|
|
|
|
// and it's set to default value
|
|
|
|
await expect(projectSettingsTab).toBeChecked()
|
|
|
|
await expect(themeColorSetting).toHaveValue(settingValues.default)
|
|
|
|
|
|
|
|
// Set project-level value to 50
|
|
|
|
await themeColorSetting.fill(settingValues.project)
|
|
|
|
|
|
|
|
// Set user-level value to 120
|
|
|
|
await userSettingsTab.click()
|
|
|
|
await themeColorSetting.fill(settingValues.user)
|
|
|
|
await projectSettingsTab.click()
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step('Reset project settings', async () => {
|
|
|
|
// Click the reset settings button.
|
2024-09-11 09:39:10 -04:00
|
|
|
await resetButton('project').click()
|
2024-08-12 15:18:33 -04:00
|
|
|
|
2024-09-11 09:39:10 -04:00
|
|
|
await expect(resetToast('project')).toBeVisible()
|
|
|
|
await expect(resetToast('project')).not.toBeVisible()
|
2024-08-20 14:06:39 -04:00
|
|
|
|
2024-08-12 15:18:33 -04:00
|
|
|
// Verify it is now set to the inherited user value
|
2024-09-11 09:39:10 -04:00
|
|
|
await expect(themeColorSetting).toHaveValue(settingValues.user)
|
2024-08-12 15:18:33 -04:00
|
|
|
|
2024-09-11 09:39:10 -04:00
|
|
|
await test.step(`Check that the user settings did not change`, async () => {
|
|
|
|
await userSettingsTab.click()
|
|
|
|
await expect(themeColorSetting).toHaveValue(settingValues.user)
|
|
|
|
})
|
2024-08-12 15:18:33 -04:00
|
|
|
|
2024-09-11 09:39:10 -04:00
|
|
|
await test.step(`Set project-level again to test the user-level reset`, async () => {
|
|
|
|
await projectSettingsTab.click()
|
|
|
|
await themeColorSetting.fill(settingValues.project)
|
|
|
|
await userSettingsTab.click()
|
|
|
|
})
|
2024-08-12 15:18:33 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
await test.step('Reset user settings', async () => {
|
2024-09-11 09:39:10 -04:00
|
|
|
// Click the reset settings button.
|
|
|
|
await resetButton('user').click()
|
|
|
|
|
|
|
|
await expect(resetToast('user')).toBeVisible()
|
|
|
|
await expect(resetToast('user')).not.toBeVisible()
|
2024-08-12 15:18:33 -04:00
|
|
|
|
|
|
|
// Verify it is now set to the default value
|
|
|
|
await expect(themeColorSetting).toHaveValue(settingValues.default)
|
|
|
|
|
2024-09-11 09:39:10 -04:00
|
|
|
await test.step(`Check that the project settings did not change`, async () => {
|
|
|
|
await projectSettingsTab.click()
|
|
|
|
await expect(themeColorSetting).toHaveValue(settingValues.project)
|
|
|
|
})
|
2024-08-12 15:18:33 -04:00
|
|
|
})
|
2024-08-07 19:27:32 +10:00
|
|
|
})
|
2024-08-19 10:23:43 -04:00
|
|
|
|
|
|
|
test(
|
|
|
|
`Project settings override user settings on desktop`,
|
|
|
|
{ tag: '@electron' },
|
|
|
|
async ({ browser: _ }, testInfo) => {
|
2024-08-20 16:37:16 +10:00
|
|
|
test.skip(
|
|
|
|
process.platform === 'win32',
|
|
|
|
'TODO: remove this skip https://github.com/KittyCAD/modeling-app/issues/3557'
|
|
|
|
)
|
2024-08-19 10:23:43 -04:00
|
|
|
const { electronApp, page } = await setupElectron({
|
|
|
|
testInfo,
|
|
|
|
folderSetupFn: async (dir) => {
|
2024-08-23 10:50:40 -04:00
|
|
|
const bracketDir = join(dir, 'bracket')
|
|
|
|
await fsp.mkdir(bracketDir, { recursive: true })
|
2024-08-19 10:23:43 -04:00
|
|
|
await fsp.copyFile(
|
2024-08-23 10:50:40 -04:00
|
|
|
executorInputPath('focusrite_scarlett_mounting_braket.kcl'),
|
|
|
|
join(bracketDir, 'main.kcl')
|
2024-08-19 10:23:43 -04:00
|
|
|
)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
|
|
|
|
page.on('console', console.log)
|
|
|
|
|
|
|
|
// Selectors and constants
|
|
|
|
const userThemeColor = '120'
|
|
|
|
const projectThemeColor = '50'
|
|
|
|
const settingsOpenButton = page.getByRole('link', {
|
|
|
|
name: 'settings Settings',
|
|
|
|
})
|
|
|
|
const themeColorSetting = page.locator('#themeColor').getByRole('slider')
|
|
|
|
const projectSettingsTab = page.getByRole('radio', { name: 'Project' })
|
|
|
|
const userSettingsTab = page.getByRole('radio', { name: 'User' })
|
|
|
|
const settingsCloseButton = page.getByTestId('settings-close-button')
|
|
|
|
const projectLink = page.getByText('bracket')
|
|
|
|
const logoLink = page.getByTestId('app-logo')
|
|
|
|
|
|
|
|
// Open the app and set the user theme color
|
|
|
|
await test.step('Set user theme color on home', async () => {
|
|
|
|
await expect(settingsOpenButton).toBeVisible()
|
|
|
|
await settingsOpenButton.click()
|
|
|
|
// The user tab should be selected by default on home
|
|
|
|
await expect(userSettingsTab).toBeChecked()
|
|
|
|
await themeColorSetting.fill(userThemeColor)
|
|
|
|
await expect(logoLink).toHaveCSS('--primary-hue', userThemeColor)
|
|
|
|
await settingsCloseButton.click()
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step('Set project theme color', async () => {
|
|
|
|
// Open the project
|
|
|
|
await projectLink.click()
|
|
|
|
await settingsOpenButton.click()
|
|
|
|
// The project tab should be selected by default within a project
|
|
|
|
await expect(projectSettingsTab).toBeChecked()
|
|
|
|
await themeColorSetting.fill(projectThemeColor)
|
|
|
|
await expect(logoLink).toHaveCSS('--primary-hue', projectThemeColor)
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step('Refresh the application and see project setting applied', async () => {
|
2024-09-06 17:14:02 -04:00
|
|
|
await page.reload({ waitUntil: 'domcontentloaded' })
|
2024-08-19 10:23:43 -04:00
|
|
|
|
|
|
|
await expect(logoLink).toHaveCSS('--primary-hue', projectThemeColor)
|
|
|
|
await settingsCloseButton.click()
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step(`Navigate back to the home view and see user setting applied`, async () => {
|
|
|
|
await logoLink.click()
|
|
|
|
await expect(logoLink).toHaveCSS('--primary-hue', userThemeColor)
|
|
|
|
})
|
|
|
|
|
|
|
|
await electronApp.close()
|
|
|
|
}
|
|
|
|
)
|
2024-08-22 13:38:53 -04:00
|
|
|
|
2024-09-04 11:30:09 -04:00
|
|
|
test(
|
|
|
|
`Load desktop app with no settings file`,
|
|
|
|
{ tag: '@electron' },
|
|
|
|
async ({ browser: _ }, testInfo) => {
|
|
|
|
const { electronApp, page } = await setupElectron({
|
|
|
|
// This is what makes no settings file get created
|
|
|
|
cleanProjectDir: false,
|
|
|
|
testInfo,
|
|
|
|
})
|
|
|
|
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
|
|
|
|
// Selectors and constants
|
|
|
|
const errorHeading = page.getByRole('heading', {
|
|
|
|
name: 'An unextected error occurred',
|
|
|
|
})
|
|
|
|
const projectDirLink = page.getByText('Loaded from')
|
|
|
|
|
|
|
|
// If the app loads without exploding we're in the clear
|
|
|
|
await expect(errorHeading).not.toBeVisible()
|
|
|
|
await expect(projectDirLink).toBeVisible()
|
|
|
|
|
|
|
|
await electronApp.close()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
`Load desktop app with a settings file, but no project directory setting`,
|
|
|
|
{ tag: '@electron' },
|
|
|
|
async ({ browser: _ }, testInfo) => {
|
|
|
|
const { electronApp, page } = await setupElectron({
|
|
|
|
testInfo,
|
|
|
|
appSettings: {
|
|
|
|
app: {
|
|
|
|
themeColor: '259',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
|
|
|
|
// Selectors and constants
|
|
|
|
const errorHeading = page.getByRole('heading', {
|
|
|
|
name: 'An unextected error occurred',
|
|
|
|
})
|
|
|
|
const projectDirLink = page.getByText('Loaded from')
|
|
|
|
|
|
|
|
// If the app loads without exploding we're in the clear
|
|
|
|
await expect(errorHeading).not.toBeVisible()
|
|
|
|
await expect(projectDirLink).toBeVisible()
|
|
|
|
|
|
|
|
await electronApp.close()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-08-22 13:38:53 -04:00
|
|
|
test(
|
|
|
|
`Closing settings modal should go back to the original file being viewed`,
|
|
|
|
{ tag: '@electron' },
|
|
|
|
async ({ browser: _ }, testInfo) => {
|
|
|
|
const { electronApp, page } = await setupElectron({
|
|
|
|
testInfo,
|
2024-09-06 18:15:13 -04:00
|
|
|
folderSetupFn: async (dir) => {
|
|
|
|
const bracketDir = join(dir, 'project-000')
|
|
|
|
await fsp.mkdir(bracketDir, { recursive: true })
|
|
|
|
await fsp.copyFile(
|
|
|
|
executorInputPath('cube.kcl'),
|
|
|
|
join(bracketDir, 'main.kcl')
|
|
|
|
)
|
|
|
|
await fsp.copyFile(
|
|
|
|
executorInputPath('cylinder.kcl'),
|
|
|
|
join(bracketDir, '2.kcl')
|
|
|
|
)
|
|
|
|
},
|
2024-08-22 13:38:53 -04:00
|
|
|
})
|
2024-09-06 18:15:13 -04:00
|
|
|
const kclCube = await fsp.readFile(executorInputPath('cube.kcl'), 'utf-8')
|
|
|
|
const kclCylinder = await fsp.readFile(
|
|
|
|
executorInputPath('cylinder.kcl'),
|
|
|
|
'utf8'
|
|
|
|
)
|
2024-08-22 13:38:53 -04:00
|
|
|
|
|
|
|
const {
|
2024-09-06 17:14:02 -04:00
|
|
|
openKclCodePanel,
|
|
|
|
openFilePanel,
|
2024-09-06 18:15:13 -04:00
|
|
|
waitForPageLoad,
|
|
|
|
selectFile,
|
2024-08-22 13:38:53 -04:00
|
|
|
editorTextMatches,
|
|
|
|
} = await getUtils(page, test)
|
|
|
|
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
page.on('console', console.log)
|
|
|
|
|
2024-09-06 18:15:13 -04:00
|
|
|
await test.step('Precondition: Open to second project file', async () => {
|
2024-08-22 13:38:53 -04:00
|
|
|
await expect(page.getByTestId('home-section')).toBeVisible()
|
2024-09-06 18:15:13 -04:00
|
|
|
await page.getByText('project-000').click()
|
|
|
|
await waitForPageLoad()
|
|
|
|
await openKclCodePanel()
|
|
|
|
await openFilePanel()
|
|
|
|
await editorTextMatches(kclCube)
|
2024-08-22 13:38:53 -04:00
|
|
|
|
2024-09-06 18:15:13 -04:00
|
|
|
await selectFile('2.kcl')
|
|
|
|
await editorTextMatches(kclCylinder)
|
|
|
|
})
|
2024-08-22 13:38:53 -04:00
|
|
|
|
|
|
|
const settingsOpenButton = page.getByRole('link', {
|
|
|
|
name: 'settings Settings',
|
|
|
|
})
|
|
|
|
const settingsCloseButton = page.getByTestId('settings-close-button')
|
|
|
|
|
|
|
|
await test.step('Open and close settings', async () => {
|
|
|
|
await settingsOpenButton.click()
|
2024-09-06 18:15:13 -04:00
|
|
|
await expect(
|
|
|
|
page.getByRole('heading', { name: 'Settings', exact: true })
|
|
|
|
).toBeVisible()
|
2024-08-22 13:38:53 -04:00
|
|
|
await settingsCloseButton.click()
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step('Postcondition: Same file content is in editor as before settings opened', async () => {
|
|
|
|
await editorTextMatches(kclCylinder)
|
|
|
|
})
|
|
|
|
|
|
|
|
await electronApp.close()
|
|
|
|
}
|
|
|
|
)
|
2024-08-24 18:51:50 -05:00
|
|
|
|
|
|
|
test('Changing modeling default unit', async ({ page }) => {
|
|
|
|
const u = await getUtils(page)
|
2024-09-11 09:39:10 -04:00
|
|
|
await test.step(`Test setup`, async () => {
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
await u.waitForAuthSkipAppStart()
|
|
|
|
await page
|
|
|
|
.getByRole('button', { name: 'Start Sketch' })
|
|
|
|
.waitFor({ state: 'visible' })
|
|
|
|
})
|
2024-08-24 18:51:50 -05:00
|
|
|
|
2024-09-11 09:39:10 -04:00
|
|
|
// Selectors and constants
|
2024-08-24 18:51:50 -05:00
|
|
|
const userSettingsTab = page.getByRole('radio', { name: 'User' })
|
2024-09-11 09:39:10 -04:00
|
|
|
const projectSettingsTab = page.getByRole('radio', { name: 'Project' })
|
|
|
|
const defaultUnitSection = page.getByText(
|
|
|
|
'default unitRoll back default unitRoll back to match'
|
|
|
|
)
|
|
|
|
const defaultUnitRollbackButton = page.getByRole('button', {
|
|
|
|
name: 'Roll back default unit',
|
|
|
|
})
|
2024-08-24 18:51:50 -05:00
|
|
|
|
2024-09-11 09:39:10 -04:00
|
|
|
await test.step(`Open the settings modal`, async () => {
|
|
|
|
await page.getByRole('link', { name: 'Settings' }).last().click()
|
|
|
|
await expect(
|
|
|
|
page.getByRole('heading', { name: 'Settings', exact: true })
|
|
|
|
).toBeVisible()
|
|
|
|
})
|
2024-08-24 18:51:50 -05:00
|
|
|
|
2024-09-11 09:39:10 -04:00
|
|
|
await test.step(`Reset unit setting`, async () => {
|
|
|
|
await userSettingsTab.click()
|
|
|
|
await defaultUnitSection.hover()
|
|
|
|
await defaultUnitRollbackButton.click()
|
|
|
|
await projectSettingsTab.click()
|
2024-08-24 18:51:50 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
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')
|
|
|
|
})
|
|
|
|
})
|
2024-09-10 13:30:39 -04:00
|
|
|
|
|
|
|
test('Changing theme in sketch mode', async ({ page }) => {
|
|
|
|
const u = await getUtils(page)
|
|
|
|
await page.addInitScript(() => {
|
|
|
|
localStorage.setItem(
|
|
|
|
'persistCode',
|
|
|
|
`const sketch001 = startSketchOn('XZ')
|
|
|
|
|> startProfileAt([0, 0], %)
|
|
|
|
|> line([5, 0], %)
|
|
|
|
|> line([0, 5], %)
|
|
|
|
|> line([-5, 0], %)
|
|
|
|
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
|
|
|
|> close(%)
|
|
|
|
const extrude001 = extrude(5, sketch001)
|
|
|
|
`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
|
|
|
|
// Selectors and constants
|
|
|
|
const editSketchButton = page.getByRole('button', { name: 'Edit Sketch' })
|
|
|
|
const lineToolButton = page.getByTestId('line')
|
|
|
|
const segmentOverlays = page.getByTestId('segment-overlay')
|
|
|
|
const sketchOriginLocation = { x: 600, y: 250 }
|
|
|
|
const darkThemeSegmentColor: [number, number, number] = [215, 215, 215]
|
|
|
|
const lightThemeSegmentColor: [number, number, number] = [90, 90, 90]
|
|
|
|
|
|
|
|
await test.step(`Get into sketch mode`, async () => {
|
|
|
|
await u.waitForAuthSkipAppStart()
|
|
|
|
await page.mouse.click(700, 200)
|
|
|
|
await expect(editSketchButton).toBeVisible()
|
|
|
|
await editSketchButton.click()
|
|
|
|
|
|
|
|
// We use the line tool as a proxy for sketch mode
|
|
|
|
await expect(lineToolButton).toBeVisible()
|
|
|
|
await expect(segmentOverlays).toHaveCount(4)
|
|
|
|
// but we allow more time to pass for animating to the sketch
|
|
|
|
await page.waitForTimeout(1000)
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step(`Check the sketch line color before`, async () => {
|
|
|
|
await expect
|
|
|
|
.poll(() =>
|
|
|
|
u.getGreatestPixDiff(sketchOriginLocation, darkThemeSegmentColor)
|
|
|
|
)
|
|
|
|
.toBeLessThan(15)
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step(`Change theme to light using command palette`, async () => {
|
|
|
|
await page.keyboard.press('ControlOrMeta+K')
|
|
|
|
await page.getByRole('option', { name: 'theme' }).click()
|
|
|
|
await page.getByRole('option', { name: 'light' }).click()
|
|
|
|
await expect(page.getByText('theme to "light"')).toBeVisible()
|
|
|
|
|
|
|
|
// Make sure we haven't left sketch mode
|
|
|
|
await expect(lineToolButton).toBeVisible()
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step(`Check the sketch line color after`, async () => {
|
|
|
|
await expect
|
|
|
|
.poll(() =>
|
|
|
|
u.getGreatestPixDiff(sketchOriginLocation, lightThemeSegmentColor)
|
|
|
|
)
|
|
|
|
.toBeLessThan(15)
|
|
|
|
})
|
|
|
|
})
|
2024-09-13 14:49:33 -04:00
|
|
|
|
|
|
|
test(`Turning off "Show debug panel" with debug panel open leaves no phantom panel`, async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
const u = await getUtils(page)
|
|
|
|
|
|
|
|
// Override beforeEach test setup
|
|
|
|
// with debug panel open
|
|
|
|
// but "show debug panel" set to false
|
|
|
|
await page.addInitScript(
|
|
|
|
async ({ settingsKey, settings }) => {
|
|
|
|
localStorage.setItem(settingsKey, settings)
|
|
|
|
localStorage.setItem(
|
|
|
|
'persistModelingContext',
|
|
|
|
'{"openPanes":["debug"]}'
|
|
|
|
)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
settingsKey: TEST_SETTINGS_KEY,
|
|
|
|
settings: TOML.stringify({
|
|
|
|
settings: {
|
|
|
|
...TEST_SETTINGS,
|
|
|
|
modeling: { ...TEST_SETTINGS.modeling, showDebugPanel: false },
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
|
|
|
|
|
|
|
// Constants and locators
|
|
|
|
const resizeHandle = page.locator('.sidebar-resize-handles > div.block')
|
|
|
|
const debugPaneButton = page.getByTestId('debug-pane-button')
|
|
|
|
const commandsButton = page.getByRole('button', { name: 'Commands' })
|
|
|
|
const debugPaneOption = page.getByRole('option', {
|
|
|
|
name: 'Settings · modeling · show debug panel',
|
|
|
|
})
|
|
|
|
|
|
|
|
async function setShowDebugPanelTo(value: 'On' | 'Off') {
|
|
|
|
await commandsButton.click()
|
|
|
|
await debugPaneOption.click()
|
|
|
|
await page.getByRole('option', { name: value }).click()
|
|
|
|
await expect(
|
|
|
|
page.getByText(
|
|
|
|
`Set show debug panel to "${value === 'On'}" for this project`
|
|
|
|
)
|
|
|
|
).toBeVisible()
|
|
|
|
}
|
|
|
|
|
|
|
|
await test.step(`Initial load with corrupted settings`, async () => {
|
|
|
|
await u.waitForAuthSkipAppStart()
|
|
|
|
// Check that the debug panel is not visible
|
|
|
|
await expect(debugPaneButton).not.toBeVisible()
|
|
|
|
// Check the pane resize handle wrapper is not visible
|
|
|
|
await expect(resizeHandle).not.toBeVisible()
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step(`Open code pane to verify we see the resize handles`, async () => {
|
|
|
|
await u.openKclCodePanel()
|
|
|
|
await expect(resizeHandle).toBeVisible()
|
|
|
|
await u.closeKclCodePanel()
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step(`Turn on debug panel, open it`, async () => {
|
|
|
|
await setShowDebugPanelTo('On')
|
|
|
|
await expect(debugPaneButton).toBeVisible()
|
|
|
|
// We want the logic to clear the phantom panel, so we shouldn't see
|
|
|
|
// the real panel (and therefore the resize handle) yet
|
|
|
|
await expect(resizeHandle).not.toBeVisible()
|
|
|
|
await u.openDebugPanel()
|
|
|
|
await expect(resizeHandle).toBeVisible()
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step(`Turn off debug panel setting with it open`, async () => {
|
|
|
|
await setShowDebugPanelTo('Off')
|
|
|
|
await expect(debugPaneButton).not.toBeVisible()
|
|
|
|
await expect(resizeHandle).not.toBeVisible()
|
|
|
|
})
|
|
|
|
})
|
2024-08-07 19:27:32 +10:00
|
|
|
})
|