2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
2019-12-26 22:10:19 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('Sprite Icon Component', function() {
|
|
|
|
describe('Initialization', function() {
|
2018-03-17 18:26:18 +05:30
|
|
|
let icon;
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(function() {
|
2018-03-17 18:26:18 +05:30
|
|
|
const IconComponent = Vue.extend(Icon);
|
|
|
|
|
|
|
|
icon = mountComponent(IconComponent, {
|
2018-11-18 11:00:15 +05:30
|
|
|
name: 'commit',
|
2018-03-17 18:26:18 +05:30
|
|
|
size: 32,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
icon.$destroy();
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should return a defined Vue component', function() {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(icon).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should have <svg> as a child element', function() {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(icon.$el.tagName).toBe('svg');
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should have <use> as a child element with the correct href', function() {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(icon.$el.firstChild.tagName).toBe('use');
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(icon.$el.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_icons}#commit`);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should properly compute iconSizeClass', function() {
|
2018-03-17 18:26:18 +05:30
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should properly render img css', function() {
|
2018-11-08 19:23:39 +05:30
|
|
|
const { classList } = icon.$el;
|
2018-03-17 18:26:18 +05:30
|
|
|
const containsSizeClass = classList.contains('s32');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(containsSizeClass).toBe(true);
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|