import { describe, expect, it } from 'vitest';
import { render, waitFor, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MDLabel } from './MDLabel';
function getStringHtmlWithoutId(htmlElement: HTMLElement) {
return htmlElement.outerHTML.replace(/id="[^"]+"/g, '');
}
describe('md-label', () => {
it('should handle simple text', () => {
const obj = render();
return expect(obj.container).toMatchInlineSnapshot(`
This
is
a simple test
`);
});
it('should handle line break', () => {
const obj = render(
);
return expect(obj.container).toMatchInlineSnapshot(`
This
is
a simple test
on multiple line
`);
});
it('should handle paragraphs break', () => {
const obj = render(
);
return expect(obj.container).toMatchInlineSnapshot(`
This
is
a simple test
with multiple paragraphs
`);
});
it('should handle emoticon', () => {
const obj = render();
return expect(obj.container).toMatchInlineSnapshot(`
Demo
of a
🐶
`);
});
it('should render external link', () => {
const obj = render(
);
const stringHtmlWithoutId = getStringHtmlWithoutId(obj.container);
return expect(stringHtmlWithoutId).toMatchInlineSnapshot(
`""`
);
});
it('should render external link with tooltip', async () => {
render(
);
const link = screen.getByText('link'); // Get the link element by its text content
// Simulate hover event
await userEvent.hover(link);
let tooltip: HTMLElement | undefined;
await waitFor(() => {
tooltip = screen.getByRole('tooltip');
});
expect(link.getAttribute('data-tooltip-id')).toBe(tooltip?.id);
expect(tooltip).toBeInTheDocument();
});
it('should render internal link', () => {
const obj = render(
);
return expect(getStringHtmlWithoutId(obj.container)).toMatchInlineSnapshot(
`""`
);
});
it('should render internal link with tooltip', async () => {
render(
);
const link = screen.getByText('internal link'); // Get the link element by its text content
// Simulate hover event
await userEvent.hover(link);
let tooltip = null;
await waitFor(() => {
tooltip = screen.getByRole('tooltip');
});
expect(tooltip).toBeInTheDocument();
});
});