Merge Frank test setup work (#3418)
* Working window.electron.getPath * Loading project-specific settings in electron tests * Simplify test until we can get snapshots/traces working in electron tests * test tweaks --------- Co-authored-by: Frank Noirot <frank@kittycad.io>
This commit is contained in:
@ -1,9 +1,5 @@
|
||||
import { _electron as electron, test, expect } from '@playwright/test'
|
||||
import { getUtils, setup, tearDown } from './test-utils'
|
||||
import fs from 'fs/promises'
|
||||
import { secrets } from './secrets'
|
||||
import { join } from 'path'
|
||||
import { tomlStringify } from 'lang/wasm'
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { getUtils, setupElectron, tearDown } from './test-utils'
|
||||
|
||||
test.afterEach(async ({ page }, testInfo) => {
|
||||
await tearDown(page, testInfo)
|
||||
@ -12,60 +8,15 @@ test.afterEach(async ({ page }, testInfo) => {
|
||||
test(
|
||||
'When the project folder is empty, user can create new project and open it.',
|
||||
{ tag: '@electron' },
|
||||
async ({ page: browserPage, context: browserContext }, testInfo) => {
|
||||
// create or otherwise clear the folder ./electron-test-projects-dir
|
||||
const settingsFileName = `./${testInfo.title
|
||||
.replace(/\s/gi, '-')
|
||||
.replace(/\W/gi, '')}`
|
||||
const projectDirName = settingsFileName + '-dir'
|
||||
try {
|
||||
await fs.rm(projectDirName, { recursive: true })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
await fs.mkdir(projectDirName)
|
||||
|
||||
// get full path for ./electron-test-projects-dir
|
||||
const fullProjectPath = await fs.realpath(projectDirName)
|
||||
|
||||
const electronApp = await electron.launch({
|
||||
args: ['.'],
|
||||
})
|
||||
const context = electronApp.context()
|
||||
const page = await electronApp.firstWindow()
|
||||
|
||||
const electronTempDirectory = await page.evaluate(async () => {
|
||||
return await window.electron.getPath(
|
||||
'temp'
|
||||
)
|
||||
})
|
||||
const tempSettingsFilePath = join(electronTempDirectory, settingsFileName)
|
||||
const settingsOverrides = tomlStringify({
|
||||
app: {
|
||||
projectDirectory: fullProjectPath,
|
||||
},
|
||||
})
|
||||
|
||||
if (settingsOverrides instanceof Error) {
|
||||
throw settingsOverrides
|
||||
}
|
||||
await fs.writeFile(tempSettingsFilePath + '.toml', settingsOverrides)
|
||||
|
||||
console.log('from within test setup', {
|
||||
settingsFileName,
|
||||
fullPath: fullProjectPath,
|
||||
electronApp,
|
||||
page,
|
||||
settingsFilePath: tempSettingsFilePath + '.toml',
|
||||
})
|
||||
|
||||
await setup(context, page, fullProjectPath)
|
||||
// Set local storage directly using evaluate
|
||||
|
||||
async ({ browserName }, testInfo) => {
|
||||
test.skip(
|
||||
browserName === 'webkit',
|
||||
'Skip on Safari because `window.tearDown` does not work'
|
||||
)
|
||||
const { electronApp, page } = await setupElectron({ testInfo })
|
||||
const u = await getUtils(page)
|
||||
await page.setViewportSize({ width: 1200, height: 500 })
|
||||
await page.goto('http://localhost:3000/')
|
||||
await page.setViewportSize({ width: 1200, height: 500 })
|
||||
|
||||
page.on('console', console.log)
|
||||
|
||||
@ -111,12 +62,33 @@ const extrude001 = extrude(200, sketch001)`)
|
||||
})
|
||||
.toBeLessThan(10)
|
||||
|
||||
await page.mouse.click(pointOnModel.x, pointOnModel.y)
|
||||
// check user can interact with model by checking it turns yellow
|
||||
await expect
|
||||
.poll(() => u.getGreatestPixDiff(pointOnModel, [176, 180, 132]))
|
||||
.toBeLessThan(10)
|
||||
await expect(async () => {
|
||||
await page.mouse.move(0, 0, { steps: 5 })
|
||||
await page.mouse.move(pointOnModel.x, pointOnModel.y, { steps: 5 })
|
||||
await page.mouse.click(pointOnModel.x, pointOnModel.y)
|
||||
// check user can interact with model by checking it turns yellow
|
||||
await expect
|
||||
.poll(() => u.getGreatestPixDiff(pointOnModel, [176, 180, 132]))
|
||||
.toBeLessThan(10)
|
||||
}).toPass({ timeout: 40_000, intervals: [1_000] })
|
||||
|
||||
await page.getByTestId('app-logo').click()
|
||||
|
||||
await expect(
|
||||
page.getByRole('button', { name: 'New project' })
|
||||
).toBeVisible()
|
||||
|
||||
const createProject = async (projectNum: number) => {
|
||||
await page.getByRole('button', { name: 'New project' }).click()
|
||||
await expect(page.getByText('Successfully created')).toBeVisible()
|
||||
await expect(page.getByText('Successfully created')).not.toBeVisible()
|
||||
|
||||
const projectNumStr = projectNum.toString().padStart(3, '0')
|
||||
await expect(page.getByText(`project-${projectNumStr}`)).toBeVisible()
|
||||
}
|
||||
for (let i = 1; i <= 10; i++) {
|
||||
await createProject(i)
|
||||
}
|
||||
await electronApp.close()
|
||||
}
|
||||
)
|
||||
|
Reference in New Issue
Block a user