Skip to content

Commit 0ab8dae

Browse files
committed
Auto-fix formatting issues
1 parent 0d3a3be commit 0ab8dae

File tree

1 file changed

+97
-73
lines changed

1 file changed

+97
-73
lines changed

tests/unit/helpers.test.js

Lines changed: 97 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
* and prevent regressions.
88
*/
99

10-
import { strict as assert } from 'assert';
10+
import { strict as assert } from "assert";
1111

1212
/**
1313
* Helper function to generate safe filename
1414
* Mirrors the implementation in bin/utils/name.ts
1515
*/
1616
function generateSafeFilename(name) {
1717
return name
18-
.replace(/[<>:"/\\|?*]/g, '_')
19-
.replace(/\s+/g, '_')
20-
.replace(/\.+$/g, '')
18+
.replace(/[<>:"/\\|?*]/g, "_")
19+
.replace(/\s+/g, "_")
20+
.replace(/\.+$/g, "")
2121
.slice(0, 255);
2222
}
2323

@@ -35,50 +35,70 @@ function getSafeAppName(name) {
3535
export function testGetSafeAppName() {
3636
const tests = [
3737
// Basic cases
38-
{ input: 'MyApp', expected: 'myapp', description: 'Simple name' },
39-
{ input: 'My App', expected: 'my_app', description: 'Name with space' },
40-
{ input: 'my-app', expected: 'my-app', description: 'Name with hyphen' },
38+
{ input: "MyApp", expected: "myapp", description: "Simple name" },
39+
{ input: "My App", expected: "my_app", description: "Name with space" },
40+
{ input: "my-app", expected: "my-app", description: "Name with hyphen" },
4141

4242
// Chinese characters
43-
{ input: '我的应用', expected: '我的应用', description: 'Chinese name' },
44-
{ input: '我的 App', expected: '我的_app', description: 'Mixed Chinese and English' },
43+
{ input: "我的应用", expected: "我的应用", description: "Chinese name" },
44+
{
45+
input: "我的 App",
46+
expected: "我的_app",
47+
description: "Mixed Chinese and English",
48+
},
4549

4650
// Special characters
47-
{ input: 'App@2024', expected: 'app@2024', description: 'Special character @ (preserved)' },
48-
{ input: 'My/App', expected: 'my_app', description: 'Forward slash' },
49-
{ input: 'My\\App', expected: 'my_app', description: 'Backslash' },
50-
{ input: 'App:Name', expected: 'app_name', description: 'Colon' },
51-
{ input: 'App*Name', expected: 'app_name', description: 'Asterisk' },
52-
{ input: 'App?Name', expected: 'app_name', description: 'Question mark' },
53-
{ input: 'App"Name', expected: 'app_name', description: 'Double quote' },
54-
{ input: 'App<Name>', expected: 'app_name_', description: 'Angle brackets' },
55-
{ input: 'App|Name', expected: 'app_name', description: 'Pipe' },
51+
{
52+
input: "App@2024",
53+
expected: "app@2024",
54+
description: "Special character @ (preserved)",
55+
},
56+
{ input: "My/App", expected: "my_app", description: "Forward slash" },
57+
{ input: "My\\App", expected: "my_app", description: "Backslash" },
58+
{ input: "App:Name", expected: "app_name", description: "Colon" },
59+
{ input: "App*Name", expected: "app_name", description: "Asterisk" },
60+
{ input: "App?Name", expected: "app_name", description: "Question mark" },
61+
{ input: 'App"Name', expected: "app_name", description: "Double quote" },
62+
{
63+
input: "App<Name>",
64+
expected: "app_name_",
65+
description: "Angle brackets",
66+
},
67+
{ input: "App|Name", expected: "app_name", description: "Pipe" },
5668

5769
// Edge cases
58-
{ input: 'APP', expected: 'app', description: 'All uppercase' },
59-
{ input: 'a', expected: 'a', description: 'Single character' },
60-
{ input: '123', expected: '123', description: 'Numbers only' },
61-
{ input: ' App ', expected: '_app_', description: 'Leading/trailing spaces (collapsed)' },
62-
{ input: 'App...', expected: 'app', description: 'Trailing dots' },
70+
{ input: "APP", expected: "app", description: "All uppercase" },
71+
{ input: "a", expected: "a", description: "Single character" },
72+
{ input: "123", expected: "123", description: "Numbers only" },
73+
{
74+
input: " App ",
75+
expected: "_app_",
76+
description: "Leading/trailing spaces (collapsed)",
77+
},
78+
{ input: "App...", expected: "app", description: "Trailing dots" },
6379

6480
// Long names
6581
{
66-
input: 'A'.repeat(300),
67-
expected: 'a'.repeat(255),
68-
description: 'Very long name (should truncate to 255)',
82+
input: "A".repeat(300),
83+
expected: "a".repeat(255),
84+
description: "Very long name (should truncate to 255)",
6985
},
7086
];
7187

7288
let passed = 0;
7389
let failed = 0;
7490

75-
console.log('\n🧪 Testing getSafeAppName()');
76-
console.log('─'.repeat(50));
91+
console.log("\n🧪 Testing getSafeAppName()");
92+
console.log("─".repeat(50));
7793

7894
tests.forEach((test, index) => {
7995
try {
8096
const result = getSafeAppName(test.input);
81-
assert.equal(result, test.expected, `Expected "${test.expected}", got "${result}"`);
97+
assert.equal(
98+
result,
99+
test.expected,
100+
`Expected "${test.expected}", got "${result}"`,
101+
);
82102
console.log(` ✓ Test ${index + 1}: ${test.description}`);
83103
passed++;
84104
} catch (error) {
@@ -90,7 +110,7 @@ export function testGetSafeAppName() {
90110
}
91111
});
92112

93-
console.log('─'.repeat(50));
113+
console.log("─".repeat(50));
94114
console.log(`Results: ${passed} passed, ${failed} failed\n`);
95115

96116
return failed === 0;
@@ -100,44 +120,44 @@ export function testGetSafeAppName() {
100120
* Test suite for download error notification (browser environment simulation)
101121
*/
102122
export function testDownloadErrorNotification() {
103-
console.log('\n🧪 Testing showDownloadError() Logic');
104-
console.log('─'.repeat(50));
123+
console.log("\n🧪 Testing showDownloadError() Logic");
124+
console.log("─".repeat(50));
105125

106126
const tests = [
107127
{
108-
name: 'Chinese language detection',
109-
language: 'zh-CN',
110-
filename: 'test.pdf',
111-
expectedTitle: '下载错误',
112-
expectedBody: '下载失败: test.pdf',
128+
name: "Chinese language detection",
129+
language: "zh-CN",
130+
filename: "test.pdf",
131+
expectedTitle: "下载错误",
132+
expectedBody: "下载失败: test.pdf",
113133
},
114134
{
115-
name: 'English language detection',
116-
language: 'en-US',
117-
filename: 'document.docx',
118-
expectedTitle: 'Download Error',
119-
expectedBody: 'Download failed: document.docx',
135+
name: "English language detection",
136+
language: "en-US",
137+
filename: "document.docx",
138+
expectedTitle: "Download Error",
139+
expectedBody: "Download failed: document.docx",
120140
},
121141
{
122-
name: 'Traditional Chinese',
123-
language: 'zh-TW',
124-
filename: 'file.zip',
125-
expectedTitle: '下载错误',
126-
expectedBody: '下载失败: file.zip',
142+
name: "Traditional Chinese",
143+
language: "zh-TW",
144+
filename: "file.zip",
145+
expectedTitle: "下载错误",
146+
expectedBody: "下载失败: file.zip",
127147
},
128148
{
129-
name: 'Hong Kong Chinese',
130-
language: 'zh-HK',
131-
filename: 'image.png',
132-
expectedTitle: '下载错误',
133-
expectedBody: '下载失败: image.png',
149+
name: "Hong Kong Chinese",
150+
language: "zh-HK",
151+
filename: "image.png",
152+
expectedTitle: "下载错误",
153+
expectedBody: "下载失败: image.png",
134154
},
135155
{
136-
name: 'Special characters in filename',
137-
language: 'en-US',
138-
filename: 'my file (1).pdf',
139-
expectedTitle: 'Download Error',
140-
expectedBody: 'Download failed: my file (1).pdf',
156+
name: "Special characters in filename",
157+
language: "en-US",
158+
filename: "my file (1).pdf",
159+
expectedTitle: "Download Error",
160+
expectedBody: "Download failed: my file (1).pdf",
141161
},
142162
];
143163

@@ -149,18 +169,22 @@ export function testDownloadErrorNotification() {
149169
// Simulate language detection
150170
const isChineseLanguage = (lang) =>
151171
lang &&
152-
(lang.startsWith('zh') ||
153-
lang.includes('CN') ||
154-
lang.includes('TW') ||
155-
lang.includes('HK'));
172+
(lang.startsWith("zh") ||
173+
lang.includes("CN") ||
174+
lang.includes("TW") ||
175+
lang.includes("HK"));
156176

157177
const isChinese = isChineseLanguage(test.language);
158-
const title = isChinese ? '下载错误' : 'Download Error';
178+
const title = isChinese ? "下载错误" : "Download Error";
159179
const body = isChinese
160180
? `下载失败: ${test.filename}`
161181
: `Download failed: ${test.filename}`;
162182

163-
assert.equal(title, test.expectedTitle, `Title mismatch for ${test.name}`);
183+
assert.equal(
184+
title,
185+
test.expectedTitle,
186+
`Title mismatch for ${test.name}`,
187+
);
164188
assert.equal(body, test.expectedBody, `Body mismatch for ${test.name}`);
165189

166190
console.log(` ✓ Test ${index + 1}: ${test.name}`);
@@ -175,7 +199,7 @@ export function testDownloadErrorNotification() {
175199
}
176200
});
177201

178-
console.log('─'.repeat(50));
202+
console.log("─".repeat(50));
179203
console.log(`Results: ${passed} passed, ${failed} failed\n`);
180204

181205
return failed === 0;
@@ -185,20 +209,20 @@ export function testDownloadErrorNotification() {
185209
* Run all tests
186210
*/
187211
export async function runHelperTests() {
188-
console.log('\n📦 Helper Functions Unit Tests');
189-
console.log('='.repeat(50));
212+
console.log("\n📦 Helper Functions Unit Tests");
213+
console.log("=".repeat(50));
190214

191215
const results = [];
192216

193217
// Test getSafeAppName
194218
results.push({
195-
name: 'getSafeAppName()',
219+
name: "getSafeAppName()",
196220
passed: testGetSafeAppName(),
197221
});
198222

199223
// Test download error notification
200224
results.push({
201-
name: 'showDownloadError() Logic',
225+
name: "showDownloadError() Logic",
202226
passed: testDownloadErrorNotification(),
203227
});
204228

@@ -207,13 +231,13 @@ export async function runHelperTests() {
207231
const passedCount = results.filter((r) => r.passed).length;
208232
const totalCount = results.length;
209233

210-
console.log('\n📊 Helper Tests Summary');
211-
console.log('='.repeat(50));
234+
console.log("\n📊 Helper Tests Summary");
235+
console.log("=".repeat(50));
212236
results.forEach((result) => {
213-
const icon = result.passed ? '✅' : '❌';
237+
const icon = result.passed ? "✅" : "❌";
214238
console.log(`${icon} ${result.name}`);
215239
});
216-
console.log('='.repeat(50));
240+
console.log("=".repeat(50));
217241
console.log(`Total: ${passedCount}/${totalCount} test suites passed\n`);
218242

219243
return allPassed;
@@ -226,7 +250,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
226250
process.exit(success ? 0 : 1);
227251
})
228252
.catch((error) => {
229-
console.error('Test execution failed:', error);
253+
console.error("Test execution failed:", error);
230254
process.exit(1);
231255
});
232256
}

0 commit comments

Comments
 (0)