Commit ce155692 authored by Bryce Johnson's avatar Bryce Johnson

Refactor link_to_member_avatar spec and get passing.

parent 3e5aab5d
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
showTooltip: { showTooltip: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: true,
}, },
clickable: { clickable: {
type: Boolean, type: Boolean,
...@@ -46,10 +46,10 @@ ...@@ -46,10 +46,10 @@
type: String, type: String,
required: false, required: false,
}, },
size: { avatarSize: {
type: Number, type: Number,
required: false, required: false,
default: 32, default: 32
}, },
}, },
data() { data() {
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
}, },
computed: { computed: {
avatarSizeClass() { avatarSizeClass() {
return `s${this.size}`; return `s${this.avatarSize}`;
}, },
avatarHtmlClass() { avatarHtmlClass() {
return `${this.avatarSizeClass} ${this.avatarBaseClass}`; return `${this.avatarSizeClass} ${this.avatarBaseClass}`;
...@@ -83,8 +83,8 @@ ...@@ -83,8 +83,8 @@
template: ` template: `
<div class='link-to-member-avatar'> <div class='link-to-member-avatar'>
<a :href='profileUrl' :class='linkClass' :data-original-title='displayName' :data-container='tooltipContainerAttr'> <a :href='profileUrl' :class='linkClass' :data-original-title='displayName' :data-container='tooltipContainerAttr'>
<svg v-if='avatarHtml' v-html='avatarHtml' :class='avatarHtmlClass' :width='size' :height='size' :alt='displayName'></svg> <svg v-if='avatarHtml' v-html='avatarHtml' :class='avatarHtmlClass' :width='avatarSize' :height='avatarSize' :alt='displayName'></svg>
<img :class='avatarClass' :src='avatarUrl' :width='size' :height='size' :alt='displayName'/> <img :class='avatarClass' :src='avatarUrl' :width='avatarSize' :height='avatarSize' :alt='displayName'/>
</a> </a>
</div> </div>
`, `,
......
/* eslint-disable */ /* eslint-disable */
//= require vue
//= require jquery //= require jquery
//= require vue_common_component/link_to_member_avatar //= require vue_common_component/link_to_member_avatar
...@@ -21,80 +22,51 @@ ...@@ -21,80 +22,51 @@
} }
describe('Link To Members Components', function() { describe('Link To Members Components', function() {
describe('Initialization', function() { describe('Initialization', function() {
describe('No configuration (defaults)', function() { beforeEach(function() {
beforeEach(function() {
initComponent.call(this, { nonUser: true });
});
it('should return a defined Vue component', function() {
expect(this.component).toBeDefined();
expect(this.component.$data).toBeDefined();
});
it('should have <a> and <img> children', function() {
const componentLink = this.component.$el;
const componentLinkTagname = componentLink.tagName;
const componentImg = componentLink.childNodes[0];
const componentImgTagname = componentImg.tagName;
expect(componentLink).toBeDefined();
expect(componentLinkTagname).toBe('A');
expect(componentImg).toBeDefined();
expect(componentImgTagname).toBe('IMG');
});
it('should correctly compute computed values', function() {
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 = { const propsData = this.propsData = {
avatarSize: 32,
avatarUrl: 'myavatarurl.com', avatarUrl: 'myavatarurl.com',
username: 'myusername',
displayName: 'mydisplayname', displayName: 'mydisplayname',
extraAvatarClass: 'myextraavatarclass', extraAvatarClass: 'myextraavatarclass',
extraLinkClass: 'myextralinkclass', extraLinkClass: 'myextralinkclass',
showTooltip: true, showTooltip: true,
size: 32,
nonUser: false
}; };
initComponent.call(this, { initComponent.call(this, {
propsData propsData
}); });
}); });
it('should correctly compute computed values', function(done) { it('should return a defined Vue component', function() {
const correctVals = { expect(this.component).toBeDefined();
'disabledClass': '', expect(this.component.$data).toBeDefined();
'avatarClass': 'avatar avatar-inline s48 ', });
'preppedAvatarUrl': this.propsData.avatarUrl,
'tooltipClass': 'has-tooltip', it('should have <a> and <img> children', function() {
'userProfileUrl': `/${this.propsData.username}`, const componentLink = this.component.$el.querySelector('a');
}; const componentImg = componentLink.querySelector('img');
Vue.nextTick(() => {
for (var computedKey in correctVals) { expect(componentLink).not.toBeNull();
const expectedVal = correctVals[computedKey]; expect(componentImg).not.toBeNull();
const actualComputed = this.component[computedKey]; });
expect(actualComputed).toBe(expectedVal);
} it('should correctly compute computed values', function(done) {
done(); const correctVals = {
}); 'disabledClass': '',
'avatarSizeClass': 's32',
'avatarHtmlClass': 's32 avatar avatar-inline',
'avatarClass': 'avatar avatar-inline s32 ',
'tooltipClass': 'has-tooltip',
'linkClass': 'author_link has-tooltip ',
'tooltipContainerAttr': 'body',
};
Vue.nextTick(() => {
for (var computedKey in correctVals) {
const expectedVal = correctVals[computedKey];
const actualComputed = this.component[computedKey];
expect(actualComputed).toBe(expectedVal);
}
done();
}); });
}); });
}); });
......
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