2025-10-03 16:51:44 +02:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
|
import SocialBadge from './SocialButton.vue';
|
|
|
|
|
|
|
|
|
|
function mockIconComponent(name: string) {
|
|
|
|
|
return {
|
|
|
|
|
__esModule: true,
|
|
|
|
|
default: defineComponent({
|
2025-09-23 14:18:04 +02:00
|
|
|
name,
|
|
|
|
|
template: `<svg class='${name.toLowerCase()}'></svg>`,
|
2025-10-03 16:51:44 +02:00
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-09-23 14:18:04 +02:00
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
vi.mock('@/components/icons/IconDiscord.vue', () => mockIconComponent('IconDiscord'));
|
|
|
|
|
vi.mock('@/components/icons/IconTwitter.vue', () => mockIconComponent('IconTwitter'));
|
|
|
|
|
vi.mock('@/components/icons/IconTelegram.vue', () => mockIconComponent('IconTelegram'));
|
2025-09-23 14:18:04 +02:00
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
describe('SocialBadge.vue', () => {
|
2025-09-23 14:18:04 +02:00
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
wrapper = null;
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
it('renders the correct link', () => {
|
2025-09-23 14:18:04 +02:00
|
|
|
wrapper = mount(SocialBadge, {
|
|
|
|
|
props: {
|
2025-10-03 16:51:44 +02:00
|
|
|
href: 'https://example.com',
|
2025-09-23 14:18:04 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
const link = wrapper.find('a');
|
2025-09-23 14:18:04 +02:00
|
|
|
expect(link.exists()).toBe(true);
|
2025-10-03 16:51:44 +02:00
|
|
|
expect(link.attributes('href')).toBe('https://example.com');
|
|
|
|
|
expect(link.attributes('target')).toBe('_blank');
|
2025-09-23 14:18:04 +02:00
|
|
|
});
|
|
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
it('applies the correct color for light mode', () => {
|
2025-09-23 14:18:04 +02:00
|
|
|
wrapper = mount(SocialBadge, {
|
|
|
|
|
props: {
|
|
|
|
|
dark: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
const badge = wrapper.find('.social-badge');
|
|
|
|
|
expect(badge.attributes('style')).toContain('color: black');
|
|
|
|
|
expect(badge.attributes('style')).toContain('border-color: black');
|
2025-09-23 14:18:04 +02:00
|
|
|
});
|
|
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
it('applies the correct color for dark mode', () => {
|
2025-09-23 14:18:04 +02:00
|
|
|
wrapper = mount(SocialBadge, {
|
|
|
|
|
props: {
|
|
|
|
|
dark: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
const badge = wrapper.find('.social-badge');
|
|
|
|
|
expect(badge.attributes('style')).toContain('color: white');
|
|
|
|
|
expect(badge.attributes('style')).toContain('border-color: white');
|
2025-09-23 14:18:04 +02:00
|
|
|
});
|
|
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
it('does not render an icon if the type is unsupported', async () => {
|
2025-09-23 14:18:04 +02:00
|
|
|
wrapper = mount(SocialBadge, {
|
|
|
|
|
props: {
|
2025-10-03 16:51:44 +02:00
|
|
|
type: 'unsupported',
|
2025-09-23 14:18:04 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
const icon = wrapper.find('.social-badge-icon').find('component');
|
2025-09-23 14:18:04 +02:00
|
|
|
expect(icon.exists()).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-03 16:51:44 +02:00
|
|
|
it('renders without crashing when no props are provided', () => {
|
2025-09-23 14:18:04 +02:00
|
|
|
wrapper = mount(SocialBadge);
|
2025-10-03 16:51:44 +02:00
|
|
|
|
2025-09-23 14:18:04 +02:00
|
|
|
expect(wrapper.exists()).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|