Commit 43697a6c authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'polish-user-popover' into 'master'

Hide status div when there is no user status

See merge request gitlab-org/gitlab!19938
parents 8a3410c2 6037c62d
...@@ -30,11 +30,16 @@ export default { ...@@ -30,11 +30,16 @@ export default {
}, },
computed: { computed: {
statusHtml() { statusHtml() {
if (!this.user.status) {
return '';
}
if (this.user.status.emoji && this.user.status.message_html) { if (this.user.status.emoji && this.user.status.message_html) {
return `${glEmojiTag(this.user.status.emoji)} ${this.user.status.message_html}`; return `${glEmojiTag(this.user.status.emoji)} ${this.user.status.message_html}`;
} else if (this.user.status.message_html) { } else if (this.user.status.message_html) {
return this.user.status.message_html; return this.user.status.message_html;
} }
return ''; return '';
}, },
nameIsLoading() { nameIsLoading() {
...@@ -97,7 +102,9 @@ export default { ...@@ -97,7 +102,9 @@ export default {
class="animation-container-small mb-1" class="animation-container-small mb-1"
/> />
</div> </div>
<div v-if="user.status" class="mt-2"><span v-html="statusHtml"></span></div> <div v-if="statusHtml" class="js-user-status mt-2">
<span v-html="statusHtml"></span>
</div>
</div> </div>
</div> </div>
</gl-popover> </gl-popover>
......
---
title: Remove extra whitespace in user popover
merge_request: 19938
author:
type: fixed
...@@ -29,23 +29,40 @@ describe('User Popover Component', () => { ...@@ -29,23 +29,40 @@ describe('User Popover Component', () => {
wrapper.destroy(); wrapper.destroy();
}); });
const findUserStatus = () => wrapper.find('.js-user-status');
const findTarget = () => document.querySelector('.js-user-link');
const createWrapper = (props = {}, options = {}) => {
wrapper = shallowMount(UserPopover, {
propsData: {
...DEFAULT_PROPS,
target: findTarget(),
...props,
},
sync: false,
...options,
});
};
describe('Empty', () => { describe('Empty', () => {
beforeEach(() => { beforeEach(() => {
wrapper = shallowMount(UserPopover, { createWrapper(
propsData: { {},
target: document.querySelector('.js-user-link'), {
user: { propsData: {
name: null, target: findTarget(),
username: null, user: {
location: null, name: null,
bio: null, username: null,
organization: null, location: null,
status: null, bio: null,
organization: null,
status: null,
},
}, },
attachToDocument: true,
}, },
attachToDocument: true, );
sync: false,
});
}); });
it('should return skeleton loaders', () => { it('should return skeleton loaders', () => {
...@@ -55,13 +72,7 @@ describe('User Popover Component', () => { ...@@ -55,13 +72,7 @@ describe('User Popover Component', () => {
describe('basic data', () => { describe('basic data', () => {
it('should show basic fields', () => { it('should show basic fields', () => {
wrapper = shallowMount(UserPopover, { createWrapper();
propsData: {
...DEFAULT_PROPS,
target: document.querySelector('.js-user-link'),
},
sync: false,
});
expect(wrapper.text()).toContain(DEFAULT_PROPS.user.name); expect(wrapper.text()).toContain(DEFAULT_PROPS.user.name);
expect(wrapper.text()).toContain(DEFAULT_PROPS.user.username); expect(wrapper.text()).toContain(DEFAULT_PROPS.user.username);
...@@ -77,64 +88,38 @@ describe('User Popover Component', () => { ...@@ -77,64 +88,38 @@ describe('User Popover Component', () => {
describe('job data', () => { describe('job data', () => {
it('should show only bio if no organization is available', () => { it('should show only bio if no organization is available', () => {
const testProps = Object.assign({}, DEFAULT_PROPS); const user = { ...DEFAULT_PROPS.user, bio: 'Engineer' };
testProps.user.bio = 'Engineer';
wrapper = shallowMount(UserPopover, { createWrapper({ user });
propsData: {
...testProps,
target: document.querySelector('.js-user-link'),
},
sync: false,
});
expect(wrapper.text()).toContain('Engineer'); expect(wrapper.text()).toContain('Engineer');
}); });
it('should show only organization if no bio is available', () => { it('should show only organization if no bio is available', () => {
const testProps = Object.assign({}, DEFAULT_PROPS); const user = { ...DEFAULT_PROPS.user, organization: 'GitLab' };
testProps.user.organization = 'GitLab';
wrapper = shallowMount(UserPopover, { createWrapper({ user });
propsData: {
...testProps,
target: document.querySelector('.js-user-link'),
},
sync: false,
});
expect(wrapper.text()).toContain('GitLab'); expect(wrapper.text()).toContain('GitLab');
}); });
it('should display bio and organization in separate lines', () => { it('should display bio and organization in separate lines', () => {
const testProps = Object.assign({}, DEFAULT_PROPS); const user = { ...DEFAULT_PROPS.user, bio: 'Engineer', organization: 'GitLab' };
testProps.user.bio = 'Engineer';
testProps.user.organization = 'GitLab'; createWrapper({ user });
wrapper = shallowMount(UserPopover, {
propsData: {
...DEFAULT_PROPS,
target: document.querySelector('.js-user-link'),
},
sync: false,
});
expect(wrapper.find('.js-bio').text()).toContain('Engineer'); expect(wrapper.find('.js-bio').text()).toContain('Engineer');
expect(wrapper.find('.js-organization').text()).toContain('GitLab'); expect(wrapper.find('.js-organization').text()).toContain('GitLab');
}); });
it('should not encode special characters in bio and organization', () => { it('should not encode special characters in bio and organization', () => {
const testProps = Object.assign({}, DEFAULT_PROPS); const user = {
testProps.user.bio = 'Manager & Team Lead'; ...DEFAULT_PROPS.user,
testProps.user.organization = 'Me & my <funky> Company'; bio: 'Manager & Team Lead',
organization: 'Me & my <funky> Company',
wrapper = shallowMount(UserPopover, { };
propsData: {
...DEFAULT_PROPS, createWrapper({ user });
target: document.querySelector('.js-user-link'),
},
sync: false,
});
expect(wrapper.find('.js-bio').text()).toContain('Manager & Team Lead'); expect(wrapper.find('.js-bio').text()).toContain('Manager & Team Lead');
expect(wrapper.find('.js-organization').text()).toContain('Me & my <funky> Company'); expect(wrapper.find('.js-organization').text()).toContain('Me & my <funky> Company');
...@@ -153,35 +138,41 @@ describe('User Popover Component', () => { ...@@ -153,35 +138,41 @@ describe('User Popover Component', () => {
describe('status data', () => { describe('status data', () => {
it('should show only message', () => { it('should show only message', () => {
const testProps = Object.assign({}, DEFAULT_PROPS); const user = { ...DEFAULT_PROPS.user, status: { message_html: 'Hello World' } };
testProps.user.status = { message_html: 'Hello World' };
wrapper = shallowMount(UserPopover, { createWrapper({ user });
propsData: {
...DEFAULT_PROPS,
target: document.querySelector('.js-user-link'),
},
sync: false,
});
expect(findUserStatus().exists()).toBe(true);
expect(wrapper.text()).toContain('Hello World'); expect(wrapper.text()).toContain('Hello World');
}); });
it('should show message and emoji', () => { it('should show message and emoji', () => {
const testProps = Object.assign({}, DEFAULT_PROPS); const user = {
testProps.user.status = { emoji: 'basketball_player', message_html: 'Hello World' }; ...DEFAULT_PROPS.user,
status: { emoji: 'basketball_player', message_html: 'Hello World' },
wrapper = shallowMount(UserPopover, { };
propsData: {
...DEFAULT_PROPS, createWrapper({ user });
target: document.querySelector('.js-user-link'),
status: { emoji: 'basketball_player', message_html: 'Hello World' },
},
sync: false,
});
expect(findUserStatus().exists()).toBe(true);
expect(wrapper.text()).toContain('Hello World'); expect(wrapper.text()).toContain('Hello World');
expect(wrapper.html()).toContain('<gl-emoji data-name="basketball_player"'); expect(wrapper.html()).toContain('<gl-emoji data-name="basketball_player"');
}); });
it('hides the div when status is null', () => {
const user = { ...DEFAULT_PROPS.user, status: null };
createWrapper({ user });
expect(findUserStatus().exists()).toBe(false);
});
it('hides the div when status is empty', () => {
const user = { ...DEFAULT_PROPS.user, status: { emoji: '', message_html: '' } };
createWrapper({ user });
expect(findUserStatus().exists()).toBe(false);
});
}); });
}); });
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