-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathgetSocialPlatformDetails.test.tsx
80 lines (67 loc) · 2.47 KB
/
getSocialPlatformDetails.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import {
GetSocialPlatformDetails,
PLATFORM_CONFIG,
type SocialPlatform,
} from './getSocialPlatformDetails';
describe('PLATFORM_CONFIG', () => {
it('should generate correct Twitter URL', () => {
const url = PLATFORM_CONFIG.twitter.href('username');
expect(url).toBe('https://x.com/username');
});
it('should generate correct GitHub URL', () => {
const url = PLATFORM_CONFIG.github.href('username');
expect(url).toBe('https://github.com/username');
});
it('should generate correct Farcaster URL', () => {
const url = PLATFORM_CONFIG.farcaster.href('username');
expect(url).toBe('https://warpcast.com/username');
});
it('should return website URL as-is', () => {
const url = PLATFORM_CONFIG.website.href('https://example.com');
expect(url).toBe('https://example.com');
});
it('should have an icon for each platform', () => {
const platforms: SocialPlatform[] = [
'twitter',
'github',
'farcaster',
'website',
];
for (const platform of platforms) {
expect(PLATFORM_CONFIG[platform].icon).toBeDefined();
}
});
});
describe('GetSocialPlatformDetails', () => {
const platforms: SocialPlatform[] = [
'twitter',
'github',
'farcaster',
'website',
];
for (const platform of platforms) {
it(`should render ${platform} link correctly`, () => {
const value = platform === 'website' ? 'https://example.com' : 'username';
render(<GetSocialPlatformDetails platform={platform} value={value} />);
const link = screen.getByRole('link');
expect(link).toHaveAttribute(
'href',
PLATFORM_CONFIG[platform].href(value),
);
expect(link).toHaveAttribute('target', '_blank');
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
expect(screen.getByText(platform)).toHaveClass('sr-only');
const expectedTestId = `ockSocials_${platform.charAt(0).toUpperCase() + platform.slice(1)}`;
expect(link).toHaveAttribute('data-testid', expectedTestId);
const iconContainer = link.querySelector('.flex.h-4.w-4');
expect(iconContainer).toBeInTheDocument();
});
}
it('should apply correct CSS classes', () => {
render(<GetSocialPlatformDetails platform="twitter" value="username" />);
const link = screen.getByRole('link');
expect(link.className).toContain('flex items-center justify-center p-2');
});
});