This commit is contained in:
Kurt Hutten Irev-Dev
2024-08-13 17:02:24 +10:00
parent 128c9cb3f8
commit 713a302479

View File

@ -1,8 +1,5 @@
import { _electron as electron, test, expect } from '@playwright/test' import { _electron as electron, test, expect } from '@playwright/test'
import { import { getUtils, tearDown } from './test-utils'
getUtils,
tearDown,
} from './test-utils'
import fs from 'node:fs' import fs from 'node:fs'
import { secrets } from './secrets' import { secrets } from './secrets'
@ -10,71 +7,79 @@ test.afterEach(async ({ page }, testInfo) => {
await tearDown(page, testInfo) await tearDown(page, testInfo)
}) })
test('When the project folder is empty, user can create new project and open it.', { tag: '@electron' }, async () => { test(
// create or otherwise clear the folder ./electron-test-projects-dir 'When the project folder is empty, user can create new project and open it.',
const fileName = './electron-test-projects-dir' { tag: '@electron' },
try { async () => {
fs.rmdirSync(fileName, { recursive: true }) // create or otherwise clear the folder ./electron-test-projects-dir
} catch (e) { const fileName = './electron-test-projects-dir'
console.error(e) try {
} fs.rmdirSync(fileName, { recursive: true })
} catch (e) {
console.error(e)
}
fs.mkdirSync(fileName) fs.mkdirSync(fileName)
// get full path for ./electron-test-projects-dir // get full path for ./electron-test-projects-dir
const fullPath = fs.realpathSync(fileName) const fullPath = fs.realpathSync(fileName)
const electronApp = await electron.launch({ const electronApp = await electron.launch({
args: ['.'], args: ['.'],
}) })
await electronApp.evaluate(async ({ app }) => { await electronApp.evaluate(async ({ app }) => {
return app.getAppPath() return app.getAppPath()
}) })
const page = await electronApp.firstWindow() const page = await electronApp.firstWindow()
// Set local storage directly using evaluate // Set local storage directly using evaluate
await page.evaluate( await page.evaluate(
(token) => localStorage.setItem('TOKEN_PERSIST_KEY', token), (token) => localStorage.setItem('TOKEN_PERSIST_KEY', token),
secrets.token secrets.token
) )
await page.evaluate((fullPath) => await page.evaluate(
localStorage.setItem( (fullPath) =>
'APP_SETTINGS_OVERRIDE', localStorage.setItem(
JSON.stringify({ 'APP_SETTINGS_OVERRIDE',
projectDirectory: fullPath, JSON.stringify({
}) projectDirectory: fullPath,
), fullPath })
) ),
fullPath
)
const u = await getUtils(page) const u = await getUtils(page)
await page.setViewportSize({ width: 1200, height: 500 }) await page.setViewportSize({ width: 1200, height: 500 })
page.on('console', console.log) page.on('console', console.log)
// expect to see text "No Projects found" // expect to see text "No Projects found"
await expect(page.getByText('No Projects found')).toBeVisible() await expect(page.getByText('No Projects found')).toBeVisible()
await page.getByRole('button', { name: 'New project' }).click() await page.getByRole('button', { name: 'New project' }).click()
await expect(page.getByText('Successfully created')).toBeVisible() await expect(page.getByText('Successfully created')).toBeVisible()
await expect(page.getByText('Successfully created')).not.toBeVisible() await expect(page.getByText('Successfully created')).not.toBeVisible()
await expect(page.getByText('project-000')).toBeVisible() await expect(page.getByText('project-000')).toBeVisible()
await page.getByText('project-000').click() await page.getByText('project-000').click()
await expect(page.getByTestId('loading')).toBeAttached() await expect(page.getByTestId('loading')).toBeAttached()
await expect(page.getByTestId('loading')).not.toBeAttached({ await expect(page.getByTestId('loading')).not.toBeAttached({
timeout: 20_000, timeout: 20_000,
}) })
await expect(page.getByRole('button', { name: 'Start Sketch' })).toBeEnabled({ await expect(
timeout: 20_000, page.getByRole('button', { name: 'Start Sketch' })
}) ).toBeEnabled({
timeout: 20_000,
})
await page.locator('.cm-content').fill(`const sketch001 = startSketchOn('XZ') await page.locator('.cm-content')
.fill(`const sketch001 = startSketchOn('XZ')
|> startProfileAt([-87.4, 282.92], %) |> startProfileAt([-87.4, 282.92], %)
|> line([324.07, 27.199], %, $seg01) |> line([324.07, 27.199], %, $seg01)
|> line([118.328, -291.754], %) |> line([118.328, -291.754], %)
@ -83,20 +88,21 @@ test('When the project folder is empty, user can create new project and open it.
|> close(%) |> close(%)
const extrude001 = extrude(200, sketch001)`) const extrude001 = extrude(200, sketch001)`)
const pointOnModel = { x: 660, y: 250 } const pointOnModel = { x: 660, y: 250 }
// check the model loaded by checking it's grey // check the model loaded by checking it's grey
await expect await expect
.poll(() => u.getGreatestPixDiff(pointOnModel, [132, 132, 132]), { .poll(() => u.getGreatestPixDiff(pointOnModel, [132, 132, 132]), {
timeout: 10_000, timeout: 10_000,
}) })
.toBeLessThan(10) .toBeLessThan(10)
await page.mouse.click(pointOnModel.x, pointOnModel.y) await page.mouse.click(pointOnModel.x, pointOnModel.y)
// check user can interact with model by checking it turns yellow // check user can interact with model by checking it turns yellow
await expect await expect
.poll(() => u.getGreatestPixDiff(pointOnModel, [176, 180, 132])) .poll(() => u.getGreatestPixDiff(pointOnModel, [176, 180, 132]))
.toBeLessThan(10) .toBeLessThan(10)
await electronApp.close() await electronApp.close()
}) }
)