forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralTab.test.tsx
More file actions
90 lines (76 loc) · 2.28 KB
/
Copy pathGeneralTab.test.tsx
File metadata and controls
90 lines (76 loc) · 2.28 KB
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
81
82
83
84
85
86
87
88
89
90
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import React from 'react';
import { UserProfile } from '@/types';
const mockUser: UserProfile = {
id: 'user-1234567890abcdef',
name: 'Test User',
email: 'test@txio.dev',
role: 'member',
avatar: '',
githubAccount: undefined,
notificationPreferences: {
emailNotifications: true,
executionAlerts: true,
securityAlerts: true,
marketingUpdates: false,
},
};
vi.mock('@/lib/store', () => ({
appStore: {
user: null,
updateUser: vi.fn(),
showToast: vi.fn(),
collections: [],
history: [],
customTemplates: [],
isHydrated: true,
},
useAppStore: () => ({
user: null,
updateUser: vi.fn(),
showToast: vi.fn(),
collections: [],
history: [],
customTemplates: [],
isHydrated: true,
}),
}));
vi.mock('@/services/api', () => ({
API_BASE: 'https://txio-oyac.onrender.com/api/v1',
apiService: {
updateProfile: vi.fn(),
},
}));
import { GeneralTab } from './GeneralTab';
import { API_BASE } from '@/services/api';
describe('GeneralTab GitHub connect link', () => {
const originalLocation = window.location;
beforeEach(() => {
vi.clearAllMocks();
delete (window as unknown as { location: unknown }).location;
window.location = { ...originalLocation, href: '' } as unknown as Location;
});
afterEach(() => {
window.location = originalLocation;
});
it('navigates to API_BASE/auth/github/login when Connect is clicked', () => {
render(<GeneralTab user={mockUser} onLogout={vi.fn()} />);
const connectButton = screen.getByRole('button', { name: /connect/i });
expect(connectButton).toBeInTheDocument();
fireEvent.click(connectButton);
expect(window.location.href).toBe(`${API_BASE}/auth/github/login`);
});
it('does not show Connect button when githubAccount is already linked', () => {
const userWithGithub: UserProfile = {
...mockUser,
githubAccount: {
id: 'gh-123',
login: 'octocat',
},
};
render(<GeneralTab user={userWithGithub} onLogout={vi.fn()} />);
expect(screen.queryByRole('button', { name: /connect/i })).toBeNull();
expect(screen.getByText('@octocat')).toBeInTheDocument();
});
});