2022-11-26 08:34:23 +11:00
|
|
|
import { render, screen } from '@testing-library/react'
|
2023-06-22 16:43:33 +10:00
|
|
|
import { App } from './App'
|
2023-08-15 21:56:24 -04:00
|
|
|
import { describe, test, vi } from 'vitest'
|
2023-07-26 11:47:18 -05:00
|
|
|
import { BrowserRouter } from 'react-router-dom'
|
2023-08-22 05:34:20 +10:00
|
|
|
import { GlobalStateProvider } from './hooks/useAuthMachine'
|
2022-11-12 13:11:54 +11:00
|
|
|
|
2022-11-26 08:34:23 +11:00
|
|
|
let listener: ((rect: any) => void) | undefined = undefined
|
|
|
|
;(global as any).ResizeObserver = class ResizeObserver {
|
2022-11-25 11:02:00 +11:00
|
|
|
constructor(ls: ((rect: any) => void) | undefined) {
|
2022-11-26 08:34:23 +11:00
|
|
|
listener = ls
|
2022-11-25 11:02:00 +11:00
|
|
|
}
|
|
|
|
observe() {}
|
|
|
|
unobserve() {}
|
|
|
|
disconnect() {}
|
2022-11-26 08:34:23 +11:00
|
|
|
}
|
2022-11-25 11:02:00 +11:00
|
|
|
|
2023-08-15 21:56:24 -04:00
|
|
|
describe('App tests', () => {
|
|
|
|
test('Renders the modeling app screen, including "Variables" pane.', () => {
|
|
|
|
vi.mock('react-router-dom', async () => {
|
|
|
|
const actual = (await vi.importActual('react-router-dom')) as Record<
|
|
|
|
string,
|
|
|
|
any
|
|
|
|
>
|
|
|
|
return {
|
|
|
|
...actual,
|
|
|
|
useParams: () => ({ id: 'new' }),
|
|
|
|
useLoaderData: () => ({ code: null }),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
render(
|
2023-08-22 05:34:20 +10:00
|
|
|
<TestWrap>
|
2023-08-15 21:56:24 -04:00
|
|
|
<App />
|
2023-08-22 05:34:20 +10:00
|
|
|
</TestWrap>
|
2023-08-15 21:56:24 -04:00
|
|
|
)
|
|
|
|
const linkElement = screen.getByText(/Variables/i)
|
|
|
|
expect(linkElement).toBeInTheDocument()
|
|
|
|
|
|
|
|
vi.restoreAllMocks()
|
|
|
|
})
|
2022-11-26 08:34:23 +11:00
|
|
|
})
|
2023-08-22 05:34:20 +10:00
|
|
|
|
|
|
|
function TestWrap({ children }: { children: React.ReactNode }) {
|
|
|
|
// wrap in router and xState context
|
|
|
|
return (
|
|
|
|
<BrowserRouter>
|
|
|
|
<GlobalStateProvider>{children}</GlobalStateProvider>
|
|
|
|
</BrowserRouter>
|
|
|
|
)
|
|
|
|
}
|