2022-12-04 22:38:56 +01:00
|
|
|
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
|
|
|
import {render, fireEvent, cleanup } from '@testing-library/vue'
|
2023-04-20 16:08:34 +02:00
|
|
|
import { Smile, Edit2, Pen } from '../src/lucide-vue-next'
|
2021-05-20 21:24:54 +02:00
|
|
|
|
|
|
|
|
describe('Using lucide icon components', () => {
|
2022-12-04 22:38:56 +01:00
|
|
|
afterEach(() => cleanup())
|
|
|
|
|
|
2021-05-20 21:24:54 +02:00
|
|
|
it('should render an component', () => {
|
2022-02-18 14:53:55 +01:00
|
|
|
const { container } = render(Smile)
|
|
|
|
|
expect(container).toMatchSnapshot();
|
2021-05-20 21:24:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should adjust the size, stroke color and stroke width', () => {
|
2022-02-18 14:53:55 +01:00
|
|
|
const {container} = render(Smile, {
|
|
|
|
|
props: {
|
2021-05-20 21:24:54 +02:00
|
|
|
size: 48,
|
2022-02-18 14:53:55 +01:00
|
|
|
color: 'red',
|
|
|
|
|
'stroke-width': 4
|
2021-05-20 21:24:54 +02:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2022-02-18 14:53:55 +01:00
|
|
|
const [icon] = document.getElementsByClassName('lucide');
|
|
|
|
|
|
|
|
|
|
expect(icon.getAttribute('width')).toBe('48')
|
|
|
|
|
expect(icon.getAttribute('stroke')).toBe('red')
|
|
|
|
|
expect(icon.getAttribute('stroke-width')).toBe('4')
|
|
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
2021-05-20 21:24:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should add a class to the element', () => {
|
2022-02-18 14:53:55 +01:00
|
|
|
const {container} = render(Smile, {
|
2021-05-20 21:24:54 +02:00
|
|
|
attrs: {
|
2022-02-18 14:53:55 +01:00
|
|
|
class: "my-icon"
|
2021-05-20 21:24:54 +02:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2022-02-18 14:53:55 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
|
|
|
|
|
const [icon] = document.getElementsByClassName('my-icon');
|
|
|
|
|
|
|
|
|
|
expect(icon).toHaveClass('my-icon')
|
2023-11-24 13:59:12 +01:00
|
|
|
expect(icon).toHaveClass('lucide')
|
|
|
|
|
expect(icon).toHaveClass('lucide-smile-icon')
|
2021-05-20 21:24:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should add a style attribute to the element', () => {
|
2022-02-18 14:53:55 +01:00
|
|
|
const {container} = render(Smile, {
|
2021-05-20 21:24:54 +02:00
|
|
|
attrs: {
|
|
|
|
|
style: 'position: absolute',
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2022-02-18 14:53:55 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
|
|
|
|
|
const [icon] = document.getElementsByClassName('lucide');
|
|
|
|
|
|
|
|
|
|
expect(icon).toHaveStyle({ position: 'absolute' })
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should call the onClick event', async () => {
|
2022-12-04 22:38:56 +01:00
|
|
|
const onClick = vi.fn()
|
2022-02-18 14:53:55 +01:00
|
|
|
render(Smile, {
|
|
|
|
|
attrs: {
|
|
|
|
|
onClick,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const [icon] = document.getElementsByClassName('lucide');
|
|
|
|
|
|
|
|
|
|
await fireEvent.click(icon)
|
|
|
|
|
|
|
|
|
|
expect(onClick).toHaveBeenCalled()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should pass children to the icon slot', () => {
|
|
|
|
|
const testText = 'Hello World'
|
|
|
|
|
const template = {
|
|
|
|
|
name: 'Stub',
|
|
|
|
|
template: `<text>${testText}</text>`
|
|
|
|
|
}
|
|
|
|
|
const { getByText, container } = render(Smile, {
|
|
|
|
|
slots: {
|
|
|
|
|
default: template
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const textElement = getByText(testText)
|
|
|
|
|
|
|
|
|
|
expect(textElement).toBeInTheDocument()
|
|
|
|
|
expect(container).toMatchSnapshot();
|
2021-05-20 21:24:54 +02:00
|
|
|
});
|
2023-04-20 16:08:34 +02:00
|
|
|
|
|
|
|
|
it('should render the alias icon', () => {
|
|
|
|
|
const { container } = render(Pen, {
|
|
|
|
|
props: {
|
|
|
|
|
size: 48,
|
|
|
|
|
color: 'red',
|
|
|
|
|
'stroke-width': 4
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const PenIconRenderedHTML = container.innerHTML
|
|
|
|
|
|
|
|
|
|
cleanup()
|
|
|
|
|
|
|
|
|
|
const { container: Edit2Container } = render(Edit2, {
|
|
|
|
|
props: {
|
|
|
|
|
size: 48,
|
|
|
|
|
color: 'red',
|
|
|
|
|
'stroke-width': 4
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
console.log(PenIconRenderedHTML, Edit2Container.innerHTML)
|
|
|
|
|
|
|
|
|
|
expect(PenIconRenderedHTML).toBe(Edit2Container.innerHTML)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should not scale the strokeWidth when absoluteStrokeWidth is set', () => {
|
|
|
|
|
render(Pen, {
|
|
|
|
|
props: {
|
|
|
|
|
size: 48,
|
|
|
|
|
color: 'red',
|
|
|
|
|
absoluteStrokeWidth: true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const [icon] = document.getElementsByClassName('lucide');
|
|
|
|
|
|
|
|
|
|
expect(icon.getAttribute('width')).toBe('48')
|
|
|
|
|
expect(icon.getAttribute('stroke')).toBe('red')
|
|
|
|
|
expect(icon.getAttribute('stroke-width')).toBe('1')
|
|
|
|
|
})
|
2021-05-20 21:24:54 +02:00
|
|
|
});
|