2020-07-28 23:09:34 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import MrWidgetAuthor from '~/vue_merge_request_widget/components/mr_widget_author.vue';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
window.gl = window.gl || {};
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('MrWidgetAuthor', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
let wrapper;
|
|
|
|
let oldWindowGl;
|
|
|
|
const mockAuthor = {
|
|
|
|
name: 'Administrator',
|
|
|
|
username: 'root',
|
|
|
|
webUrl: 'http://localhost:3000/root',
|
|
|
|
avatarUrl: 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-07-28 23:09:34 +05:30
|
|
|
oldWindowGl = window.gl;
|
|
|
|
window.gl = {
|
|
|
|
mrWidgetData: {
|
|
|
|
defaultAvatarUrl: 'no_avatar.png',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
wrapper = shallowMount(MrWidgetAuthor, {
|
|
|
|
propsData: {
|
|
|
|
author: mockAuthor,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
afterEach(() => {
|
2020-07-28 23:09:34 +05:30
|
|
|
wrapper.destroy();
|
|
|
|
window.gl = oldWindowGl;
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('renders link with the author web url', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(wrapper.attributes('href')).toBe('http://localhost:3000/root');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders image with avatar url', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(wrapper.find('img').attributes('src')).toBe(
|
2018-12-13 13:39:08 +05:30
|
|
|
'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('renders image with default avatar url when no avatarUrl is present in author', async () => {
|
|
|
|
wrapper.setProps({
|
|
|
|
author: {
|
|
|
|
...mockAuthor,
|
|
|
|
avatarUrl: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(wrapper.find('img').attributes('src')).toBe('no_avatar.png');
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('renders author name', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(wrapper.find('span').text()).toBe('Administrator');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|