2017-10-17 13:26:09 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
2018-02-26 19:43:34 +00:00
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2019-11-11 12:06:23 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2017-10-17 13:26:09 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
describe('Sprite Icon Component', function() {
|
|
|
|
describe('Initialization', function() {
|
2017-10-18 07:19:29 +00:00
|
|
|
let icon;
|
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
beforeEach(function() {
|
2017-10-18 07:19:29 +00:00
|
|
|
const IconComponent = Vue.extend(Icon);
|
|
|
|
|
|
|
|
icon = mountComponent(IconComponent, {
|
2018-07-18 16:56:19 +00:00
|
|
|
name: 'commit',
|
2017-11-27 19:34:03 +00:00
|
|
|
size: 32,
|
2017-10-18 07:19:29 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-17 13:26:09 +00:00
|
|
|
|
2017-10-18 07:19:29 +00:00
|
|
|
afterEach(() => {
|
|
|
|
icon.$destroy();
|
2017-10-17 13:26:09 +00:00
|
|
|
});
|
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
it('should return a defined Vue component', function() {
|
2017-10-18 07:19:29 +00:00
|
|
|
expect(icon).toBeDefined();
|
2017-10-17 13:26:09 +00:00
|
|
|
});
|
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
it('should have <svg> as a child element', function() {
|
2017-10-18 07:19:29 +00:00
|
|
|
expect(icon.$el.tagName).toBe('svg');
|
2017-10-17 13:26:09 +00:00
|
|
|
});
|
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
it('should have <use> as a child element with the correct href', function() {
|
2017-10-18 07:19:29 +00:00
|
|
|
expect(icon.$el.firstChild.tagName).toBe('use');
|
2018-07-18 16:56:19 +00:00
|
|
|
expect(icon.$el.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_icons}#commit`);
|
2017-10-17 13:26:09 +00:00
|
|
|
});
|
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
it('should properly compute iconSizeClass', function() {
|
2017-11-27 19:34:03 +00:00
|
|
|
expect(icon.iconSizeClass).toBe('s32');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('forbids invalid size prop', () => {
|
|
|
|
expect(icon.$options.props.size.validator(NaN)).toBeFalsy();
|
|
|
|
expect(icon.$options.props.size.validator(0)).toBeFalsy();
|
|
|
|
expect(icon.$options.props.size.validator(9001)).toBeFalsy();
|
2017-10-17 13:26:09 +00:00
|
|
|
});
|
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
it('should properly render img css', function() {
|
2018-06-16 21:50:13 +00:00
|
|
|
const { classList } = icon.$el;
|
2017-11-27 19:34:03 +00:00
|
|
|
const containsSizeClass = classList.contains('s32');
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-10-17 13:26:09 +00:00
|
|
|
expect(containsSizeClass).toBe(true);
|
|
|
|
});
|
2018-07-18 16:56:19 +00:00
|
|
|
|
|
|
|
it('`name` validator should return false for non existing icons', () => {
|
|
|
|
expect(Icon.props.name.validator('non_existing_icon_sprite')).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('`name` validator should return false for existing icons', () => {
|
|
|
|
expect(Icon.props.name.validator('commit')).toBe(true);
|
|
|
|
});
|
2017-10-17 13:26:09 +00:00
|
|
|
});
|
2019-11-11 12:06:23 +00:00
|
|
|
|
|
|
|
it('should call registered listeners when they are triggered', () => {
|
|
|
|
const clickHandler = jasmine.createSpy('clickHandler');
|
|
|
|
const wrapper = mount(Icon, {
|
|
|
|
propsData: { name: 'commit' },
|
|
|
|
listeners: { click: clickHandler },
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.find('svg').trigger('click');
|
|
|
|
|
|
|
|
expect(clickHandler).toHaveBeenCalled();
|
|
|
|
});
|
2017-10-17 13:26:09 +00:00
|
|
|
});
|