2023-08-01 13:23:17 -04:00
|
|
|
import { fireEvent, render, screen } from '@testing-library/react'
|
|
|
|
import UserSidebarMenu from './UserSidebarMenu'
|
2023-10-04 18:00:55 -04:00
|
|
|
import {
|
|
|
|
Route,
|
|
|
|
RouterProvider,
|
|
|
|
createMemoryRouter,
|
|
|
|
createRoutesFromElements,
|
|
|
|
} from 'react-router-dom'
|
2023-08-22 05:34:20 +10:00
|
|
|
import { Models } from '@kittycad/lib'
|
2024-02-16 09:09:58 -05:00
|
|
|
import { GlobalStateProvider } from './GlobalStateProvider'
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
import CommandBarProvider from './CommandBar/CommandBar'
|
2023-08-22 05:34:20 +10:00
|
|
|
|
|
|
|
type User = Models['User_type']
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
describe('UserSidebarMenu tests', () => {
|
|
|
|
test("Renders user's name and email if available", () => {
|
|
|
|
const userWellFormed: User = {
|
|
|
|
id: '8675309',
|
|
|
|
name: 'Test User',
|
|
|
|
email: 'kittycad.sidebar.test@example.com',
|
|
|
|
image: 'https://placekitten.com/200/200',
|
|
|
|
created_at: 'yesteryear',
|
|
|
|
updated_at: 'today',
|
2023-08-22 05:34:20 +10:00
|
|
|
company: 'Test Company',
|
|
|
|
discord: 'Test User#1234',
|
|
|
|
github: 'testuser',
|
|
|
|
phone: '555-555-5555',
|
|
|
|
first_name: 'Test',
|
|
|
|
last_name: 'User',
|
2024-02-29 11:57:47 +11:00
|
|
|
can_train_on_data: false,
|
|
|
|
is_service_account: false,
|
2023-08-15 21:56:24 -04:00
|
|
|
}
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
render(
|
2023-08-22 05:34:20 +10:00
|
|
|
<TestWrap>
|
2023-08-15 21:56:24 -04:00
|
|
|
<UserSidebarMenu user={userWellFormed} />
|
2023-08-22 05:34:20 +10:00
|
|
|
</TestWrap>
|
2023-08-15 21:56:24 -04:00
|
|
|
)
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
fireEvent.click(screen.getByTestId('user-sidebar-toggle'))
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
expect(screen.getByTestId('username')).toHaveTextContent(
|
|
|
|
userWellFormed.name || ''
|
|
|
|
)
|
|
|
|
expect(screen.getByTestId('email')).toHaveTextContent(userWellFormed.email)
|
|
|
|
})
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
test("Renders just the user's email if no name is available", () => {
|
|
|
|
const userNoName: User = {
|
|
|
|
id: '8675309',
|
|
|
|
email: 'kittycad.sidebar.test@example.com',
|
|
|
|
image: 'https://placekitten.com/200/200',
|
|
|
|
created_at: 'yesteryear',
|
|
|
|
updated_at: 'today',
|
2023-08-22 05:34:20 +10:00
|
|
|
company: 'Test Company',
|
|
|
|
discord: 'Test User#1234',
|
|
|
|
github: 'testuser',
|
|
|
|
phone: '555-555-5555',
|
|
|
|
first_name: '',
|
|
|
|
last_name: '',
|
|
|
|
name: '',
|
2024-02-29 11:57:47 +11:00
|
|
|
can_train_on_data: false,
|
|
|
|
is_service_account: false,
|
2023-08-15 21:56:24 -04:00
|
|
|
}
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
render(
|
2023-08-22 05:34:20 +10:00
|
|
|
<TestWrap>
|
2023-08-15 21:56:24 -04:00
|
|
|
<UserSidebarMenu user={userNoName} />
|
2023-08-22 05:34:20 +10:00
|
|
|
</TestWrap>
|
2023-08-15 21:56:24 -04:00
|
|
|
)
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
fireEvent.click(screen.getByTestId('user-sidebar-toggle'))
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
expect(screen.getByTestId('username')).toHaveTextContent(userNoName.email)
|
|
|
|
})
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
test('Renders a menu button if no user avatar is available', () => {
|
|
|
|
const userNoAvatar: User = {
|
|
|
|
id: '8675309',
|
|
|
|
name: 'Test User',
|
|
|
|
email: 'kittycad.sidebar.test@example.com',
|
|
|
|
created_at: 'yesteryear',
|
|
|
|
updated_at: 'today',
|
2023-08-22 05:34:20 +10:00
|
|
|
company: 'Test Company',
|
|
|
|
discord: 'Test User#1234',
|
|
|
|
github: 'testuser',
|
|
|
|
phone: '555-555-5555',
|
|
|
|
first_name: 'Test',
|
|
|
|
last_name: 'User',
|
|
|
|
image: '',
|
2024-02-29 11:57:47 +11:00
|
|
|
can_train_on_data: false,
|
|
|
|
is_service_account: false,
|
2023-08-15 21:56:24 -04:00
|
|
|
}
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
render(
|
2023-08-22 05:34:20 +10:00
|
|
|
<TestWrap>
|
2023-08-15 21:56:24 -04:00
|
|
|
<UserSidebarMenu user={userNoAvatar} />
|
2023-08-22 05:34:20 +10:00
|
|
|
</TestWrap>
|
2023-08-15 21:56:24 -04:00
|
|
|
)
|
2023-08-01 13:23:17 -04:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
expect(screen.getByTestId('user-sidebar-toggle')).toHaveTextContent('Menu')
|
|
|
|
})
|
2023-08-01 13:23:17 -04:00
|
|
|
})
|
2023-08-22 05:34:20 +10:00
|
|
|
|
|
|
|
function TestWrap({ children }: { children: React.ReactNode }) {
|
|
|
|
// wrap in router and xState context
|
2023-10-04 18:00:55 -04:00
|
|
|
// We have to use a memory router in the testing environment,
|
|
|
|
// and we have to use the createMemoryRouter function instead of <MemoryRouter /> as of react-router v6.4:
|
|
|
|
// https://reactrouter.com/en/6.16.0/routers/picking-a-router#using-v64-data-apis
|
|
|
|
const router = createMemoryRouter(
|
|
|
|
createRoutesFromElements(
|
|
|
|
<Route
|
|
|
|
path="/file/:id"
|
|
|
|
element={
|
|
|
|
<CommandBarProvider>
|
2024-02-16 09:09:58 -05:00
|
|
|
<GlobalStateProvider>{children}</GlobalStateProvider>
|
2023-10-04 18:00:55 -04:00
|
|
|
</CommandBarProvider>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
{
|
|
|
|
initialEntries: ['/file/new'],
|
|
|
|
initialIndex: 0,
|
|
|
|
}
|
2023-08-22 05:34:20 +10:00
|
|
|
)
|
2023-10-04 18:00:55 -04:00
|
|
|
return <RouterProvider router={router} />
|
2023-08-22 05:34:20 +10:00
|
|
|
}
|