2017-10-17 09:26:09 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
2018-02-26 14:43:34 -05:00
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2017-10-17 09:26:09 -04:00
|
|
|
|
2017-10-17 10:53:13 -04:00
|
|
|
describe('Sprite Icon Component', function () {
|
2017-10-17 09:26:09 -04:00
|
|
|
describe('Initialization', function () {
|
2017-10-18 03:19:29 -04:00
|
|
|
let icon;
|
|
|
|
|
2017-10-17 09:26:09 -04:00
|
|
|
beforeEach(function () {
|
2017-10-18 03:19:29 -04:00
|
|
|
const IconComponent = Vue.extend(Icon);
|
|
|
|
|
|
|
|
icon = mountComponent(IconComponent, {
|
2018-07-18 12:56:19 -04:00
|
|
|
name: 'commit',
|
2017-11-27 14:34:03 -05:00
|
|
|
size: 32,
|
2017-10-17 09:26:09 -04:00
|
|
|
cssClasses: 'extraclasses',
|
2018-08-07 08:30:08 -04:00
|
|
|
tabIndex: '0',
|
2017-10-18 03:19:29 -04:00
|
|
|
});
|
|
|
|
});
|
2017-10-17 09:26:09 -04:00
|
|
|
|
2017-10-18 03:19:29 -04:00
|
|
|
afterEach(() => {
|
|
|
|
icon.$destroy();
|
2017-10-17 09:26:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a defined Vue component', function () {
|
2017-10-18 03:19:29 -04:00
|
|
|
expect(icon).toBeDefined();
|
2017-10-17 09:26:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should have <svg> as a child element', function () {
|
2017-10-18 03:19:29 -04:00
|
|
|
expect(icon.$el.tagName).toBe('svg');
|
2017-10-17 09:26:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should have <use> as a child element with the correct href', function () {
|
2017-10-18 03:19:29 -04:00
|
|
|
expect(icon.$el.firstChild.tagName).toBe('use');
|
2018-07-18 12:56:19 -04:00
|
|
|
expect(icon.$el.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_icons}#commit`);
|
2017-10-17 09:26:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should properly compute iconSizeClass', function () {
|
2017-11-27 14:34:03 -05: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 09:26:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should properly render img css', function () {
|
2018-06-16 17:50:13 -04:00
|
|
|
const { classList } = icon.$el;
|
2017-11-27 14:34:03 -05:00
|
|
|
const containsSizeClass = classList.contains('s32');
|
2017-10-17 09:26:09 -04:00
|
|
|
const containsCustomClass = classList.contains('extraclasses');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-17 09:26:09 -04:00
|
|
|
expect(containsSizeClass).toBe(true);
|
|
|
|
expect(containsCustomClass).toBe(true);
|
|
|
|
});
|
2018-07-18 12:56:19 -04: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);
|
|
|
|
});
|
2018-08-07 08:30:08 -04:00
|
|
|
|
|
|
|
it('should contain `tabindex` attribute on svg element when `tabIndex` prop is defined', () => {
|
|
|
|
expect(icon.$el.getAttribute('tabindex')).toBe('0');
|
|
|
|
});
|
2017-10-17 09:26:09 -04:00
|
|
|
});
|
|
|
|
});
|