Commit 2a4a7bea authored by Bryce Johnson's avatar Bryce Johnson

Begin link-to-member unit test.

parent 5e7210c0
...@@ -42,6 +42,10 @@ ...@@ -42,6 +42,10 @@
type: Boolean, type: Boolean,
default: false, default: false,
required: false, required: false,
},
tooltipContainer: {
type: String,
required: false,
} }
}, },
data() { data() {
...@@ -50,6 +54,9 @@ ...@@ -50,6 +54,9 @@
}; };
}, },
computed: { computed: {
avatarElemId() {
return `${this.username}-avatar-link`;
},
userProfileUrl() { userProfileUrl() {
return this.nonUser || !this.username ? '' : `/${this.username}`; return this.nonUser || !this.username ? '' : `/${this.username}`;
}, },
...@@ -67,12 +74,17 @@ ...@@ -67,12 +74,17 @@
}, },
linkClass() { linkClass() {
return `author_link ${this.tooltipClass} ${this.extraLinkClass} ${this.disabledClass}` return `author_link ${this.tooltipClass} ${this.extraLinkClass} ${this.disabledClass}`
},
tooltipContainerAttr() {
return this.tooltipContainer || `#${this.avatarElemId}`;
} }
}, },
template: ` template: `
<a :href='userProfileUrl' :class='linkClass' :data-original-title='displayName' data-container='body'> <span :id='avatarElemId'>
<img :class='avatarClass' :src='preppedAvatarUrl' :width='size' :height='size' :alt='displayName'/> <a :href='userProfileUrl' :class='linkClass' :data-original-title='displayName' :data-container='tooltipContainerAttr'>
</a> <img :class='avatarClass' :src='preppedAvatarUrl' :width='size' :height='size' :alt='displayName'/>
</a>
</span>
` `
}); });
})(); })();
/* eslint-disable */ /* eslint-disable */
//= require jquery //= require jquery
//= require vue //= require vue
//= require issuable_time_tracker //= require vue_common_component/link_to_member_avatar
((gl) => { ((gl) => {
function initComponent(propsData = {}) {
fixture.set(`
<div>
<div id="mock-container"></div>
</div>
`);
const LinkToMembersComponent = Vue.component('link-to-member-avatar');
this.component = new LinkToMembersComponent({
el: '#mock-container',
propsData,
}).$mount();
this.$document = $(document);
}
describe('Link To Members Components', function() { describe('Link To Members Components', function() {
describe('Initialization', function() { describe('Initialization', function() {
is defined describe('No configuration (defaults)', function() {
has containing elements beforeEach(function() {
configuration, including computed values and special config initComponent.call(this, { nonUser: true });
loading state });
});
describe('Invalid input', function() { it('should return a defined Vue component', function() {
defaults applied or errors thrown expect(this.component).toBeDefined();
}); expect(this.component.$data).toBeDefined();
});
describe('Tooltip', function() { it('should have <a> and <img> children', function() {
hover state const componentLink = this.component.$el;
display based on flags const componentLinkTagname = componentLink.tagName;
});
const componentImg = componentLink.childNodes[0];
const componentImgTagname = componentImg.tagName;
describe('Avatar', function() { expect(componentLink).toBeDefined();
avatarurl vs empty state vs gravatar expect(componentLinkTagname).toBe('A');
expect(componentImg).toBeDefined();
expect(componentImgTagname).toBe('IMG');
});
it('should correctly compute computed values', function() {
// disabledclass, avatarClass, tooltipClass, userProfileUrl, preppedAvatarUrl, linkClass, tooltipClass
const correctVals = {
'disabledClass': 'disabled',
'avatarClass': 'avatar avatar-inline s48 ',
'preppedAvatarUrl': '/assets/no_avatar.png',
'tooltipClass': '',
'userProfileUrl': '',
};
for (var computedKey in correctVals) {
const expectedVal = correctVals[computedKey];
const actualComputed = this.component[computedKey];
expect(actualComputed).toBe(expectedVal);
}
});
});
describe('Props Configured', function() {
beforeEach(function() {
const propsData = this.propsData = {
avatarUrl: 'myavatarurl.com',
username: 'myusername',
displayName: 'mydisplayname',
extraAvatarClass: 'myextraavatarclass',
extraLinkClass: 'myextralinkclass',
showTooltip: true,
size: 32,
nonUser: false
};
initComponent.call(this, {
propsData
});
});
it('should correctly compute computed values', function(done) {
// disabledclass, avatarClass, tooltipClass, userProfileUrl, preppedAvatarUrl, linkClass, tooltipClass
const correctVals = {
'disabledClass': '',
'avatarClass': 'avatar avatar-inline s48 ',
'preppedAvatarUrl': this.propsData.avatarUrl,
'tooltipClass': 'has-tooltip',
'userProfileUrl': `/${this.propsData.username}`,
};
Vue.nextTick(() => {
for (var computedKey in correctVals) {
const expectedVal = correctVals[computedKey];
const actualComputed = this.component[computedKey];
expect(actualComputed).toBe(expectedVal);
}
done();
});
});
});
}); });
describe('Interaction', function() { describe('Interaction', function() {
click link and handler fires it('should remove approval', function() {
});
it('should give approval', function() {
});
// click link and handler fires
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment