2017-10-17 13:26:09 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
2017-10-18 07:19:29 +00:00
|
|
|
import mountComponent from '../../helpers/vue_mount_component_helper';
|
2017-10-17 13:26:09 +00:00
|
|
|
|
2017-10-17 14:53:13 +00:00
|
|
|
describe('Sprite Icon Component', function () {
|
2017-10-17 13:26:09 +00:00
|
|
|
describe('Initialization', function () {
|
2017-10-18 07:19:29 +00:00
|
|
|
let icon;
|
|
|
|
|
2017-10-17 13:26:09 +00:00
|
|
|
beforeEach(function () {
|
2017-10-18 07:19:29 +00:00
|
|
|
const IconComponent = Vue.extend(Icon);
|
|
|
|
|
|
|
|
icon = mountComponent(IconComponent, {
|
2017-10-17 13:26:09 +00:00
|
|
|
name: 'test',
|
2017-11-27 19:34:03 +00:00
|
|
|
size: 32,
|
2017-10-17 13:26:09 +00:00
|
|
|
cssClasses: 'extraclasses',
|
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
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
expect(icon.$el.firstChild.getAttribute('xlink:href')).toBe(`${gon.sprite_icons}#test`);
|
2017-10-17 13:26:09 +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
|
|
|
});
|
|
|
|
|
|
|
|
it('should properly render img css', function () {
|
2017-10-18 07:19:29 +00:00
|
|
|
const classList = icon.$el.classList;
|
2017-11-27 19:34:03 +00:00
|
|
|
const containsSizeClass = classList.contains('s32');
|
2017-10-17 13:26:09 +00:00
|
|
|
const containsCustomClass = classList.contains('extraclasses');
|
|
|
|
expect(containsSizeClass).toBe(true);
|
|
|
|
expect(containsCustomClass).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|