Commit c66555e9 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Add unit tests

parent 13113ca4
...@@ -109,19 +109,33 @@ describe('User Avatar Image Component', () => { ...@@ -109,19 +109,33 @@ describe('User Avatar Image Component', () => {
default: ['Action!'], default: ['Action!'],
}; };
describe('when `tooltipText` is provided and no default slot', () => {
beforeEach(() => { beforeEach(() => {
wrapper = shallowMount(UserAvatarImage, { wrapper = shallowMount(UserAvatarImage, {
propsData: PROVIDED_PROPS, propsData: { ...PROVIDED_PROPS },
});
});
it('renders the tooltip with `tooltipText` as content', () => {
expect(wrapper.findComponent(GlTooltip).text()).toBe(PROVIDED_PROPS.tooltipText);
});
});
describe('when `tooltipText` and default slot is provided', () => {
beforeEach(() => {
wrapper = shallowMount(UserAvatarImage, {
propsData: { ...PROVIDED_PROPS },
slots, slots,
}); });
}); });
it('renders the tooltip slot', () => { it('does not render `tooltipText` inside the tooltip', () => {
expect(wrapper.findComponent(GlTooltip).exists()).toBe(true); expect(wrapper.findComponent(GlTooltip).text()).not.toBe(PROVIDED_PROPS.tooltipText);
}); });
it('renders the tooltip content', () => { it('renders the content provided via default slot', () => {
expect(wrapper.findComponent(GlTooltip).text()).toContain(slots.default[0]); expect(wrapper.findComponent(GlTooltip).text()).toContain(slots.default[0]);
}); });
}); });
});
}); });
...@@ -90,33 +90,38 @@ describe('User Avatar Image Component', () => { ...@@ -90,33 +90,38 @@ describe('User Avatar Image Component', () => {
}); });
}); });
describe('dynamic tooltip content', () => { describe('Dynamic tooltip content', () => {
const props = PROVIDED_PROPS;
const slots = { const slots = {
default: ['Action!'], default: ['Action!'],
}; };
describe('when `tooltipText` is provided and no default slot', () => {
beforeEach(() => { beforeEach(() => {
wrapper = shallowMount(UserAvatarImage, { wrapper = shallowMount(UserAvatarImage, {
propsData: { props }, propsData: { ...PROVIDED_PROPS },
slots,
}); });
}); });
it('renders the tooltip slot', () => { it('renders the tooltip with `tooltipText` as content', () => {
expect(wrapper.findComponent(GlTooltip).exists()).toBe(true); expect(wrapper.findComponent(GlTooltip).text()).toBe(PROVIDED_PROPS.tooltipText);
});
}); });
it('renders the tooltip content', () => { describe('when `tooltipText` and default slot is provided', () => {
expect(wrapper.findComponent(GlTooltip).text()).toContain(slots.default[0]); beforeEach(() => {
wrapper = shallowMount(UserAvatarImage, {
propsData: { ...PROVIDED_PROPS },
slots,
});
}); });
it('does not render tooltip data attributes on avatar image', () => { it('does not render `tooltipText` inside the tooltip', () => {
const avatarImg = wrapper.find('img'); expect(wrapper.findComponent(GlTooltip).text()).not.toBe(PROVIDED_PROPS.tooltipText);
});
expect(avatarImg.attributes('title')).toBeFalsy(); it('renders the content provided via default slot', () => {
expect(avatarImg.attributes('data-placement')).not.toBeDefined(); expect(wrapper.findComponent(GlTooltip).text()).toContain(slots.default[0]);
expect(avatarImg.attributes('data-container')).not.toBeDefined(); });
}); });
}); });
}); });
...@@ -153,4 +153,29 @@ describe('UserAvatarList', () => { ...@@ -153,4 +153,29 @@ describe('UserAvatarList', () => {
}); });
}); });
}); });
describe('additional styling for the image', () => {
it('should not add CSS class when feature flag `glAvatarForAllUserAvatars` is disabled', () => {
factory({
propsData: { items: createList(1) },
});
const link = wrapper.findComponent(UserAvatarLink);
expect(link.props('imgCssClasses')).not.toBe('gl-mr-3');
});
it('should add CSS class when feature flag `glAvatarForAllUserAvatars` is enabled', () => {
factory({
propsData: { items: createList(1) },
provide: {
glFeatures: {
glAvatarForAllUserAvatars: true,
},
},
});
const link = wrapper.findComponent(UserAvatarLink);
expect(link.props('imgCssClasses')).toBe('gl-mr-3');
});
});
}); });
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