debian-mirror-gitlab/spec/javascripts/vue_shared/components/icon_spec.js

68 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
import Icon from '~/vue_shared/components/icon.vue';
2018-03-27 19:54:05 +05:30
import mountComponent from 'spec/helpers/vue_mount_component_helper';
2018-03-17 18:26:18 +05:30
describe('Sprite Icon Component', function () {
describe('Initialization', function () {
let icon;
beforeEach(function () {
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,
cssClasses: 'extraclasses',
2018-11-18 11:00:15 +05:30
tabIndex: '0',
2018-03-17 18:26:18 +05:30
});
});
afterEach(() => {
icon.$destroy();
});
it('should return a defined Vue component', function () {
expect(icon).toBeDefined();
});
it('should have <svg> as a child element', function () {
expect(icon.$el.tagName).toBe('svg');
});
it('should have <use> as a child element with the correct href', function () {
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
});
it('should properly compute iconSizeClass', function () {
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();
});
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');
const containsCustomClass = classList.contains('extraclasses');
expect(containsSizeClass).toBe(true);
expect(containsCustomClass).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);
});
it('should contain `tabindex` attribute on svg element when `tabIndex` prop is defined', () => {
expect(icon.$el.getAttribute('tabindex')).toBe('0');
});
2018-03-17 18:26:18 +05:30
});
});