Fix tests that relied on one-click, no-navigation project creation

This commit is contained in:
Frank Noirot
2024-10-08 09:15:18 -04:00
parent 3d2e48732c
commit f0136a5939
4 changed files with 55 additions and 101 deletions

View File

@ -3,6 +3,7 @@ import { test, expect } from './fixtures/fixtureSetup'
import * as fsp from 'fs/promises' import * as fsp from 'fs/promises'
import * as fs from 'fs' import * as fs from 'fs'
import { import {
createProject,
executorInputPath, executorInputPath,
getUtils, getUtils,
setup, setup,
@ -114,20 +115,15 @@ test.describe('when using the file tree to', () => {
async ({ browser: _, tronApp }, testInfo) => { async ({ browser: _, tronApp }, testInfo) => {
await tronApp.initialise() await tronApp.initialise()
const { const { panesOpen, pasteCodeInEditor, renameFile, editorTextMatches } =
panesOpen, await getUtils(tronApp.page, test)
createAndSelectProject,
pasteCodeInEditor,
renameFile,
editorTextMatches,
} = await getUtils(tronApp.page, test)
await tronApp.page.setViewportSize({ width: 1200, height: 500 }) await tronApp.page.setViewportSize({ width: 1200, height: 500 })
tronApp.page.on('console', console.log) tronApp.page.on('console', console.log)
await panesOpen(['files', 'code']) await panesOpen(['files', 'code'])
await createAndSelectProject('project-000') await createProject({ name: 'project-000', page: tronApp.page })
// File the main.kcl with contents // File the main.kcl with contents
const kclCube = await fsp.readFile( const kclCube = await fsp.readFile(
@ -164,15 +160,14 @@ test.describe('when using the file tree to', () => {
async ({ browser: _, tronApp }, testInfo) => { async ({ browser: _, tronApp }, testInfo) => {
await tronApp.initialise() await tronApp.initialise()
const { panesOpen, createAndSelectProject, createNewFile } = const { panesOpen, createNewFile } = await getUtils(tronApp.page, test)
await getUtils(tronApp.page, test)
await tronApp.page.setViewportSize({ width: 1200, height: 500 }) await tronApp.page.setViewportSize({ width: 1200, height: 500 })
tronApp.page.on('console', console.log) tronApp.page.on('console', console.log)
await panesOpen(['files']) await panesOpen(['files'])
await createAndSelectProject('project-000') await createProject({ name: 'project-000', page: tronApp.page })
await createNewFile('') await createNewFile('')
await createNewFile('') await createNewFile('')
@ -201,7 +196,6 @@ test.describe('when using the file tree to', () => {
const { const {
openKclCodePanel, openKclCodePanel,
openFilePanel, openFilePanel,
createAndSelectProject,
pasteCodeInEditor, pasteCodeInEditor,
createNewFileAndSelect, createNewFileAndSelect,
renameFile, renameFile,
@ -212,7 +206,7 @@ test.describe('when using the file tree to', () => {
await tronApp.page.setViewportSize({ width: 1200, height: 500 }) await tronApp.page.setViewportSize({ width: 1200, height: 500 })
tronApp.page.on('console', console.log) tronApp.page.on('console', console.log)
await createAndSelectProject('project-000') await createProject({ name: 'project-000', page: tronApp.page })
await openKclCodePanel() await openKclCodePanel()
await openFilePanel() await openFilePanel()
// File the main.kcl with contents // File the main.kcl with contents
@ -255,20 +249,15 @@ test.describe('when using the file tree to', () => {
async ({ browser: _, tronApp }, testInfo) => { async ({ browser: _, tronApp }, testInfo) => {
await tronApp.initialise() await tronApp.initialise()
const { const { panesOpen, pasteCodeInEditor, deleteFile, editorTextMatches } =
panesOpen, await getUtils(tronApp.page, _test)
createAndSelectProject,
pasteCodeInEditor,
deleteFile,
editorTextMatches,
} = await getUtils(tronApp.page, _test)
await tronApp.page.setViewportSize({ width: 1200, height: 500 }) await tronApp.page.setViewportSize({ width: 1200, height: 500 })
tronApp.page.on('console', console.log) tronApp.page.on('console', console.log)
await panesOpen(['files', 'code']) await panesOpen(['files', 'code'])
await createAndSelectProject('project-000') await createProject({ name: 'project-000', page: tronApp.page })
// File the main.kcl with contents // File the main.kcl with contents
const kclCube = await fsp.readFile( const kclCube = await fsp.readFile(
'src/wasm-lib/tests/executor/inputs/cube.kcl', 'src/wasm-lib/tests/executor/inputs/cube.kcl',
@ -298,7 +287,6 @@ test.describe('when using the file tree to', () => {
const { const {
panesOpen, panesOpen,
createAndSelectProject,
pasteCodeInEditor, pasteCodeInEditor,
createNewFile, createNewFile,
openDebugPanel, openDebugPanel,
@ -310,7 +298,7 @@ test.describe('when using the file tree to', () => {
tronApp.page.on('console', console.log) tronApp.page.on('console', console.log)
await panesOpen(['files', 'code']) await panesOpen(['files', 'code'])
await createAndSelectProject('project-000') await createProject({ name: 'project-000', page: tronApp.page })
// Create a small file // Create a small file
const kclCube = await fsp.readFile( const kclCube = await fsp.readFile(
@ -714,7 +702,7 @@ _test.describe('Renaming in the file tree', () => {
}) })
await _test.step('Rename the folder', async () => { await _test.step('Rename the folder', async () => {
await page.waitForTimeout(60000) await page.waitForTimeout(1000)
await folderToRename.click({ button: 'right' }) await folderToRename.click({ button: 'right' })
await _expect(renameMenuItem).toBeVisible() await _expect(renameMenuItem).toBeVisible()
await renameMenuItem.click() await renameMenuItem.click()

View File

@ -7,7 +7,7 @@ import {
Paths, Paths,
setupElectron, setupElectron,
tearDown, tearDown,
createProjectAndRenameIt, createProject,
} from './test-utils' } from './test-utils'
import fsp from 'fs/promises' import fsp from 'fs/promises'
import fs from 'fs' import fs from 'fs'
@ -863,23 +863,15 @@ test(
page.on('console', console.log) page.on('console', console.log)
const createProjectAndRenameItTest = async ({
name,
page,
}: {
name: string
page: Page
}) => {
await test.step(`Create and rename project ${name}`, async () => {
await createProjectAndRenameIt({ name, page })
})
}
// we need to create the folders so that the order is correct // we need to create the folders so that the order is correct
// creating them ahead of time with fs tools means they all have the same timestamp // creating them ahead of time with fs tools means they all have the same timestamp
await createProjectAndRenameItTest({ name: 'router-template-slate', page }) await createProject({
await createProjectAndRenameItTest({ name: 'bracket', page }) name: 'router-template-slate',
await createProjectAndRenameItTest({ name: 'lego', page }) page,
returnHome: true,
})
await createProject({ name: 'bracket', page, returnHome: true })
await createProject({ name: 'lego', page, returnHome: true })
await test.step('delete the middle project, i.e. the bracket project', async () => { await test.step('delete the middle project, i.e. the bracket project', async () => {
const project = page.getByText('bracket') const project = page.getByText('bracket')
@ -991,23 +983,15 @@ test(
page.on('console', console.log) page.on('console', console.log)
const createProjectAndRenameItTest = async ({
name,
page,
}: {
name: string
page: Page
}) => {
await test.step(`Create and rename project ${name}`, async () => {
await createProjectAndRenameIt({ name, page })
})
}
// we need to create the folders so that the order is correct // we need to create the folders so that the order is correct
// creating them ahead of time with fs tools means they all have the same timestamp // creating them ahead of time with fs tools means they all have the same timestamp
await createProjectAndRenameItTest({ name: 'router-template-slate', page }) await createProject({
await createProjectAndRenameItTest({ name: 'bracket', page }) name: 'router-template-slate',
await createProjectAndRenameItTest({ name: 'lego', page }) page,
returnHome: true,
})
await createProject({ name: 'bracket', page, returnHome: true })
await createProject({ name: 'lego', page, returnHome: true })
await test.step('should be shorted by modified initially', async () => { await test.step('should be shorted by modified initially', async () => {
const lastModifiedButton = page.getByRole('button', { const lastModifiedButton = page.getByRole('button', {
@ -1158,16 +1142,10 @@ extrude001 = extrude(200, sketch001)`)
page.getByRole('button', { name: 'New project' }) page.getByRole('button', { name: 'New project' })
).toBeVisible() ).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++) { for (let i = 1; i <= 10; i++) {
await createProject(i) const name = `project-${i.toString().padStart(3, '0')}`
await createProject({ name, page, returnHome: true })
await expect(page.getByText(name)).toBeVisible()
} }
await electronApp.close() await electronApp.close()
} }
@ -1672,7 +1650,7 @@ test(
page.on('console', console.log) page.on('console', console.log)
await test.step('Should create and name a project called wrist brace', async () => { await test.step('Should create and name a project called wrist brace', async () => {
await createProjectAndRenameIt({ name: 'wrist brace', page }) await createProject({ name: 'wrist brace', page, returnHome: true })
}) })
await test.step('Should go through onboarding', async () => { await test.step('Should go through onboarding', async () => {

View File

@ -459,17 +459,6 @@ export async function getUtils(page: Page, test_?: typeof test) {
return text.replace(/\s+/g, '') return text.replace(/\s+/g, '')
}, },
createAndSelectProject: async (hasText: string) => {
return test_?.step(
`Create and select project with text "${hasText}"`,
async () => {
await page.getByTestId('home-new-file').click()
const projectLinksPost = page.getByTestId('project-link')
await projectLinksPost.filter({ hasText }).click()
}
)
},
editorTextMatches: async (code: string) => { editorTextMatches: async (code: string) => {
const editor = page.locator(editorSelector) const editor = page.locator(editorSelector)
return expect(editor).toHaveText(code, { useInnerText: true }) return expect(editor).toHaveText(code, { useInnerText: true })
@ -954,30 +943,25 @@ export async function isOutOfViewInScrollContainer(
return isOutOfView return isOutOfView
} }
export async function createProjectAndRenameIt({ export async function createProject({
name, name,
page, page,
returnHome = false,
}: { }: {
name: string name: string
page: Page page: Page
returnHome?: boolean
}) { }) {
await page.getByRole('button', { name: 'New project' }).click() await test.step(`Create project and navigate to it`, async () => {
await expect(page.getByText('Successfully created')).toBeVisible() await page.getByRole('button', { name: 'New project' }).click()
await expect(page.getByText('Successfully created')).not.toBeVisible() await page.getByRole('textbox', { name: 'Name' }).fill(name)
await page.getByRole('button', { name: 'Continue' }).click()
await expect(page.getByText(`project-000`)).toBeVisible() if (returnHome) {
await page.getByText(`project-000`).hover() await page.waitForURL('**/file/**', { waitUntil: 'domcontentloaded' })
await page.getByText(`project-000`).focus() await page.getByTestId('app-logo').click()
}
await page.getByLabel('sketch').first().click() })
await page.waitForTimeout(100)
// type the name passed in
await page.keyboard.press('Backspace')
await page.keyboard.type(name)
await page.getByLabel('checkmark').last().click()
} }
export function executorInputPath(fileName: string): string { export function executorInputPath(fileName: string): string {

View File

@ -1,5 +1,11 @@
import { test, expect, Page } from '@playwright/test' import { test, expect, Page } from '@playwright/test'
import { getUtils, setup, tearDown, setupElectron } from './test-utils' import {
getUtils,
setup,
tearDown,
setupElectron,
createProject,
} from './test-utils'
import { join } from 'path' import { join } from 'path'
import fs from 'fs' import fs from 'fs'
@ -700,12 +706,10 @@ test(
const fileExists = () => const fileExists = () =>
fs.existsSync(join(dir, projectName, textToCadFileName)) fs.existsSync(join(dir, projectName, textToCadFileName))
const { const { openFilePanel, openKclCodePanel, waitForPageLoad } = await getUtils(
createAndSelectProject, page,
openFilePanel, test
openKclCodePanel, )
waitForPageLoad,
} = await getUtils(page, test)
await page.setViewportSize({ width: 1200, height: 500 }) await page.setViewportSize({ width: 1200, height: 500 })
@ -719,7 +723,7 @@ test(
) )
// Create and navigate to the project // Create and navigate to the project
await createAndSelectProject('project-000') await createProject({ name: 'project-000', page })
// Wait for Start Sketch otherwise you will not have access Text-to-CAD command // Wait for Start Sketch otherwise you will not have access Text-to-CAD command
await waitForPageLoad() await waitForPageLoad()