Test: restart electron with settings intact (#3488)

* Test: restart electron with settings intact

* Make testing-selections 1px less sensitive
This commit is contained in:
Adam Sunderland
2024-08-16 15:24:36 -04:00
committed by GitHub
parent 0c15299b0e
commit 9d71900caf
3 changed files with 68 additions and 19 deletions

View File

@ -774,3 +774,46 @@ test(
await electronApp.close() await electronApp.close()
} }
) )
test(
'Settings persist across restarts',
{ tag: '@electron' },
async ({ browserName }, testInfo) => {
await test.step('We can change a user setting like theme', async () => {
const { electronApp, page } = await setupElectron({
testInfo,
})
await page.setViewportSize({ width: 1200, height: 500 })
page.on('console', console.log)
await page.getByTestId('user-sidebar-toggle').click()
await page.getByTestId('user-settings').click()
await expect(page.getByTestId('app-theme')).toHaveValue('dark')
await page.getByTestId('app-theme').selectOption('light')
await electronApp.close()
})
await test.step('Starting the app again and we can see the same theme', async () => {
let { electronApp, page } = await setupElectron({
testInfo,
cleanProjectDir: false,
})
await page.setViewportSize({ width: 1200, height: 500 })
page.on('console', console.log)
await page.getByTestId('user-sidebar-toggle').click()
await page.getByTestId('user-settings').click()
await expect(page.getByTestId('app-theme')).toHaveValue('light')
await electronApp.close()
})
}
)

View File

@ -676,21 +676,25 @@ export async function setup(context: BrowserContext, page: Page) {
export async function setupElectron({ export async function setupElectron({
testInfo, testInfo,
folderSetupFn, folderSetupFn,
cleanProjectDir = true,
}: { }: {
testInfo: TestInfo testInfo: TestInfo
folderSetupFn?: (projectDirName: string) => Promise<void> folderSetupFn?: (projectDirName: string) => Promise<void>
cleanProjectDir?: boolean
}) { }) {
// create or otherwise clear the folder // create or otherwise clear the folder
const projectDirName = testInfo.outputPath('electron-test-projects-dir') const projectDirName = testInfo.outputPath('electron-test-projects-dir')
try { try {
if (fsSync.existsSync(projectDirName)) { if (fsSync.existsSync(projectDirName) && cleanProjectDir) {
await fsp.rm(projectDirName, { recursive: true }) await fsp.rm(projectDirName, { recursive: true })
} }
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
await fsp.mkdir(projectDirName) if (cleanProjectDir) {
await fsp.mkdir(projectDirName)
}
const electronApp = await electron.launch({ const electronApp = await electron.launch({
args: ['.', '--no-sandbox'], args: ['.', '--no-sandbox'],
@ -708,17 +712,19 @@ export async function setupElectron({
context.on('console', console.log) context.on('console', console.log)
page.on('console', console.log) page.on('console', console.log)
const tempSettingsFilePath = join(projectDirName, SETTINGS_FILE_NAME) if (cleanProjectDir) {
const settingsOverrides = TOML.stringify({ const tempSettingsFilePath = join(projectDirName, SETTINGS_FILE_NAME)
...TEST_SETTINGS, const settingsOverrides = TOML.stringify({
settings: { ...TEST_SETTINGS,
app: { settings: {
...TEST_SETTINGS.app, app: {
projectDirectory: projectDirName, ...TEST_SETTINGS.app,
projectDirectory: projectDirName,
},
}, },
}, })
}) await fsp.writeFile(tempSettingsFilePath, settingsOverrides)
await fsp.writeFile(tempSettingsFilePath, settingsOverrides) }
await folderSetupFn?.(projectDirName) await folderSetupFn?.(projectDirName)

View File

@ -795,18 +795,18 @@ const extrude001 = extrude(50, sketch001)
await page.waitForTimeout(200) await page.waitForTimeout(200)
await expect( await expect(
await u.getGreatestPixDiff(extrudeWall, hoverColor) await u.getGreatestPixDiff(extrudeWall, hoverColor)
).toBeLessThan(5) ).toBeLessThan(6)
await page.mouse.click(extrudeWall.x, extrudeWall.y) await page.mouse.click(extrudeWall.x, extrudeWall.y)
await expect(page.locator('.cm-activeLine')).toHaveText(`|> ${extrudeText}`) await expect(page.locator('.cm-activeLine')).toHaveText(`|> ${extrudeText}`)
await page.waitForTimeout(200) await page.waitForTimeout(200)
await expect( await expect(
await u.getGreatestPixDiff(extrudeWall, selectColor) await u.getGreatestPixDiff(extrudeWall, selectColor)
).toBeLessThan(5) ).toBeLessThan(6)
await page.waitForTimeout(1000) await page.waitForTimeout(1000)
// check color stays there, i.e. not overridden (this was a bug previously) // check color stays there, i.e. not overridden (this was a bug previously)
await expect( await expect(
await u.getGreatestPixDiff(extrudeWall, selectColor) await u.getGreatestPixDiff(extrudeWall, selectColor)
).toBeLessThan(5) ).toBeLessThan(6)
await page.mouse.move(nothing.x, nothing.y) await page.mouse.move(nothing.x, nothing.y)
await page.waitForTimeout(300) await page.waitForTimeout(300)
@ -817,21 +817,21 @@ const extrude001 = extrude(50, sketch001)
hoverColor = [134, 134, 134] hoverColor = [134, 134, 134]
selectColor = [158, 162, 110] selectColor = [158, 162, 110]
await expect(await u.getGreatestPixDiff(cap, noHoverColor)).toBeLessThan(5) await expect(await u.getGreatestPixDiff(cap, noHoverColor)).toBeLessThan(6)
await page.mouse.move(cap.x, cap.y) await page.mouse.move(cap.x, cap.y)
await expect(page.getByTestId('hover-highlight').first()).toBeVisible() await expect(page.getByTestId('hover-highlight').first()).toBeVisible()
await expect(page.getByTestId('hover-highlight').first()).toContainText( await expect(page.getByTestId('hover-highlight').first()).toContainText(
removeAfterFirstParenthesis(capText) removeAfterFirstParenthesis(capText)
) )
await page.waitForTimeout(200) await page.waitForTimeout(200)
await expect(await u.getGreatestPixDiff(cap, hoverColor)).toBeLessThan(5) await expect(await u.getGreatestPixDiff(cap, hoverColor)).toBeLessThan(6)
await page.mouse.click(cap.x, cap.y) await page.mouse.click(cap.x, cap.y)
await expect(page.locator('.cm-activeLine')).toHaveText(`|> ${capText}`) await expect(page.locator('.cm-activeLine')).toHaveText(`|> ${capText}`)
await page.waitForTimeout(200) await page.waitForTimeout(200)
await expect(await u.getGreatestPixDiff(cap, selectColor)).toBeLessThan(5) await expect(await u.getGreatestPixDiff(cap, selectColor)).toBeLessThan(6)
await page.waitForTimeout(1000) await page.waitForTimeout(1000)
// check color stays there, i.e. not overridden (this was a bug previously) // check color stays there, i.e. not overridden (this was a bug previously)
await expect(await u.getGreatestPixDiff(cap, selectColor)).toBeLessThan(5) await expect(await u.getGreatestPixDiff(cap, selectColor)).toBeLessThan(6)
}) })
test("Various pipe expressions should and shouldn't allow edit and or extrude", async ({ test("Various pipe expressions should and shouldn't allow edit and or extrude", async ({
page, page,