Skip to content

Commit 16507b6

Browse files
Copilotdev31sanghvi
andcommitted
Add quick reference guide and comprehensive test suite
Co-authored-by: dev31sanghvi <[email protected]>
1 parent 6909c38 commit 16507b6

File tree

2 files changed

+352
-0
lines changed

2 files changed

+352
-0
lines changed

QUICKSTART.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Copybuffer Quick Reference
2+
3+
## Installation
4+
5+
```bash
6+
git clone https://github.com/dev31sanghvi/Copybuffer.git
7+
cd Copybuffer
8+
npm install
9+
npm run build
10+
npm link # Optional: for global command
11+
```
12+
13+
## Quick Start
14+
15+
```bash
16+
# Start monitoring
17+
copybuffer start
18+
19+
# View history
20+
copybuffer list
21+
22+
# Search
23+
copybuffer search "text"
24+
25+
# Get help
26+
copybuffer --help
27+
```
28+
29+
## All Commands
30+
31+
| Command | Description | Example |
32+
|---------|-------------|---------|
33+
| `start` | Start clipboard monitoring | `copybuffer start` |
34+
| `stop` | Stop clipboard monitoring | `copybuffer stop` |
35+
| `list` | List clipboard history | `copybuffer list --limit 20` |
36+
| `search <query>` | Search clipboard history | `copybuffer search "github"` |
37+
| `copy <id>` | Copy entry to clipboard | `copybuffer copy abc123-def-456` |
38+
| `delete <id>` | Delete an entry | `copybuffer delete abc123-def-456` |
39+
| `clear` | Clear all history | `copybuffer clear --yes` |
40+
| `export <file>` | Export history | `copybuffer export backup.json` |
41+
| `import <file>` | Import history | `copybuffer import backup.json` |
42+
| `sync-to-gist` | Sync to GitHub Gist | `copybuffer sync-to-gist` |
43+
| `sync-from-gist` | Sync from GitHub Gist | `copybuffer sync-from-gist` |
44+
| `config` | Show configuration | `copybuffer config` |
45+
| `config-set <key> <value>` | Set config value | `copybuffer config-set maxHistorySize 2000` |
46+
47+
## Configuration Options
48+
49+
```bash
50+
# Max history entries
51+
copybuffer config-set maxHistorySize 2000
52+
53+
# Data directory
54+
copybuffer config-set dataDir /path/to/data
55+
56+
# Hotkeys
57+
copybuffer config-set hotkeys.toggleHistory F11
58+
copybuffer config-set hotkeys.search F12
59+
60+
# Gist sync
61+
copybuffer config-set gist.enabled true
62+
copybuffer config-set gist.token YOUR_TOKEN
63+
```
64+
65+
## Files and Directories
66+
67+
| Path | Description |
68+
|------|-------------|
69+
| `~/.copybuffer/` | Data directory |
70+
| `~/.copybuffer/config.json` | Configuration file |
71+
| `~/.copybuffer/history.json` | Clipboard history |
72+
73+
## Hotkeys (Default)
74+
75+
| Key | Action |
76+
|-----|--------|
77+
| F9 | Toggle clipboard history |
78+
| F10 | Search clipboard |
79+
80+
## Common Workflows
81+
82+
### Basic Usage
83+
```bash
84+
copybuffer start # Start in one terminal
85+
# Use your system normally, copy things
86+
copybuffer list # View in another terminal
87+
```
88+
89+
### Search and Restore
90+
```bash
91+
copybuffer search "important text"
92+
copybuffer copy <entry-id>
93+
# Now paste with Ctrl+V
94+
```
95+
96+
### Backup and Sync
97+
```bash
98+
# Local backup
99+
copybuffer export ~/backups/clipboard-$(date +%Y%m%d).json
100+
101+
# Cloud sync
102+
copybuffer sync-to-gist # Upload
103+
copybuffer sync-from-gist # Download
104+
```
105+
106+
## Troubleshooting
107+
108+
| Issue | Solution |
109+
|-------|----------|
110+
| Command not found | Run `npm link` or use `node dist/cli.js` |
111+
| Clipboard not working | Install `xclip`: `sudo apt-get install xclip` |
112+
| Hotkeys not working | Check permissions or use CLI commands |
113+
| Gist sync fails | Verify token has `gist` scope |
114+
115+
## Environment Variables
116+
117+
Create `.env` file (optional):
118+
```bash
119+
GITHUB_TOKEN=your_token_here
120+
GIST_ID=your_gist_id_here
121+
```
122+
123+
## API Quick Reference
124+
125+
```typescript
126+
import { clipboardMonitor, searchManager, storageManager } from './dist/exports';
127+
128+
// Monitor
129+
clipboardMonitor.start();
130+
clipboardMonitor.stop();
131+
132+
// Search
133+
searchManager.search({ query: 'text', limit: 10 });
134+
searchManager.getRecent(20);
135+
136+
// Storage
137+
storageManager.loadHistory();
138+
storageManager.saveEntry(entry);
139+
storageManager.deleteEntry(id);
140+
storageManager.clearHistory();
141+
```
142+
143+
## Tips
144+
145+
- Use aliases in `.bashrc`: `alias cb='copybuffer list'`
146+
- Set up cron jobs for automated backups
147+
- Use tags in custom entries for better organization
148+
- Sync regularly if using multiple machines
149+
150+
## Links
151+
152+
- [Full Documentation](README.md)
153+
- [Examples](EXAMPLES.md)
154+
- [Contributing](CONTRIBUTING.md)
155+
- [GitHub Repository](https://github.com/dev31sanghvi/Copybuffer)
156+
157+
## License
158+
159+
MIT License - Free to use and modify for personal use.

test.sh

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
#!/bin/bash
2+
3+
# Comprehensive test script for Copybuffer
4+
# This script tests all major features to ensure they work correctly
5+
6+
# Don't exit on error - we want to count failures
7+
# set -e # Exit on error
8+
9+
echo "======================================"
10+
echo " Copybuffer Comprehensive Test"
11+
echo "======================================"
12+
echo ""
13+
14+
# Colors for output
15+
GREEN='\033[0;32m'
16+
RED='\033[0;31m'
17+
YELLOW='\033[1;33m'
18+
NC='\033[0m' # No Color
19+
20+
# Test counter
21+
TESTS_PASSED=0
22+
TESTS_FAILED=0
23+
24+
# Function to run a test
25+
run_test() {
26+
local test_name="$1"
27+
local command="$2"
28+
29+
echo -n "Testing: $test_name... "
30+
31+
if eval "$command" > /tmp/test_output.log 2>&1; then
32+
echo -e "${GREEN}PASSED${NC}"
33+
((TESTS_PASSED++))
34+
else
35+
echo -e "${RED}FAILED${NC}"
36+
echo " Error output:"
37+
cat /tmp/test_output.log | head -5
38+
((TESTS_FAILED++))
39+
fi
40+
}
41+
42+
# Function to verify output contains text
43+
verify_output() {
44+
local test_name="$1"
45+
local command="$2"
46+
local expected="$3"
47+
48+
echo -n "Testing: $test_name... "
49+
50+
if eval "$command" 2>&1 | grep -q "$expected"; then
51+
echo -e "${GREEN}PASSED${NC}"
52+
((TESTS_PASSED++))
53+
else
54+
echo -e "${RED}FAILED${NC}"
55+
echo " Expected to find: $expected"
56+
((TESTS_FAILED++))
57+
fi
58+
}
59+
60+
# Ensure clean state
61+
rm -rf ~/.copybuffer
62+
rm -f /tmp/test-*.json
63+
64+
echo "1. Build Tests"
65+
echo "--------------"
66+
run_test "TypeScript compilation" "npm run build"
67+
run_test "ESLint validation" "npm run lint"
68+
echo ""
69+
70+
echo "2. CLI Tests"
71+
echo "------------"
72+
run_test "CLI help command" "node dist/cli.js --help"
73+
run_test "CLI version command" "node dist/cli.js --version"
74+
echo ""
75+
76+
echo "3. Configuration Tests"
77+
echo "---------------------"
78+
verify_output "Default config creation" "node dist/cli.js config" "dataDir"
79+
verify_output "Config contains maxHistorySize" "node dist/cli.js config" "maxHistorySize"
80+
verify_output "Config contains hotkeys" "node dist/cli.js config" "hotkeys"
81+
run_test "Set config value" "node dist/cli.js config-set maxHistorySize 500"
82+
verify_output "Verify config update" "node dist/cli.js config" '"maxHistorySize": "500"'
83+
echo ""
84+
85+
echo "4. Storage Tests"
86+
echo "---------------"
87+
88+
# Create test data
89+
cat > /tmp/test-import.json << 'EOF'
90+
[
91+
{
92+
"id": "test-001",
93+
"content": "Test entry 1",
94+
"timestamp": 1698601200000,
95+
"type": "text"
96+
},
97+
{
98+
"id": "test-002",
99+
"content": "Test entry 2 with keyword",
100+
"timestamp": 1698601260000,
101+
"type": "text"
102+
},
103+
{
104+
"id": "test-003",
105+
"content": "Another test entry",
106+
"timestamp": 1698601320000,
107+
"type": "text",
108+
"tags": ["test", "example"]
109+
}
110+
]
111+
EOF
112+
113+
run_test "Import history" "node dist/cli.js import /tmp/test-import.json"
114+
verify_output "List shows entries" "node dist/cli.js list" "Test entry 1"
115+
run_test "Export history" "node dist/cli.js export /tmp/test-export.json"
116+
run_test "Exported file exists" "test -f /tmp/test-export.json"
117+
echo ""
118+
119+
echo "5. Search Tests"
120+
echo "--------------"
121+
verify_output "Search finds entry" "node dist/cli.js search 'keyword'" "Test entry 2"
122+
verify_output "Search with limit" "node dist/cli.js search 'test' --limit 2" "Test entry"
123+
verify_output "Search no results" "node dist/cli.js search 'nonexistent'" "No results found"
124+
echo ""
125+
126+
echo "6. Delete Tests"
127+
echo "--------------"
128+
run_test "Delete entry" "node dist/cli.js delete test-001"
129+
verify_output "Entry deleted" "node dist/cli.js search 'Test entry 1'" "No results found"
130+
echo ""
131+
132+
echo "7. List Tests"
133+
echo "------------"
134+
verify_output "List default limit" "node dist/cli.js list" "Showing"
135+
verify_output "List with custom limit" "node dist/cli.js list --limit 5" "Showing"
136+
echo ""
137+
138+
echo "8. Clear Tests"
139+
echo "-------------"
140+
run_test "Clear history" "node dist/cli.js clear --yes"
141+
verify_output "History cleared" "node dist/cli.js list" "No clipboard history found"
142+
echo ""
143+
144+
echo "9. File Structure Tests"
145+
echo "----------------------"
146+
run_test "Config directory exists" "test -d ~/.copybuffer"
147+
run_test "Config file exists" "test -f ~/.copybuffer/config.json"
148+
run_test "History file exists" "test -f ~/.copybuffer/history.json"
149+
echo ""
150+
151+
echo "10. Module Tests"
152+
echo "---------------"
153+
154+
# Create a simple test script to verify imports
155+
cat > /tmp/test-imports.js << 'EOF'
156+
const path = require('path');
157+
const projectDir = '/home/runner/work/Copybuffer/Copybuffer';
158+
const { storageManager, searchManager, configManager } = require(path.join(projectDir, 'dist/exports'));
159+
160+
// Test that modules export correctly
161+
console.log('storageManager:', typeof storageManager);
162+
console.log('searchManager:', typeof searchManager);
163+
console.log('configManager:', typeof configManager);
164+
165+
// Test basic functionality
166+
const config = configManager.getConfig();
167+
console.log('Config loaded:', config.dataDir ? 'yes' : 'no');
168+
169+
const history = storageManager.loadHistory();
170+
console.log('History loaded:', Array.isArray(history) ? 'yes' : 'no');
171+
172+
const recent = searchManager.getRecent(10);
173+
console.log('Recent retrieved:', Array.isArray(recent) ? 'yes' : 'no');
174+
EOF
175+
176+
run_test "Module imports work" "node /tmp/test-imports.js"
177+
echo ""
178+
179+
echo "======================================"
180+
echo " Test Summary"
181+
echo "======================================"
182+
echo ""
183+
echo -e "Tests Passed: ${GREEN}${TESTS_PASSED}${NC}"
184+
echo -e "Tests Failed: ${RED}${TESTS_FAILED}${NC}"
185+
echo ""
186+
187+
if [ $TESTS_FAILED -eq 0 ]; then
188+
echo -e "${GREEN}All tests passed!${NC}"
189+
exit 0
190+
else
191+
echo -e "${RED}Some tests failed!${NC}"
192+
exit 1
193+
fi

0 commit comments

Comments
 (0)