gitlab-org--gitlab-foss/spec/javascripts/vue_shared/components/user_avatar_link_spec.js

90 lines
3.0 KiB
JavaScript
Raw Normal View History

2017-04-15 23:38:07 +00:00
import Vue from 'vue';
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
describe('User Avatar Link Component', function () {
beforeEach(function () {
this.propsData = {
linkHref: 'myavatarurl.com',
imgSize: 99,
imgSrc: 'myavatarurl.com',
imgAlt: 'mydisplayname',
imgCssClasses: 'myextraavatarclass',
tooltipText: 'tooltip text',
tooltipPlacement: 'bottom',
username: 'username',
2017-04-15 23:38:07 +00:00
};
const UserAvatarLinkComponent = Vue.extend(UserAvatarLink);
this.userAvatarLink = new UserAvatarLinkComponent({
propsData: this.propsData,
}).$mount();
this.userAvatarImage = this.userAvatarLink.$children[0];
});
it('should return a defined Vue component', function () {
expect(this.userAvatarLink).toBeDefined();
});
it('should have user-avatar-image registered as child component', function () {
expect(this.userAvatarLink.$options.components.userAvatarImage).toBeDefined();
});
it('user-avatar-link should have user-avatar-image as child component', function () {
expect(this.userAvatarImage).toBeDefined();
});
it('should render <a> as a child element', function () {
expect(this.userAvatarLink.$el.tagName).toBe('A');
2017-04-15 23:38:07 +00:00
});
it('should have <img> as a child element', function () {
expect(this.userAvatarLink.$el.querySelector('img')).not.toBeNull();
2017-04-15 23:38:07 +00:00
});
it('should return neccessary props as defined', function () {
_.each(this.propsData, (val, key) => {
expect(this.userAvatarLink[key]).toBeDefined();
});
});
describe('no username', function () {
beforeEach(function (done) {
this.userAvatarLink.username = '';
Vue.nextTick(done);
});
it('should not render <span> as a child element', function () {
expect(this.userAvatarLink.$el.querySelector('span')).toBeNull();
});
it('should render avatar image tooltip', function () {
expect(this.userAvatarLink.$el.querySelector('img').dataset.originalTitle).toEqual(this.propsData.tooltipText);
});
});
describe('username', function () {
it('should not render avatar image tooltip', function () {
expect(this.userAvatarLink.$el.querySelector('img').dataset.originalTitle).toEqual('');
});
it('should render <span> as a child element', function () {
expect(this.userAvatarLink.$el.querySelector('span')).toBeDefined();
});
it('should render username prop in <span>', function () {
expect(this.userAvatarLink.$el.querySelector('span').innerText.trim()).toEqual(this.propsData.username);
});
it('should render text tooltip for <span>', function () {
expect(this.userAvatarLink.$el.querySelector('span').dataset.originalTitle).toEqual(this.propsData.tooltipText);
});
it('should render text tooltip placement for <span>', function () {
expect(this.userAvatarLink.$el.querySelector('span').getAttribute('tooltip-placement')).toEqual(this.propsData.tooltipPlacement);
});
});
2017-04-15 23:38:07 +00:00
});