import {
describe,
expect,
jest,
test,
} from '@jest/globals';
import { fireEvent, render } from '@testing-library/react';
import * as React from 'react';
import Element from '../src/Element';
describe('Element component', () => {
test('expanded element renders properly', () => {
const { container } = render(
,
);
expect(container).toMatchSnapshot();
});
test('collapsed element renders properly', () => {
const { container } = render(
,
);
expect(container).toMatchSnapshot();
});
test('element with attribute renders properly', () => {
const { container } = render(
,
);
expect(container).toMatchSnapshot();
});
test('click collapse button should collapse element and hide bubble', () => {
const setXml = jest.fn();
const showBubble = jest.fn();
const { getByTitle } = render(
,
);
fireEvent.click(getByTitle('Collapse'));
expect(setXml.mock.calls[0][0]).toEqual({
root: {
'#collapsed': true,
'#name': 'root',
},
});
expect(showBubble.mock.calls[0][0]).toEqual({
show: false,
});
});
test('click open tag should show bubble', () => {
const showBubble = jest.fn();
const { getByText } = render(
,
);
fireEvent.click(getByText('root'));
expect(showBubble.mock.calls[0][0]).toEqual({
element: 'root',
id: ['root'],
left: 0,
show: true,
top: 0,
value: 'root',
});
});
});