import { shallowMount } from '@vue/test-utils';
import TextWithHighlights from '@/components/TextWithHighlights.vue';
describe('TextWithHighlights', () => {
it('highlights the search text in the content', () => {
const wrapper = shallowMount(TextWithHighlights, {
props: {
content: 'Test content',
search: 'Test',
},
});
expect(wrapper.html()).toContain('Test');
expect(wrapper.html()).toContain(' content');
});
it('renders correctly when search is not set', () => {
const wrapper = shallowMount(TextWithHighlights, {
props: {
content: 'Test content',
},
});
expect(wrapper.html()).toEqual(
'Test content',
);
expect(wrapper.html()).not.toContain('');
});
it('renders correctly numbers when search is not set', () => {
const wrapper = shallowMount(TextWithHighlights, {
props: {
content: 1,
},
});
expect(wrapper.html()).toEqual('1');
expect(wrapper.html()).not.toContain('');
});
it('renders correctly objects when search is not set', async () => {
const wrapper = shallowMount(TextWithHighlights, {
props: {
content: { hello: 'world' },
},
});
expect(wrapper.html()).toEqual(
'{\n "hello": "world"\n}',
);
expect(wrapper.html()).not.toContain('');
});
it('renders correctly objects ignoring search', () => {
const wrapper = shallowMount(TextWithHighlights, {
props: {
content: { hello: 'world' },
search: 'yo',
},
});
expect(wrapper.html()).toEqual(
'{\n "hello": "world"\n}',
);
expect(wrapper.html()).not.toContain('');
});
it('highlights the search text in middle of the content', () => {
const wrapper = shallowMount(TextWithHighlights, {
props: {
content: 'Test content hello world',
search: 'con',
},
});
expect(wrapper.html()).toEqual(
'Test content hello world',
);
});
it('handles special regex characters in search correctly', () => {
const wrapper = shallowMount(TextWithHighlights, {
props: {
content: 'Test content (hello) world',
search: '(hello)',
},
});
expect(wrapper.html()).toEqual(
'Test content (hello) world',
);
});
it('searches for special regex characters correctly', () => {
const wrapper = shallowMount(TextWithHighlights, {
props: {
// eslint-disable-next-line n8n-local-rules/no-interpolation-in-regular-string
content: 'Test content ()^${}[] world',
// eslint-disable-next-line n8n-local-rules/no-interpolation-in-regular-string
search: '()^${}[]',
},
});
expect(wrapper.html()).toEqual(
// eslint-disable-next-line n8n-local-rules/no-interpolation-in-regular-string
'Test content ()^${}[] world',
);
});
it('renders new lines in the content correctly', () => {
const wrapper = shallowMount(TextWithHighlights, {
props: {
content: 'Line 1\n Line 2\nLine 3',
},
});
expect(wrapper.html()).toContain(
'Line 1\\n Line 2\\nLine 3',
);
});
});