Merge branch 'demo' into feat/recursive-goal-making
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { fireEvent, screen } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import {Tooltip} from "../../../../../src/pages/VisProgPage/visualProgrammingUI/components/NodeComponents.tsx";
|
||||
import {renderWithSidebar} from "../../../../test-utils/test-utils.tsx";
|
||||
|
||||
describe('Tooltip component test', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('renders and shows tooltip content on hover', () => {
|
||||
renderWithSidebar(
|
||||
<Tooltip nodeType="phase">
|
||||
<div>?</div>
|
||||
</Tooltip>
|
||||
);
|
||||
|
||||
const trigger = screen.getByText('?');
|
||||
|
||||
// initially hidden
|
||||
expect(
|
||||
screen.queryByText('Phase tooltip text')
|
||||
).not.toBeInTheDocument();
|
||||
|
||||
// hover shows tooltip
|
||||
fireEvent.mouseOver(trigger);
|
||||
|
||||
expect(screen.getByText('phase')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('A phase is a single stage of the program, during a phase Pepper will behave in accordance with any connected norms, goals and triggers')
|
||||
).toBeInTheDocument();
|
||||
|
||||
// rendered via portal
|
||||
expect(
|
||||
document.body.contains(
|
||||
screen.getByText('A phase is a single stage of the program, during a phase Pepper will behave in accordance with any connected norms, goals and triggers')
|
||||
)
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -19,6 +19,48 @@ export function renderWithProviders(
|
||||
}
|
||||
|
||||
|
||||
type SidebarRect = Partial<DOMRect>;
|
||||
|
||||
const defaultRect: DOMRect = {
|
||||
top: 0,
|
||||
left: 0,
|
||||
bottom: 100,
|
||||
right: 200,
|
||||
width: 200,
|
||||
height: 100,
|
||||
x: 0,
|
||||
y: 0,
|
||||
toJSON: () => {},
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders a component and injects a mock `#draggable-sidebar`
|
||||
* element required by Tooltip positioning logic.
|
||||
*/
|
||||
export function renderWithSidebar(
|
||||
ui: ReactElement,
|
||||
rect: SidebarRect = {},
|
||||
options?: RenderOptions
|
||||
) {
|
||||
const sidebar = document.createElement('div');
|
||||
sidebar.id = 'draggable-sidebar';
|
||||
|
||||
sidebar.getBoundingClientRect = jest.fn(() => ({
|
||||
...defaultRect,
|
||||
...rect,
|
||||
}));
|
||||
|
||||
document.body.appendChild(sidebar);
|
||||
|
||||
const result = render(ui, options);
|
||||
|
||||
return {
|
||||
...result,
|
||||
sidebar,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Re-export everything from testing library
|
||||
//eslint-disable-next-line react-refresh/only-export-components
|
||||
export * from '@testing-library/react';
|
||||
|
||||
Reference in New Issue
Block a user