Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 42 additions & 42 deletions packages/hotspot/src/hotspot/__tests__/circle.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('CircleComponent', () => {
it('should render with correct position and radius', () => {
const { getByTestId } = render(<CircleComponent {...defaultProps} />);
const circle = getByTestId('circle');

expect(circle).toHaveAttribute('x', '50');
expect(circle).toHaveAttribute('y', '50');
expect(circle).toHaveAttribute('radius', '30');
Expand All @@ -79,29 +79,29 @@ describe('CircleComponent', () => {
it('should render with hotspot color when not selected', () => {
const { getByTestId } = render(<CircleComponent {...defaultProps} />);
const circle = getByTestId('circle');

expect(circle).toHaveAttribute('fill', '#FF0000');
});

it('should render with selected color when selected', () => {
const { getByTestId } = render(<CircleComponent {...defaultProps} selected={true} />);
const circle = getByTestId('circle');

expect(circle).toHaveAttribute('fill', '#00FF00');
});

it('should apply scale transform', () => {
const { getByTestId } = render(<CircleComponent {...defaultProps} scale={2.0} />);
const group = getByTestId('group');

expect(group).toHaveAttribute('scaleX', '2');
expect(group).toHaveAttribute('scaleY', '2');
});

it('should render with default scale of 1', () => {
const { getByTestId } = render(<CircleComponent {...defaultProps} />);
const group = getByTestId('group');

expect(group).toHaveAttribute('scaleX', '1');
expect(group).toHaveAttribute('scaleY', '1');
});
Expand All @@ -112,9 +112,9 @@ describe('CircleComponent', () => {
const onClick = jest.fn();
const { getByTestId } = render(<CircleComponent {...defaultProps} onClick={onClick} />);
const circle = getByTestId('circle');

fireEvent.click(circle);

expect(onClick).toHaveBeenCalledWith({
id: 'circle1',
selected: true,
Expand All @@ -126,20 +126,20 @@ describe('CircleComponent', () => {
const onClick = jest.fn();
const { getByTestId, rerender } = render(<CircleComponent {...defaultProps} onClick={onClick} selected={false} />);
const circle = getByTestId('circle');

fireEvent.click(circle);

expect(onClick).toHaveBeenCalledWith({
id: 'circle1',
selected: true,
selector: 'Mouse',
});

rerender(<CircleComponent {...defaultProps} onClick={onClick} selected={true} />);

const circleAfter = getByTestId('circle');
fireEvent.click(circleAfter);

expect(onClick).toHaveBeenCalledWith({
id: 'circle1',
selected: false,
Expand All @@ -151,37 +151,37 @@ describe('CircleComponent', () => {
const onClick = jest.fn();
const { getByTestId } = render(<CircleComponent {...defaultProps} onClick={onClick} disabled={true} />);
const circle = getByTestId('circle');

fireEvent.click(circle);

expect(onClick).not.toHaveBeenCalled();
});

it('should change cursor to pointer on mouse enter when not disabled', () => {
const { getByTestId } = render(<CircleComponent {...defaultProps} />);
const circle = getByTestId('circle');

fireEvent.mouseEnter(circle);

expect(document.body.style.cursor).toBe('pointer');
});

it('should not change cursor when disabled', () => {
const { getByTestId } = render(<CircleComponent {...defaultProps} disabled={true} />);
const circle = getByTestId('circle');

fireEvent.mouseEnter(circle);

expect(document.body.style.cursor).toBe('default');
});

it('should reset cursor to default on mouse leave', () => {
const { getByTestId } = render(<CircleComponent {...defaultProps} />);
const circle = getByTestId('circle');

fireEvent.mouseEnter(circle);
fireEvent.mouseLeave(circle);

expect(document.body.style.cursor).toBe('default');
});
});
Expand All @@ -190,9 +190,9 @@ describe('CircleComponent', () => {
it('should show hover rect when hoverOutlineColor is provided', () => {
const { container, getByTestId } = render(<CircleComponent {...defaultProps} hoverOutlineColor="#FFFF00" />);
const circle = getByTestId('circle');

fireEvent.mouseEnter(circle);

const rects = container.querySelectorAll('[data-testid="rect"]');
expect(rects.length).toBeGreaterThan(0);
});
Expand All @@ -208,9 +208,9 @@ describe('CircleComponent', () => {
/>
);
const circle = getByTestId('circle');

fireEvent.mouseEnter(circle);

const rect = container.querySelector('[data-testid="rect"]');
if (rect) {
// Rect should be positioned at (x - radius, y - radius) with width/height = radius * 2
Expand All @@ -226,12 +226,12 @@ describe('CircleComponent', () => {
<CircleComponent {...defaultProps} selected={true} hoverOutlineColor="#FFFF00" />
);
const circle = getByTestId('circle');

fireEvent.mouseEnter(circle);

const rect = container.querySelector('[data-testid="rect"]');
if (rect) {
expect(rect).toHaveAttribute('stroke', 'transparent');
expect(rect).toHaveAttribute('stroke', '#FFFF00');
}
});
});
Expand All @@ -247,7 +247,7 @@ describe('CircleComponent', () => {
showCorrectEnabled={false}
/>
);

const icon = getByTestId('icon-image');
expect(icon).toBeInTheDocument();
});
Expand All @@ -262,7 +262,7 @@ describe('CircleComponent', () => {
showCorrectEnabled={false}
/>
);

const icon = getByTestId('icon-image');
expect(icon).toBeInTheDocument();
});
Expand All @@ -277,7 +277,7 @@ describe('CircleComponent', () => {
showCorrectEnabled={false}
/>
);

const icon = getByTestId('icon-image');
expect(icon).toBeInTheDocument();
});
Expand All @@ -292,7 +292,7 @@ describe('CircleComponent', () => {
showCorrectEnabled={false}
/>
);

const icon = queryByTestId('icon-image');
expect(icon).not.toBeInTheDocument();
});
Expand All @@ -307,7 +307,7 @@ describe('CircleComponent', () => {
showCorrectEnabled={true}
/>
);

const icon = getByTestId('icon-image');
expect(icon).toBeInTheDocument();
});
Expand All @@ -322,7 +322,7 @@ describe('CircleComponent', () => {
showCorrectEnabled={true}
/>
);

const icon = getByTestId('icon-image');
expect(icon).toBeInTheDocument();
});
Expand All @@ -337,7 +337,7 @@ describe('CircleComponent', () => {
showCorrectEnabled={true}
/>
);

const icon = queryByTestId('icon-image');
expect(icon).not.toBeInTheDocument();
});
Expand All @@ -352,7 +352,7 @@ describe('CircleComponent', () => {
showCorrectEnabled={true}
/>
);

const icon = queryByTestId('icon-image');
expect(icon).not.toBeInTheDocument();
});
Expand All @@ -365,7 +365,7 @@ describe('CircleComponent', () => {
markAsCorrect={true}
/>
);

const circle = getByTestId('circle');
expect(circle).toHaveAttribute('stroke', 'green');
});
Expand All @@ -379,7 +379,7 @@ describe('CircleComponent', () => {
markAsCorrect={false}
/>
);

const circle = getByTestId('circle');
expect(circle).toHaveAttribute('stroke', 'red');
});
Expand All @@ -395,7 +395,7 @@ describe('CircleComponent', () => {
showCorrectEnabled={false}
/>
);

const icon = getByTestId('icon-image');
expect(icon).toHaveAttribute('data-tooltip', 'Great job!');
});
Expand All @@ -415,7 +415,7 @@ describe('CircleComponent', () => {
showCorrectEnabled={false}
/>
);

const icon = getByTestId('icon-image');
// Icon should be at x - 10, y - 10
expect(icon).toHaveAttribute('data-x', '90');
Expand All @@ -431,7 +431,7 @@ describe('CircleComponent', () => {
radius={5}
/>
);

const circle = getByTestId('circle');
expect(circle).toHaveAttribute('radius', '5');
});
Expand All @@ -443,7 +443,7 @@ describe('CircleComponent', () => {
radius={200}
/>
);

const circle = getByTestId('circle');
expect(circle).toHaveAttribute('radius', '200');
});
Expand All @@ -455,7 +455,7 @@ describe('CircleComponent', () => {
scale={0.5}
/>
);

const group = getByTestId('group');
expect(group).toHaveAttribute('scaleX', '0.5');
expect(group).toHaveAttribute('scaleY', '0.5');
Expand Down
Loading
Loading