1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-31 18:50:14 +02:00

add layout option in share modal

This commit is contained in:
Kushagra Gour
2025-06-27 15:21:10 +05:30
parent e89bb4c5db
commit 0d4ba6314d
3 changed files with 238 additions and 33 deletions

View File

@@ -54,15 +54,48 @@ describe('Layout Parameter Tests', () => {
const params = new URLSearchParams(global.window.location.search);
global.window.codeHtml = params.get('html') || '';
global.window.codeCss = params.get('css') || '';
global.window.codeLayout = params.get('layout')
? parseInt(params.get('layout'), 10)
: null;
global.window.codeLayout = (() => {
const layout = params.get('layout');
if (!layout) return null;
if (layout === 'full') {
return 4;
}
const _val = parseInt(layout, 10);
if (_val >= 1 && _val <= 5) {
return _val;
}
return null;
})();
}
expect(global.window.codeLayout).toBe(3);
expect(global.window.codeHtml).toBe('<div>test</div>');
});
test('should handle "full" alias for layout mode 4', () => {
// Set up URL with "full" layout parameter
global.window.location.search = '?layout=full&html=<div>test</div>';
// Simulate the URL parsing logic
if (global.window.location.search) {
const params = new URLSearchParams(global.window.location.search);
global.window.codeLayout = (() => {
const layout = params.get('layout');
if (!layout) return null;
if (layout === 'full') {
return 4;
}
const _val = parseInt(layout, 10);
if (_val >= 1 && _val <= 5) {
return _val;
}
return null;
})();
}
expect(global.window.codeLayout).toBe(4);
});
test('should handle invalid layout parameter gracefully', () => {
// Set up URL with invalid layout parameter
global.window.location.search = '?layout=invalid&html=<div>test</div>';
@@ -70,12 +103,21 @@ describe('Layout Parameter Tests', () => {
// Simulate the URL parsing logic
if (global.window.location.search) {
const params = new URLSearchParams(global.window.location.search);
global.window.codeLayout = params.get('layout')
? parseInt(params.get('layout'), 10)
: null;
global.window.codeLayout = (() => {
const layout = params.get('layout');
if (!layout) return null;
if (layout === 'full') {
return 4;
}
const _val = parseInt(layout, 10);
if (_val >= 1 && _val <= 5) {
return _val;
}
return null;
})();
}
expect(global.window.codeLayout).toBe(NaN);
expect(global.window.codeLayout).toBe(null);
});
test('should handle layout parameter out of range', () => {
@@ -87,13 +129,22 @@ describe('Layout Parameter Tests', () => {
if (global.window.location.search) {
const params = new URLSearchParams(global.window.location.search);
global.window.codeLayout = params.get('layout')
? parseInt(params.get('layout'), 10)
: null;
global.window.codeLayout = (() => {
const layout = params.get('layout');
if (!layout) return null;
if (layout === 'full') {
return 4;
}
const _val = parseInt(layout, 10);
if (_val >= 1 && _val <= 5) {
return _val;
}
return null;
})();
}
// The layout should be parsed but may be outside valid range
expect(global.window.codeLayout).toBe(layoutValue);
// The layout should be null for out-of-range values
expect(global.window.codeLayout).toBe(null);
});
});
@@ -120,9 +171,18 @@ describe('Layout Parameter Tests', () => {
const params = new URLSearchParams(global.window.location.search);
global.window.codeHtml = params.get('html') || '';
global.window.codeCss = params.get('css') || '';
global.window.codeLayout = params.get('layout')
? parseInt(params.get('layout'), 10)
: null;
global.window.codeLayout = (() => {
const layout = params.get('layout');
if (!layout) return null;
if (layout === 'full') {
return 4;
}
const _val = parseInt(layout, 10);
if (_val >= 1 && _val <= 5) {
return _val;
}
return null;
})();
}
expect(global.window.codeLayout).toBe(2);
@@ -138,11 +198,47 @@ describe('Layout Parameter Tests', () => {
// Simulate the URL parsing logic
if (global.window.location.search) {
const params = new URLSearchParams(global.window.location.search);
global.window.codeLayout = params.get('layout')
? parseInt(params.get('layout'), 10)
: null;
global.window.codeLayout = (() => {
const layout = params.get('layout');
if (!layout) return null;
if (layout === 'full') {
return 4;
}
const _val = parseInt(layout, 10);
if (_val >= 1 && _val <= 5) {
return _val;
}
return null;
})();
}
expect(global.window.codeLayout).toBe(null);
});
test('should handle all valid layout values', () => {
// Test all valid layout values (1-5)
const validLayouts = [1, 2, 3, 4, 5];
validLayouts.forEach(layoutValue => {
global.window.location.search = `?layout=${layoutValue}`;
if (global.window.location.search) {
const params = new URLSearchParams(global.window.location.search);
global.window.codeLayout = (() => {
const layout = params.get('layout');
if (!layout) return null;
if (layout === 'full') {
return 4;
}
const _val = parseInt(layout, 10);
if (_val >= 1 && _val <= 5) {
return _val;
}
return null;
})();
}
expect(global.window.codeLayout).toBe(layoutValue);
});
});
});