-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest-protocol-direct.js
More file actions
executable file
·79 lines (68 loc) · 2.37 KB
/
Copy pathtest-protocol-direct.js
File metadata and controls
executable file
·79 lines (68 loc) · 2.37 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
// Direct test script for spinshare:// protocol handling
// This script directly tests the URL handling logic without relying on system protocol registration
const { URL } = require('url');
// Test URLs
const testUrls = [
'spinshare://chart/154',
'spinshare://user/123',
'spinshare://playlist/456',
'spinshare://invalid/789', // Should log "Unknown deep link type"
'spinshare://chart/with/extra/segments', // Should still work, using first two segments
'spinshare://chart', // Should not navigate (not enough segments)
'http://example.com', // Should not be handled
];
// Mock the mainWindow.webContents.send function
const mockSend = (channel, route) => {
console.log(`[MOCK] Sending to channel '${channel}': ${route}`);
return true;
};
// Function to handle deep link navigation (copied from main.js)
function handleDeepLink(url) {
console.log(`\nTesting URL: ${url}`);
try {
const parsedUrl = new URL(url);
// Only handle spinshare:// URLs
if (parsedUrl.protocol !== 'spinshare:') {
console.log(`Not a spinshare:// URL: ${url}`);
return false;
}
// Remove leading slash
let pathname = parsedUrl.pathname;
if (pathname.startsWith('/')) {
pathname = pathname.substring(1);
}
const type = parsedUrl.hostname;
switch (type) {
default:
console.log(`Unknown deep link type: ${type}`);
return false;
case 'chart':
return mockSend('navigate-to', `/chart/${pathname}`);
case 'user':
return mockSend('navigate-to', `/user/${pathname}`);
case 'playlist':
return mockSend('navigate-to', `/playlist/${pathname}`);
}
} catch (error) {
console.error(`Error handling deep link: ${error.message}`);
return false;
}
}
// Test all URLs
console.log('=== Testing spinshare:// protocol handling ===');
let passCount = 0;
let failCount = 0;
testUrls.forEach((url) => {
const result = handleDeepLink(url);
if (result) {
console.log('✅ PASS');
passCount++;
} else {
console.log('❌ FAIL');
failCount++;
}
});
console.log('\n=== Test Results ===');
console.log(`Total tests: ${testUrls.length}`);
console.log(`Passed: ${passCount}`);
console.log(`Failed: ${failCount}`);