* Rename useCalc * Move CommandBar so it has access to settings and kcl * Create codemirror variable mention extension * Make project path a dep of TextEditor useMemo * Add incomplete KCL input for CommandBar to replace current number arg type * Add previous variables autocompletion to kcl input * Fix missed typos from merge * Working AST mods, not working variable additions * Add ability to create a new variable * Add icon and tooltip to command arg tag if a variable is added * Polish variable naming logic, preserve when going back * Allow stepping back from KCL input * Don't prevent keydown of enter, it's used by autocomplete * Round the variable value in cmd bar header * Add Playwright test * Formatting, polish TS types * More type wrangling * Needed to fmt after above type wrangling * Update snapshot tests to account for new variable name autogeneration * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Merge branch 'main' into cmd-bar-make-variable * Update all test instances of var name with number index after merge with main * Partial revert of "Polish variable naming logic, preserve when going back" This reverts commitdddcb13c36
. * Revert "Update all test instances of var name with number index after merge with main" This reverts commit8c4b63b523
. * Revert "Update snapshot tests to account for new variable name autogeneration" This reverts commit11bfce3832
. * Retry a refactoring of findUniqueName * minor feedback from @jgomez720 - better highlighting of kcl input - consistent hotkeys - disallow invalid var names * Polish stepping back state logic * Fix tests now that keyboard shortcut changed * Remove unused imports * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Fix tests * Trigger CI * Update src/components/ProjectSidebarMenu.test.tsx * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * re-trigger CI --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
99 lines
2.6 KiB
TypeScript
99 lines
2.6 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react'
|
|
import { BrowserRouter } from 'react-router-dom'
|
|
import ProjectSidebarMenu from './ProjectSidebarMenu'
|
|
import { type ProjectWithEntryPointMetadata } from 'lib/types'
|
|
import { GlobalStateProvider } from './GlobalStateProvider'
|
|
import { APP_NAME } from 'lib/constants'
|
|
import { vi } from 'vitest'
|
|
import { ExportButtonProps } from './ExportButton'
|
|
|
|
const now = new Date()
|
|
const projectWellFormed = {
|
|
name: 'Simple Box',
|
|
path: '/some/path/Simple Box',
|
|
children: [
|
|
{
|
|
name: 'main.kcl',
|
|
path: '/some/path/Simple Box/main.kcl',
|
|
},
|
|
],
|
|
entrypointMetadata: {
|
|
accessedAt: now,
|
|
blksize: 32,
|
|
blocks: 32,
|
|
createdAt: now,
|
|
dev: 1,
|
|
gid: 1,
|
|
ino: 1,
|
|
isDir: false,
|
|
isFile: true,
|
|
isSymlink: false,
|
|
mode: 1,
|
|
modifiedAt: now,
|
|
nlink: 1,
|
|
permissions: { readonly: false, mode: 1 },
|
|
rdev: 1,
|
|
size: 32,
|
|
uid: 1,
|
|
},
|
|
} satisfies ProjectWithEntryPointMetadata
|
|
|
|
const mockExportButton = vi.fn()
|
|
vi.mock('/src/components/ExportButton', () => ({
|
|
// engineCommandManager method call in ExportButton causes vitest to hang
|
|
ExportButton: (props: ExportButtonProps) => {
|
|
mockExportButton(props)
|
|
return <button>Fake export button</button>
|
|
},
|
|
}))
|
|
|
|
describe('ProjectSidebarMenu tests', () => {
|
|
test('Renders the project name', () => {
|
|
render(
|
|
<BrowserRouter>
|
|
<GlobalStateProvider>
|
|
<ProjectSidebarMenu project={projectWellFormed} />
|
|
</GlobalStateProvider>
|
|
</BrowserRouter>
|
|
)
|
|
|
|
fireEvent.click(screen.getByTestId('project-sidebar-toggle'))
|
|
|
|
expect(screen.getByTestId('projectName')).toHaveTextContent(
|
|
projectWellFormed.name
|
|
)
|
|
expect(screen.getByTestId('createdAt')).toHaveTextContent(
|
|
`Created ${now.toLocaleDateString()}`
|
|
)
|
|
})
|
|
|
|
test('Renders app name if given no project', () => {
|
|
render(
|
|
<BrowserRouter>
|
|
<GlobalStateProvider>
|
|
<ProjectSidebarMenu />
|
|
</GlobalStateProvider>
|
|
</BrowserRouter>
|
|
)
|
|
|
|
fireEvent.click(screen.getByTestId('project-sidebar-toggle'))
|
|
|
|
expect(screen.getByTestId('projectName')).toHaveTextContent(APP_NAME)
|
|
})
|
|
|
|
test('Renders as a link if set to do so', () => {
|
|
render(
|
|
<BrowserRouter>
|
|
<GlobalStateProvider>
|
|
<ProjectSidebarMenu project={projectWellFormed} renderAsLink={true} />
|
|
</GlobalStateProvider>
|
|
</BrowserRouter>
|
|
)
|
|
|
|
expect(screen.getByTestId('project-sidebar-link')).toBeInTheDocument()
|
|
expect(screen.getByTestId('project-sidebar-link-name')).toHaveTextContent(
|
|
projectWellFormed.name
|
|
)
|
|
})
|
|
})
|