Files
api/web/__test__/components/Activation/ActivationPartnerLogo.test.ts
T
Michael Datelle a5f48da322 test: create tests for components batch 3 (#1374)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added comprehensive unit tests for components including SsoButton,
ThemeSwitcher, UpdateOs, UserProfile, WanIpCheck, WelcomeModal,
ActivationModal, ActivationPartnerLogo, ActivationPartnerLogoImg, and
ActivationSteps.
- **Tests**
- Enhanced existing test suites for ColorSwitcher, DummyServerSwitcher,
and I18nHost to improve test isolation, DOM management, and reliability.
- **Style**
- Made minor typographic correction in ActivationModal description text.
- **Refactor**
- Reorganized import statements in several components for improved code
clarity.
- **Chores**
- Added necessary imports in multiple components to support Vue
Composition API features.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: mdatelle <mike@datelle.net>
2025-05-07 16:21:45 -04:00

82 lines
2.3 KiB
TypeScript

/**
* ActivationPartnerLogo Component Test Coverage
*/
import { ref } from 'vue';
import { mount } from '@vue/test-utils';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import ActivationPartnerLogo from '~/components/Activation/ActivationPartnerLogo.vue';
const mockActivationPartnerLogoImg = {
template: '<div data-testid="partner-logo-img"></div>',
};
const mockActivationCodeDataStore = {
partnerInfo: ref({
partnerUrl: null as string | null,
}),
};
vi.mock('~/components/Activation/store/activationCodeData', () => ({
useActivationCodeDataStore: () => mockActivationCodeDataStore,
}));
describe('ActivationPartnerLogo', () => {
beforeEach(() => {
vi.clearAllMocks();
mockActivationCodeDataStore.partnerInfo.value = {
partnerUrl: null,
};
});
const mountComponent = () => {
return mount(ActivationPartnerLogo, {
global: {
stubs: {
ActivationPartnerLogoImg: mockActivationPartnerLogoImg,
},
},
});
};
it('renders a link with partner logo when partnerUrl exists', () => {
mockActivationCodeDataStore.partnerInfo.value = {
partnerUrl: 'https://example.com',
};
const wrapper = mountComponent();
const link = wrapper.find('a');
const logoImg = wrapper.find('[data-testid="partner-logo-img"]');
expect(link.exists()).toBe(true);
expect(link.attributes('href')).toBe('https://example.com');
expect(link.attributes('target')).toBe('_blank');
expect(link.attributes('rel')).toBe('noopener noreferrer');
expect(logoImg.exists()).toBe(true);
});
it('does not render anything when no partnerUrl exists', () => {
const wrapper = mountComponent();
const link = wrapper.find('a');
const logoImg = wrapper.find('[data-testid="partner-logo-img"]');
expect(link.exists()).toBe(false);
expect(logoImg.exists()).toBe(false);
});
it('applies correct opacity classes for hover and focus states', () => {
mockActivationCodeDataStore.partnerInfo.value = {
partnerUrl: 'https://example.com',
};
const wrapper = mountComponent();
const link = wrapper.find('a');
expect(link.classes()).toContain('opacity-100');
expect(link.classes()).toContain('hover:opacity-75');
expect(link.classes()).toContain('focus:opacity-75');
});
});