|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>Test PowerShell Share</title> |
| 7 | + <style> |
| 8 | + body { |
| 9 | + font-family: monospace; |
| 10 | + padding: 20px; |
| 11 | + background: #f5f5f5; |
| 12 | + } |
| 13 | + #yasqe { |
| 14 | + height: 300px; |
| 15 | + border: 1px solid #ccc; |
| 16 | + background: white; |
| 17 | + margin-bottom: 20px; |
| 18 | + } |
| 19 | + #output { |
| 20 | + margin-top: 20px; |
| 21 | + padding: 15px; |
| 22 | + background: white; |
| 23 | + border: 1px solid #ddd; |
| 24 | + white-space: pre-wrap; |
| 25 | + font-family: 'Courier New', monospace; |
| 26 | + font-size: 12px; |
| 27 | + } |
| 28 | + button { |
| 29 | + margin: 10px 5px; |
| 30 | + padding: 10px 20px; |
| 31 | + cursor: pointer; |
| 32 | + background: #4CAF50; |
| 33 | + color: white; |
| 34 | + border: none; |
| 35 | + border-radius: 4px; |
| 36 | + } |
| 37 | + button:hover { |
| 38 | + background: #45a049; |
| 39 | + } |
| 40 | + .validation { |
| 41 | + margin-top: 20px; |
| 42 | + padding: 10px; |
| 43 | + background: #e8f5e9; |
| 44 | + border: 1px solid #4CAF50; |
| 45 | + border-radius: 4px; |
| 46 | + } |
| 47 | + .validation.fail { |
| 48 | + background: #ffebee; |
| 49 | + border-color: #f44336; |
| 50 | + } |
| 51 | + .validation h3 { |
| 52 | + margin-top: 0; |
| 53 | + } |
| 54 | + .check { |
| 55 | + margin: 5px 0; |
| 56 | + } |
| 57 | + .check.pass::before { |
| 58 | + content: '✓ '; |
| 59 | + color: green; |
| 60 | + font-weight: bold; |
| 61 | + } |
| 62 | + .check.fail::before { |
| 63 | + content: '✗ '; |
| 64 | + color: red; |
| 65 | + font-weight: bold; |
| 66 | + } |
| 67 | + </style> |
| 68 | +</head> |
| 69 | +<body> |
| 70 | + <h1>PowerShell Share Format Test</h1> |
| 71 | + <p>This page tests the new PowerShell share format with multi-line query and sparql-generated output file.</p> |
| 72 | + |
| 73 | + <div id="yasqe"></div> |
| 74 | + <button id="testBtn">Generate PowerShell Command</button> |
| 75 | + |
| 76 | + <div id="output"></div> |
| 77 | + <div id="validation"></div> |
| 78 | + |
| 79 | + <script type="module"> |
| 80 | + import Yasqe from '../packages/yasqe/src/index.ts'; |
| 81 | + |
| 82 | + // Initialize YASQE |
| 83 | + const yasqe = new Yasqe(document.getElementById('yasqe'), { |
| 84 | + value: `SELECT ?s ?p ?o WHERE { |
| 85 | + ?s ?p ?o . |
| 86 | + FILTER(?p = rdf:type) |
| 87 | +} |
| 88 | +ORDER BY ?s DESC(?o) |
| 89 | +LIMIT 10`, |
| 90 | + requestConfig: { |
| 91 | + endpoint: 'https://dbpedia.org/sparql', |
| 92 | + method: 'POST' |
| 93 | + } |
| 94 | + }); |
| 95 | + |
| 96 | + function testPowerShellShare() { |
| 97 | + try { |
| 98 | + const psCommand = yasqe.getAsPowerShellString(); |
| 99 | + const output = document.getElementById('output'); |
| 100 | + const validationDiv = document.getElementById('validation'); |
| 101 | + output.textContent = psCommand; |
| 102 | + |
| 103 | + // Validation checks |
| 104 | + const checks = [ |
| 105 | + ['Contains $query or $update variable', /\$(query|update) = @"/g.test(psCommand)], |
| 106 | + ['Contains closing @"', /^"@$/gm.test(psCommand)], |
| 107 | + ['Contains actual query text (not encoded)', psCommand.includes('SELECT ?s ?p ?o WHERE')], |
| 108 | + ['Contains ORDER BY clause', psCommand.includes('ORDER BY')], |
| 109 | + ['Contains Body with variable reference', /Body = ".*\$(query|update).*"/g.test(psCommand)], |
| 110 | + ['Contains sparql-generated output file', psCommand.includes('sparql-generated')], |
| 111 | + ['Does NOT contain URL-encoded query', !psCommand.includes('SELECT%20')], |
| 112 | + ['Does NOT contain encoded equals', !psCommand.includes('%3D')], |
| 113 | + ]; |
| 114 | + |
| 115 | + let validationHTML = '<h3>Validation Results:</h3>'; |
| 116 | + let allPassed = true; |
| 117 | + checks.forEach(([name, passed]) => { |
| 118 | + validationHTML += `<div class="check ${passed ? 'pass' : 'fail'}">${name}</div>`; |
| 119 | + if (!passed) allPassed = false; |
| 120 | + }); |
| 121 | + |
| 122 | + validationDiv.innerHTML = validationHTML; |
| 123 | + validationDiv.className = allPassed ? 'validation pass' : 'validation fail'; |
| 124 | + |
| 125 | + if (allPassed) { |
| 126 | + output.style.borderColor = 'green'; |
| 127 | + output.style.backgroundColor = '#f1f8f4'; |
| 128 | + } else { |
| 129 | + output.style.borderColor = 'red'; |
| 130 | + output.style.backgroundColor = '#fff5f5'; |
| 131 | + } |
| 132 | + |
| 133 | + console.log('\nGenerated PowerShell Command:'); |
| 134 | + console.log(psCommand); |
| 135 | + console.log('\nValidation Results:'); |
| 136 | + checks.forEach(([name, passed]) => { |
| 137 | + console.log(`${passed ? '✓' : '✗'} ${name}`); |
| 138 | + }); |
| 139 | + } catch (error) { |
| 140 | + document.getElementById('output').textContent = 'Error: ' + error.message; |
| 141 | + document.getElementById('validation').innerHTML = '<h3 class="fail">Error occurred!</h3><p>' + error.message + '</p>'; |
| 142 | + console.error(error); |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + // Setup button click handler |
| 147 | + document.getElementById('testBtn').addEventListener('click', testPowerShellShare); |
| 148 | + |
| 149 | + // Auto-run test on load |
| 150 | + window.addEventListener('load', () => { |
| 151 | + setTimeout(testPowerShellShare, 1000); |
| 152 | + }); |
| 153 | + </script> |
| 154 | +</body> |
| 155 | +</html> |
0 commit comments