@moontra/moonui-pro 2.20.1 → 2.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +691 -261
- package/dist/index.mjs +7418 -4934
- package/package.json +4 -3
- package/scripts/postbuild.js +27 -0
- package/src/components/advanced-chart/index.tsx +5 -1
- package/src/components/advanced-forms/index.tsx +175 -16
- package/src/components/calendar/event-dialog.tsx +18 -13
- package/src/components/calendar/index.tsx +197 -50
- package/src/components/dashboard/dashboard-grid.tsx +21 -3
- package/src/components/dashboard/types.ts +3 -0
- package/src/components/dashboard/widgets/activity-feed.tsx +6 -1
- package/src/components/dashboard/widgets/comparison-widget.tsx +177 -0
- package/src/components/dashboard/widgets/index.ts +5 -0
- package/src/components/dashboard/widgets/metric-card.tsx +21 -1
- package/src/components/dashboard/widgets/progress-widget.tsx +113 -0
- package/src/components/error-boundary/index.tsx +160 -37
- package/src/components/form-wizard/form-wizard-context.tsx +54 -26
- package/src/components/form-wizard/form-wizard-progress.tsx +33 -2
- package/src/components/form-wizard/types.ts +2 -1
- package/src/components/github-stars/hooks.ts +1 -0
- package/src/components/github-stars/variants.tsx +3 -1
- package/src/components/health-check/index.tsx +14 -14
- package/src/components/hover-card-3d/index.tsx +2 -3
- package/src/components/index.ts +5 -3
- package/src/components/kanban/kanban.tsx +23 -18
- package/src/components/license-error/index.tsx +2 -0
- package/src/components/magnetic-button/index.tsx +56 -7
- package/src/components/memory-efficient-data/index.tsx +117 -115
- package/src/components/navbar/index.tsx +781 -0
- package/src/components/performance-debugger/index.tsx +62 -38
- package/src/components/performance-monitor/index.tsx +47 -33
- package/src/components/phone-number-input/index.tsx +32 -27
- package/src/components/phone-number-input/phone-number-input-simple.tsx +167 -0
- package/src/components/rich-text-editor/index.tsx +26 -28
- package/src/components/rich-text-editor/slash-commands-extension.ts +15 -5
- package/src/components/sidebar/index.tsx +32 -13
- package/src/components/timeline/index.tsx +84 -49
- package/src/components/ui/accordion.tsx +550 -42
- package/src/components/ui/avatar.tsx +2 -0
- package/src/components/ui/badge.tsx +2 -0
- package/src/components/ui/breadcrumb.tsx +2 -0
- package/src/components/ui/button.tsx +39 -33
- package/src/components/ui/card.tsx +2 -0
- package/src/components/ui/collapsible.tsx +546 -50
- package/src/components/ui/command.tsx +790 -67
- package/src/components/ui/dialog.tsx +510 -92
- package/src/components/ui/dropdown-menu.tsx +540 -52
- package/src/components/ui/index.ts +37 -5
- package/src/components/ui/input.tsx +2 -0
- package/src/components/ui/magnetic-button.tsx +1 -1
- package/src/components/ui/media-gallery.tsx +1 -2
- package/src/components/ui/navigation-menu.tsx +130 -0
- package/src/components/ui/pagination.tsx +2 -0
- package/src/components/ui/select.tsx +6 -2
- package/src/components/ui/spotlight-card.tsx +1 -1
- package/src/components/ui/table.tsx +2 -0
- package/src/components/ui/tabs-pro.tsx +542 -0
- package/src/components/ui/tabs.tsx +23 -167
- package/src/components/ui/toggle.tsx +12 -12
- package/src/index.ts +11 -3
- package/src/styles/index.css +596 -0
- package/src/use-performance-optimizer.ts +1 -1
- package/src/utils/chart-helpers.ts +1 -1
- package/src/__tests__/use-intersection-observer.test.tsx +0 -216
- package/src/__tests__/use-local-storage.test.tsx +0 -174
- package/src/__tests__/use-pro-access.test.tsx +0 -183
- package/src/components/advanced-chart/advanced-chart.test.tsx +0 -281
- package/src/components/data-table/data-table.test.tsx +0 -187
- package/src/components/enhanced/badge.tsx +0 -191
- package/src/components/enhanced/button.tsx +0 -362
- package/src/components/enhanced/card.tsx +0 -266
- package/src/components/enhanced/dialog.tsx +0 -246
- package/src/components/enhanced/index.ts +0 -4
- package/src/components/file-upload/file-upload.test.tsx +0 -243
- package/src/components/rich-text-editor/index-old-backup.tsx +0 -437
- package/src/types/moonui.d.ts +0 -22
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { renderHook, act } from '@testing-library/react';
|
|
2
|
-
import { useIntersectionObserver } from '../use-intersection-observer';
|
|
3
|
-
|
|
4
|
-
// Mock IntersectionObserver
|
|
5
|
-
const mockIntersectionObserver = jest.fn();
|
|
6
|
-
mockIntersectionObserver.mockImplementation((callback, options) => {
|
|
7
|
-
return {
|
|
8
|
-
observe: jest.fn(),
|
|
9
|
-
unobserve: jest.fn(),
|
|
10
|
-
disconnect: jest.fn(),
|
|
11
|
-
};
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
beforeAll(() => {
|
|
15
|
-
global.IntersectionObserver = mockIntersectionObserver;
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('useIntersectionObserver', () => {
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
jest.clearAllMocks();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should return ref and isIntersecting state', () => {
|
|
24
|
-
const { result } = renderHook(() => useIntersectionObserver());
|
|
25
|
-
|
|
26
|
-
expect(result.current.ref).toBeDefined();
|
|
27
|
-
expect(result.current.isIntersecting).toBe(false);
|
|
28
|
-
expect(typeof result.current.ref).toBe('function');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should create IntersectionObserver with default options', () => {
|
|
32
|
-
renderHook(() => useIntersectionObserver());
|
|
33
|
-
|
|
34
|
-
expect(mockIntersectionObserver).toHaveBeenCalledWith(
|
|
35
|
-
expect.any(Function),
|
|
36
|
-
{
|
|
37
|
-
threshold: 0,
|
|
38
|
-
root: null,
|
|
39
|
-
rootMargin: '0%',
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should create IntersectionObserver with custom options', () => {
|
|
45
|
-
const options = {
|
|
46
|
-
threshold: 0.5,
|
|
47
|
-
root: document.body,
|
|
48
|
-
rootMargin: '10px',
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
renderHook(() => useIntersectionObserver(options));
|
|
52
|
-
|
|
53
|
-
expect(mockIntersectionObserver).toHaveBeenCalledWith(
|
|
54
|
-
expect.any(Function),
|
|
55
|
-
options
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should observe element when ref is set', () => {
|
|
60
|
-
const mockObserve = jest.fn();
|
|
61
|
-
mockIntersectionObserver.mockImplementation(() => ({
|
|
62
|
-
observe: mockObserve,
|
|
63
|
-
unobserve: jest.fn(),
|
|
64
|
-
disconnect: jest.fn(),
|
|
65
|
-
}));
|
|
66
|
-
|
|
67
|
-
const { result } = renderHook(() => useIntersectionObserver());
|
|
68
|
-
|
|
69
|
-
const mockElement = document.createElement('div');
|
|
70
|
-
|
|
71
|
-
act(() => {
|
|
72
|
-
result.current.ref(mockElement);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
expect(mockObserve).toHaveBeenCalledWith(mockElement);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should call onChange when intersection state changes', () => {
|
|
79
|
-
const mockOnChange = jest.fn();
|
|
80
|
-
let observerCallback: any;
|
|
81
|
-
|
|
82
|
-
mockIntersectionObserver.mockImplementation((callback) => {
|
|
83
|
-
observerCallback = callback;
|
|
84
|
-
return {
|
|
85
|
-
observe: jest.fn(),
|
|
86
|
-
unobserve: jest.fn(),
|
|
87
|
-
disconnect: jest.fn(),
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const { result } = renderHook(() =>
|
|
92
|
-
useIntersectionObserver({ onChange: mockOnChange })
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const mockElement = document.createElement('div');
|
|
96
|
-
const mockEntry = {
|
|
97
|
-
isIntersecting: true,
|
|
98
|
-
target: mockElement,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
act(() => {
|
|
102
|
-
result.current.ref(mockElement);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
act(() => {
|
|
106
|
-
observerCallback([mockEntry]);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
expect(mockOnChange).toHaveBeenCalledWith(true, mockEntry);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should freeze state when freezeOnceVisible is true', () => {
|
|
113
|
-
let observerCallback: any;
|
|
114
|
-
|
|
115
|
-
mockIntersectionObserver.mockImplementation((callback) => {
|
|
116
|
-
observerCallback = callback;
|
|
117
|
-
return {
|
|
118
|
-
observe: jest.fn(),
|
|
119
|
-
unobserve: jest.fn(),
|
|
120
|
-
disconnect: jest.fn(),
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
const { result } = renderHook(() =>
|
|
125
|
-
useIntersectionObserver({ freezeOnceVisible: true })
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
const mockElement = document.createElement('div');
|
|
129
|
-
const mockEntry = {
|
|
130
|
-
isIntersecting: true,
|
|
131
|
-
target: mockElement,
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
act(() => {
|
|
135
|
-
result.current.ref(mockElement);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// First intersection - should update
|
|
139
|
-
act(() => {
|
|
140
|
-
observerCallback([mockEntry]);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
expect(result.current.isIntersecting).toBe(true);
|
|
144
|
-
|
|
145
|
-
// Second intersection with false - should not update (frozen)
|
|
146
|
-
act(() => {
|
|
147
|
-
observerCallback([{ ...mockEntry, isIntersecting: false }]);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
expect(result.current.isIntersecting).toBe(true);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('should disconnect observer on unmount', () => {
|
|
154
|
-
const mockDisconnect = jest.fn();
|
|
155
|
-
mockIntersectionObserver.mockImplementation(() => ({
|
|
156
|
-
observe: jest.fn(),
|
|
157
|
-
unobserve: jest.fn(),
|
|
158
|
-
disconnect: mockDisconnect,
|
|
159
|
-
}));
|
|
160
|
-
|
|
161
|
-
const { unmount } = renderHook(() => useIntersectionObserver());
|
|
162
|
-
|
|
163
|
-
unmount();
|
|
164
|
-
|
|
165
|
-
expect(mockDisconnect).toHaveBeenCalled();
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('should handle initialIsIntersecting option', () => {
|
|
169
|
-
const { result } = renderHook(() =>
|
|
170
|
-
useIntersectionObserver({ initialIsIntersecting: true })
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
expect(result.current.isIntersecting).toBe(true);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('should not create observer when IntersectionObserver is not supported', () => {
|
|
177
|
-
// Temporarily remove IntersectionObserver
|
|
178
|
-
const originalIntersectionObserver = global.IntersectionObserver;
|
|
179
|
-
(global as any).IntersectionObserver = undefined;
|
|
180
|
-
|
|
181
|
-
const { result } = renderHook(() => useIntersectionObserver());
|
|
182
|
-
|
|
183
|
-
expect(result.current.ref).toBeDefined();
|
|
184
|
-
expect(result.current.isIntersecting).toBe(false);
|
|
185
|
-
|
|
186
|
-
// Restore IntersectionObserver
|
|
187
|
-
global.IntersectionObserver = originalIntersectionObserver;
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('should handle multiple elements with useMultipleIntersectionObserver', () => {
|
|
191
|
-
// This would be a separate hook, but we can test the concept
|
|
192
|
-
const mockObserve = jest.fn();
|
|
193
|
-
const mockUnobserve = jest.fn();
|
|
194
|
-
|
|
195
|
-
mockIntersectionObserver.mockImplementation(() => ({
|
|
196
|
-
observe: mockObserve,
|
|
197
|
-
unobserve: mockUnobserve,
|
|
198
|
-
disconnect: jest.fn(),
|
|
199
|
-
}));
|
|
200
|
-
|
|
201
|
-
const { result } = renderHook(() => useIntersectionObserver());
|
|
202
|
-
|
|
203
|
-
const element1 = document.createElement('div');
|
|
204
|
-
const element2 = document.createElement('div');
|
|
205
|
-
|
|
206
|
-
act(() => {
|
|
207
|
-
result.current.ref(element1);
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
act(() => {
|
|
211
|
-
result.current.ref(element2);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
expect(mockObserve).toHaveBeenCalledWith(element2);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { renderHook, act } from '@testing-library/react'
|
|
2
|
-
import { useLocalStorage } from '../use-local-storage'
|
|
3
|
-
|
|
4
|
-
// Mock localStorage
|
|
5
|
-
const mockLocalStorage = (() => {
|
|
6
|
-
let store: Record<string, string> = {}
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
getItem: jest.fn((key: string) => store[key] || null),
|
|
10
|
-
setItem: jest.fn((key: string, value: string) => {
|
|
11
|
-
store[key] = value
|
|
12
|
-
}),
|
|
13
|
-
removeItem: jest.fn((key: string) => {
|
|
14
|
-
delete store[key]
|
|
15
|
-
}),
|
|
16
|
-
clear: jest.fn(() => {
|
|
17
|
-
store = {}
|
|
18
|
-
}),
|
|
19
|
-
get length() {
|
|
20
|
-
return Object.keys(store).length
|
|
21
|
-
},
|
|
22
|
-
key: jest.fn((index: number) => Object.keys(store)[index] || null),
|
|
23
|
-
}
|
|
24
|
-
})()
|
|
25
|
-
|
|
26
|
-
Object.defineProperty(window, 'localStorage', {
|
|
27
|
-
value: mockLocalStorage,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
describe('useLocalStorage', () => {
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
mockLocalStorage.clear()
|
|
33
|
-
jest.clearAllMocks()
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('returns initial value when localStorage is empty', () => {
|
|
37
|
-
const { result } = renderHook(() => useLocalStorage('test-key', 'initial'))
|
|
38
|
-
|
|
39
|
-
expect(result.current[0]).toBe('initial')
|
|
40
|
-
expect(mockLocalStorage.getItem).toHaveBeenCalledWith('test-key')
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('returns stored value from localStorage', () => {
|
|
44
|
-
mockLocalStorage.setItem('test-key', JSON.stringify('stored-value'))
|
|
45
|
-
|
|
46
|
-
const { result } = renderHook(() => useLocalStorage('test-key', 'initial'))
|
|
47
|
-
|
|
48
|
-
expect(result.current[0]).toBe('stored-value')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('stores value in localStorage when setValue is called', () => {
|
|
52
|
-
const { result } = renderHook(() => useLocalStorage('test-key', 'initial'))
|
|
53
|
-
|
|
54
|
-
act(() => {
|
|
55
|
-
result.current[1]('new-value')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
expect(result.current[0]).toBe('new-value')
|
|
59
|
-
expect(mockLocalStorage.setItem).toHaveBeenCalledWith('test-key', JSON.stringify('new-value'))
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('handles function updates', () => {
|
|
63
|
-
const { result } = renderHook(() => useLocalStorage('test-key', 10))
|
|
64
|
-
|
|
65
|
-
act(() => {
|
|
66
|
-
result.current[1]((prev) => (prev ?? 0) + 5)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
expect(result.current[0]).toBe(15)
|
|
70
|
-
expect(mockLocalStorage.setItem).toHaveBeenCalledWith('test-key', JSON.stringify(15))
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('handles complex objects', () => {
|
|
74
|
-
const initialObject = { name: 'test', count: 0 }
|
|
75
|
-
const { result } = renderHook(() => useLocalStorage('object-key', initialObject))
|
|
76
|
-
|
|
77
|
-
const newObject = { name: 'updated', count: 5 }
|
|
78
|
-
|
|
79
|
-
act(() => {
|
|
80
|
-
result.current[1](newObject)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
expect(result.current[0]).toEqual(newObject)
|
|
84
|
-
expect(mockLocalStorage.setItem).toHaveBeenCalledWith('object-key', JSON.stringify(newObject))
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('handles localStorage errors gracefully', () => {
|
|
88
|
-
mockLocalStorage.setItem.mockImplementation(() => {
|
|
89
|
-
throw new Error('Storage quota exceeded')
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
const consoleSpy = jest.spyOn(console, 'error').mockImplementation()
|
|
93
|
-
|
|
94
|
-
const { result } = renderHook(() => useLocalStorage('test-key', 'initial'))
|
|
95
|
-
|
|
96
|
-
act(() => {
|
|
97
|
-
result.current[1]('new-value')
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
// Should still update the state even if localStorage fails
|
|
101
|
-
expect(result.current[0]).toBe('new-value')
|
|
102
|
-
expect(consoleSpy).toHaveBeenCalled()
|
|
103
|
-
|
|
104
|
-
consoleSpy.mockRestore()
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('handles malformed JSON in localStorage', () => {
|
|
108
|
-
mockLocalStorage.getItem.mockReturnValue('invalid-json{')
|
|
109
|
-
|
|
110
|
-
const consoleSpy = jest.spyOn(console, 'error').mockImplementation()
|
|
111
|
-
|
|
112
|
-
const { result } = renderHook(() => useLocalStorage('test-key', 'initial'))
|
|
113
|
-
|
|
114
|
-
// Should fall back to initial value when JSON parsing fails
|
|
115
|
-
expect(result.current[0]).toBe('initial')
|
|
116
|
-
expect(consoleSpy).toHaveBeenCalled()
|
|
117
|
-
|
|
118
|
-
consoleSpy.mockRestore()
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('removes item from localStorage when value is undefined', () => {
|
|
122
|
-
mockLocalStorage.setItem('test-key', JSON.stringify('stored-value'))
|
|
123
|
-
|
|
124
|
-
const { result } = renderHook(() => useLocalStorage('test-key', 'initial'))
|
|
125
|
-
|
|
126
|
-
act(() => {
|
|
127
|
-
result.current[1](undefined)
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
expect(result.current[0]).toBeUndefined()
|
|
131
|
-
expect(mockLocalStorage.removeItem).toHaveBeenCalledWith('test-key')
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('handles boolean values correctly', () => {
|
|
135
|
-
const { result } = renderHook(() => useLocalStorage('bool-key', false))
|
|
136
|
-
|
|
137
|
-
act(() => {
|
|
138
|
-
result.current[1](true)
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
expect(result.current[0]).toBe(true)
|
|
142
|
-
expect(mockLocalStorage.setItem).toHaveBeenCalledWith('bool-key', JSON.stringify(true))
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('handles null values correctly', () => {
|
|
146
|
-
const { result } = renderHook(() => useLocalStorage<string | null>('null-key', null))
|
|
147
|
-
|
|
148
|
-
act(() => {
|
|
149
|
-
result.current[1]('not-null')
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
expect(result.current[0]).toBe('not-null')
|
|
153
|
-
|
|
154
|
-
act(() => {
|
|
155
|
-
result.current[1](null)
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
expect(result.current[0]).toBe(null)
|
|
159
|
-
expect(mockLocalStorage.setItem).toHaveBeenCalledWith('null-key', JSON.stringify(null))
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
it('maintains state consistency across multiple hook instances with same key', () => {
|
|
163
|
-
const { result: result1 } = renderHook(() => useLocalStorage('shared-key', 'initial'))
|
|
164
|
-
const { result: result2 } = renderHook(() => useLocalStorage('shared-key', 'initial'))
|
|
165
|
-
|
|
166
|
-
act(() => {
|
|
167
|
-
result1.current[1]('updated')
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
// Both instances should have the same value
|
|
171
|
-
expect(result1.current[0]).toBe('updated')
|
|
172
|
-
expect(result2.current[0]).toBe('updated')
|
|
173
|
-
})
|
|
174
|
-
})
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { renderHook } from '@testing-library/react'
|
|
2
|
-
import { useSession } from 'next-auth/react'
|
|
3
|
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
4
|
-
import { useProAccess } from '../use-pro-access'
|
|
5
|
-
import React from 'react'
|
|
6
|
-
|
|
7
|
-
// Mock next-auth
|
|
8
|
-
jest.mock('next-auth/react')
|
|
9
|
-
const mockUseSession = useSession as jest.MockedFunction<typeof useSession>
|
|
10
|
-
|
|
11
|
-
// Mock fetch
|
|
12
|
-
global.fetch = jest.fn()
|
|
13
|
-
|
|
14
|
-
// Test wrapper with QueryClient
|
|
15
|
-
const createWrapper = () => {
|
|
16
|
-
const queryClient = new QueryClient({
|
|
17
|
-
defaultOptions: {
|
|
18
|
-
queries: {
|
|
19
|
-
retry: false,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
})
|
|
23
|
-
const TestWrapper = ({ children }: { children: React.ReactNode }) => (
|
|
24
|
-
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
25
|
-
)
|
|
26
|
-
TestWrapper.displayName = 'TestWrapper'
|
|
27
|
-
return TestWrapper
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe('useProAccess Hook', () => {
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
jest.clearAllMocks()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('returns false for unauthenticated users', () => {
|
|
36
|
-
mockUseSession.mockReturnValue({
|
|
37
|
-
data: null,
|
|
38
|
-
status: 'unauthenticated',
|
|
39
|
-
update: jest.fn(),
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const { result } = renderHook(() => useProAccess(), {
|
|
43
|
-
wrapper: createWrapper()
|
|
44
|
-
})
|
|
45
|
-
expect(result.current.hasProAccess).toBe(false)
|
|
46
|
-
expect(result.current.isLoading).toBe(false)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('returns false for authenticated users without pro subscription', () => {
|
|
50
|
-
mockUseSession.mockReturnValue({
|
|
51
|
-
data: {
|
|
52
|
-
user: {
|
|
53
|
-
id: '1',
|
|
54
|
-
email: 'user@example.com',
|
|
55
|
-
name: 'Test User',
|
|
56
|
-
},
|
|
57
|
-
expires: '2024-12-31',
|
|
58
|
-
},
|
|
59
|
-
status: 'authenticated',
|
|
60
|
-
update: jest.fn(),
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
const { result } = renderHook(() => useProAccess(), {
|
|
64
|
-
wrapper: createWrapper()
|
|
65
|
-
})
|
|
66
|
-
expect(result.current.hasProAccess).toBe(false)
|
|
67
|
-
expect(result.current.isLoading).toBe(false)
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('returns true for authenticated users with active pro subscription', () => {
|
|
71
|
-
mockUseSession.mockReturnValue({
|
|
72
|
-
data: {
|
|
73
|
-
user: {
|
|
74
|
-
id: '1',
|
|
75
|
-
email: 'pro@example.com',
|
|
76
|
-
name: 'Pro User',
|
|
77
|
-
subscription: {
|
|
78
|
-
plan: 'pro',
|
|
79
|
-
status: 'active',
|
|
80
|
-
expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(), // 30 days from now
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
expires: '2024-12-31',
|
|
84
|
-
},
|
|
85
|
-
status: 'authenticated',
|
|
86
|
-
update: jest.fn(),
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
const { result } = renderHook(() => useProAccess(), {
|
|
90
|
-
wrapper: createWrapper()
|
|
91
|
-
})
|
|
92
|
-
expect(result.current.hasProAccess).toBe(true)
|
|
93
|
-
expect(result.current.isLoading).toBe(false)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('returns false for users with expired pro subscription', () => {
|
|
97
|
-
mockUseSession.mockReturnValue({
|
|
98
|
-
data: {
|
|
99
|
-
user: {
|
|
100
|
-
id: '1',
|
|
101
|
-
email: 'expired@example.com',
|
|
102
|
-
name: 'Expired User',
|
|
103
|
-
subscription: {
|
|
104
|
-
plan: 'pro',
|
|
105
|
-
status: 'active',
|
|
106
|
-
expiresAt: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(), // 1 day ago
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
expires: '2024-12-31',
|
|
110
|
-
},
|
|
111
|
-
status: 'authenticated',
|
|
112
|
-
update: jest.fn(),
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
const { result } = renderHook(() => useProAccess(), {
|
|
116
|
-
wrapper: createWrapper()
|
|
117
|
-
})
|
|
118
|
-
expect(result.current.hasProAccess).toBe(false)
|
|
119
|
-
expect(result.current.isLoading).toBe(false)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
it('returns false for users with cancelled pro subscription', () => {
|
|
123
|
-
mockUseSession.mockReturnValue({
|
|
124
|
-
data: {
|
|
125
|
-
user: {
|
|
126
|
-
id: '1',
|
|
127
|
-
email: 'cancelled@example.com',
|
|
128
|
-
name: 'Cancelled User',
|
|
129
|
-
subscription: {
|
|
130
|
-
plan: 'pro',
|
|
131
|
-
status: 'cancelled',
|
|
132
|
-
expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(),
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
expires: '2024-12-31',
|
|
136
|
-
},
|
|
137
|
-
status: 'authenticated',
|
|
138
|
-
update: jest.fn(),
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
const { result } = renderHook(() => useProAccess(), {
|
|
142
|
-
wrapper: createWrapper()
|
|
143
|
-
})
|
|
144
|
-
expect(result.current.hasProAccess).toBe(false)
|
|
145
|
-
expect(result.current.isLoading).toBe(false)
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
it('returns loading state when session is loading', () => {
|
|
149
|
-
mockUseSession.mockReturnValue({
|
|
150
|
-
data: null,
|
|
151
|
-
status: 'loading',
|
|
152
|
-
update: jest.fn(),
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
const { result } = renderHook(() => useProAccess(), {
|
|
156
|
-
wrapper: createWrapper()
|
|
157
|
-
})
|
|
158
|
-
expect(result.current.hasProAccess).toBe(false)
|
|
159
|
-
expect(result.current.isLoading).toBe(true)
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
it('handles edge cases with missing subscription data', () => {
|
|
163
|
-
mockUseSession.mockReturnValue({
|
|
164
|
-
data: {
|
|
165
|
-
user: {
|
|
166
|
-
id: '1',
|
|
167
|
-
email: 'user@example.com',
|
|
168
|
-
name: 'Test User',
|
|
169
|
-
subscription: undefined,
|
|
170
|
-
},
|
|
171
|
-
expires: '2024-12-31',
|
|
172
|
-
},
|
|
173
|
-
status: 'authenticated',
|
|
174
|
-
update: jest.fn(),
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
const { result } = renderHook(() => useProAccess(), {
|
|
178
|
-
wrapper: createWrapper()
|
|
179
|
-
})
|
|
180
|
-
expect(result.current.hasProAccess).toBe(false)
|
|
181
|
-
expect(result.current.isLoading).toBe(false)
|
|
182
|
-
})
|
|
183
|
-
})
|