2022-02-18 14:53:55 +01:00
|
|
|
import {render, fireEvent} from '@testing-library/vue'
|
2021-03-23 19:26:50 +01:00
|
|
|
import { Smile } from '../src/icons'
|
2021-02-22 20:26:38 +01:00
|
|
|
|
|
|
|
|
describe('Using lucide icon components', () => {
|
|
|
|
|
it('should render an component', () => {
|
2022-02-18 14:53:55 +01:00
|
|
|
const {container} = render(Smile)
|
|
|
|
|
expect(container).toMatchSnapshot();
|
2021-02-22 20:26:38 +01: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-02-22 20:26:38 +01:00
|
|
|
size: 48,
|
2022-02-18 14:53:55 +01:00
|
|
|
color: 'red',
|
2021-02-22 20:26:38 +01:00
|
|
|
strokeWidth: 4
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
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-02-22 20:26:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should add a class to the element', () => {
|
2022-02-18 14:53:55 +01:00
|
|
|
const {container} = render(Smile, {
|
2021-02-22 20:26:38 +01:00
|
|
|
attrs: {
|
|
|
|
|
class: "my-icon"
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2022-02-18 14:53:55 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
|
|
|
|
|
const [icon] = document.getElementsByClassName('lucide');
|
|
|
|
|
|
|
|
|
|
expect(icon).toHaveClass('my-icon')
|
2021-02-22 20:26:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should add a style attribute to the element', () => {
|
2022-02-18 14:53:55 +01:00
|
|
|
const {container} = render(Smile, {
|
2021-02-22 20:26:38 +01: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' })
|
2021-02-22 20:26:38 +01:00
|
|
|
});
|
2021-09-20 08:33:32 +02:00
|
|
|
|
2022-02-18 14:53:55 +01:00
|
|
|
it('should call the onClick event', async () => {
|
2021-09-20 08:33:32 +02:00
|
|
|
const onClick = jest.fn()
|
2022-02-18 14:53:55 +01:00
|
|
|
render(Smile, {
|
2021-09-20 08:33:32 +02:00
|
|
|
listeners: {
|
|
|
|
|
click: onClick
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2022-02-18 14:53:55 +01:00
|
|
|
const [icon] = document.getElementsByClassName('lucide');
|
|
|
|
|
|
|
|
|
|
await fireEvent.click(icon)
|
|
|
|
|
|
2021-09-20 08:33:32 +02:00
|
|
|
expect(onClick).toHaveBeenCalled()
|
|
|
|
|
});
|
2022-02-18 14:53:55 +01:00
|
|
|
|
|
|
|
|
it('should pass children to the icon slot', () => {
|
|
|
|
|
const testText = 'Hello World'
|
|
|
|
|
const template = `<text>${testText}</text>`
|
|
|
|
|
const { getByText, container } = render(Smile, {
|
|
|
|
|
slots: {
|
|
|
|
|
default: { template }
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const textElement = getByText(testText)
|
|
|
|
|
|
|
|
|
|
expect(textElement).toBeInTheDocument()
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
});
|
2021-02-22 20:26:38 +01:00
|
|
|
});
|