2024-08-13 17:00:56 +10:00
|
|
|
import { _electron as electron, test, expect } from '@playwright/test'
|
2024-08-13 18:34:41 +02:00
|
|
|
import { getUtils, setup, tearDown } from './test-utils'
|
|
|
|
import fs from 'fs/promises'
|
2024-08-13 19:36:39 +02:00
|
|
|
import { join } from 'path'
|
2024-08-12 18:06:08 -04:00
|
|
|
|
2024-08-13 17:00:56 +10:00
|
|
|
test.afterEach(async ({ page }, testInfo) => {
|
|
|
|
await tearDown(page, testInfo)
|
|
|
|
})
|
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
test(
|
|
|
|
'When the project folder is empty, user can create new project and open it.',
|
|
|
|
{ tag: '@electron' },
|
2024-08-13 19:36:39 +02:00
|
|
|
async ({ page: browserPage, context: browserContext }, testInfo) => {
|
2024-08-13 17:02:24 +10:00
|
|
|
// create or otherwise clear the folder ./electron-test-projects-dir
|
2024-08-13 19:36:39 +02:00
|
|
|
const settingsFileName = `./${testInfo.title
|
|
|
|
.replace(/\s/gi, '-')
|
2024-08-13 20:56:18 +02:00
|
|
|
.replace(/![\w-]/gi, '')}`
|
2024-08-13 19:36:39 +02:00
|
|
|
const projectDirName = settingsFileName + '-dir'
|
2024-08-13 17:02:24 +10:00
|
|
|
try {
|
2024-08-13 19:36:39 +02:00
|
|
|
await fs.rm(projectDirName, { recursive: true })
|
2024-08-13 17:02:24 +10:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
}
|
|
|
|
|
2024-08-13 19:36:39 +02:00
|
|
|
await fs.mkdir(projectDirName)
|
2024-08-13 17:02:24 +10:00
|
|
|
|
|
|
|
// get full path for ./electron-test-projects-dir
|
2024-08-13 19:36:39 +02:00
|
|
|
const fullProjectPath = await fs.realpath(projectDirName)
|
2024-08-13 17:02:24 +10:00
|
|
|
|
|
|
|
const electronApp = await electron.launch({
|
|
|
|
args: ['.'],
|
|
|
|
})
|
2024-08-13 19:36:39 +02:00
|
|
|
const context = electronApp.context()
|
2024-08-13 17:02:24 +10:00
|
|
|
const page = await electronApp.firstWindow()
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 20:56:18 +02:00
|
|
|
await page.goto('http://localhost:3000/')
|
2024-08-13 19:36:39 +02:00
|
|
|
const electronTempDirectory = await page.evaluate(async () => {
|
2024-08-13 20:56:18 +02:00
|
|
|
return await window.electron.getPath('temp')
|
2024-08-13 19:36:39 +02:00
|
|
|
})
|
|
|
|
const tempSettingsFilePath = join(electronTempDirectory, settingsFileName)
|
2024-08-13 20:56:18 +02:00
|
|
|
const settingsOverrides = `[settings.project]
|
|
|
|
directory = "/Users/frankjohnson/Documents/zoo-modeling-app-projects-2"
|
|
|
|
`
|
2024-08-13 19:36:39 +02:00
|
|
|
|
|
|
|
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)
|
2024-08-13 17:02:24 +10:00
|
|
|
// Set local storage directly using evaluate
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
const u = await getUtils(page)
|
|
|
|
await page.setViewportSize({ width: 1200, height: 500 })
|
2024-08-13 19:36:39 +02:00
|
|
|
await page.goto('http://localhost:3000/')
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
page.on('console', console.log)
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
// expect to see text "No Projects found"
|
|
|
|
await expect(page.getByText('No Projects found')).toBeVisible()
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
await page.getByRole('button', { name: 'New project' }).click()
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
await expect(page.getByText('Successfully created')).toBeVisible()
|
|
|
|
await expect(page.getByText('Successfully created')).not.toBeVisible()
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
await expect(page.getByText('project-000')).toBeVisible()
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
await page.getByText('project-000').click()
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
await expect(page.getByTestId('loading')).toBeAttached()
|
|
|
|
await expect(page.getByTestId('loading')).not.toBeAttached({
|
|
|
|
timeout: 20_000,
|
|
|
|
})
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: 'Start Sketch' })
|
|
|
|
).toBeEnabled({
|
|
|
|
timeout: 20_000,
|
|
|
|
})
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
await page.locator('.cm-content')
|
|
|
|
.fill(`const sketch001 = startSketchOn('XZ')
|
2024-08-13 17:00:56 +10:00
|
|
|
|> startProfileAt([-87.4, 282.92], %)
|
|
|
|
|> line([324.07, 27.199], %, $seg01)
|
|
|
|
|> line([118.328, -291.754], %)
|
|
|
|
|> line([-180.04, -202.08], %)
|
|
|
|
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
|
|
|
|> close(%)
|
|
|
|
const extrude001 = extrude(200, sketch001)`)
|
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
const pointOnModel = { x: 660, y: 250 }
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
// check the model loaded by checking it's grey
|
|
|
|
await expect
|
|
|
|
.poll(() => u.getGreatestPixDiff(pointOnModel, [132, 132, 132]), {
|
|
|
|
timeout: 10_000,
|
|
|
|
})
|
|
|
|
.toBeLessThan(10)
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
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)
|
2024-08-13 17:00:56 +10:00
|
|
|
|
2024-08-13 17:02:24 +10:00
|
|
|
await electronApp.close()
|
|
|
|
}
|
|
|
|
)
|