@designcrowd/library.brand-page 5.15.12 → 5.15.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/{CreatedOnBrandCrowd-de-de-DFKc_so0.js → CreatedOnBrandCrowd-de-de-C5FXWLML.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-en-us-40QRcYUX.js → CreatedOnBrandCrowd-en-us-G_4dcPih.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-es-es-DMfH3fRr.js → CreatedOnBrandCrowd-es-es-BRncVaEZ.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-fr-DbNQrijo.js → CreatedOnBrandCrowd-fr-ca-DPFhUq3i.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-ca-DbNQrijo.js → CreatedOnBrandCrowd-fr-fr-DPFhUq3i.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-pt-V3Xcyi3r.js → CreatedOnBrandCrowd-pt-br-DKWkP6IS.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-br-V3Xcyi3r.js → CreatedOnBrandCrowd-pt-pt-DKWkP6IS.js} +1 -1
- package/lib/src/{CreatedOnDcom-de-de-DpegN5_e.js → CreatedOnDcom-de-de-CMMOIPW8.js} +1 -1
- package/lib/src/{CreatedOnDcom-en-us-ByiQFMkC.js → CreatedOnDcom-en-us-DS6QmZZJ.js} +1 -1
- package/lib/src/{CreatedOnDcom-es-es-5eBXXPKs.js → CreatedOnDcom-es-es-DjUY-mfY.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-ca-DRMV4ACI.js → CreatedOnDcom-fr-ca-DX8LU2Yu.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-fr-CQrrHapF.js → CreatedOnDcom-fr-fr-BDLSIYqq.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-br-8bqzVFM8.js → CreatedOnDcom-pt-br-Bcp-qwUZ.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-pt-Dgv_C7cs.js → CreatedOnDcom-pt-pt-DtolTWh9.js} +1 -1
- package/lib/src/brand-page/utils/logo.util.d.ts +19 -0
- package/lib/src/brand-page/utils/logo.util.js +79 -1
- package/lib/src/brand-page/utils/migration/migration-07.js +7 -17
- package/lib/src/brand-page/utils/migration/migration-08.d.ts +5 -0
- package/lib/src/brand-page/utils/migration/migration-08.js +71 -0
- package/lib/src/brand-page/utils/migration.util.js +6 -0
- package/lib/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.js +6 -2
- package/lib/src/clients/fabric-render-client.js +1 -1
- package/lib/src/css/library.brand-page-brandCrowd.min.css +2 -2
- package/lib/src/css/library.brand-page-brandPage.min.css +2 -2
- package/lib/src/css/library.brand-page-designCom.min.css +2 -2
- package/lib/src/css/library.brand-page-preview.min.css +2 -2
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.mjs +53 -52
- package/lib/src/{lib-CF7FYBeS.js → lib-B3L785Hu.js} +11279 -11170
- package/lib/src/lib.js +1 -1
- package/package.json +1 -1
- package/src/brand-page/components/logo/LogoRender.vue +2 -1
- package/src/brand-page/utils/__snapshots__/migration.util.test.ts.snap +3 -3
- package/src/brand-page/utils/logo.util.ts +130 -1
- package/src/brand-page/utils/migration/migration-07.test.ts +2 -0
- package/src/brand-page/utils/migration/migration-07.ts +8 -25
- package/src/brand-page/utils/migration/migration-08.test.ts +398 -0
- package/src/brand-page/utils/migration/migration-08.ts +118 -0
- package/src/brand-page/utils/migration.util.ts +6 -0
- package/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.ts +11 -2
- package/src/clients/fabric-render-client.ts +1 -1
- package/src/lib.ts +4 -1
package/lib/src/lib.js
CHANGED
|
@@ -26,7 +26,7 @@ export { default as SensitiveContentModal } from './brand-page/components/sensit
|
|
|
26
26
|
// functions
|
|
27
27
|
export { getBrandPageViewModelFromBrandPageModel, migrateBrandPageModel, } from './brand-page/utils';
|
|
28
28
|
export * as brandPageUtils from './brand-page/utils';
|
|
29
|
-
export { getOptimalLogoSize } from './brand-page/utils/logo.util';
|
|
29
|
+
export { getOptimalLogoSize, calculateOptimizedLogoDimensions, } from './brand-page/utils/logo.util';
|
|
30
30
|
export { sanitizeRTEHtml } from './brand-page-maker/utils';
|
|
31
31
|
export { getPageSlugFromPageTitle } from './brand-page-maker/utils/slug.util';
|
|
32
32
|
// stores
|
package/package.json
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
>
|
|
16
16
|
<div
|
|
17
17
|
:style="{
|
|
18
|
-
...(props.isBrandPageOrIsBrandContact
|
|
18
|
+
...(props.isBrandPageOrIsBrandContact &&
|
|
19
|
+
!props.viewModel?.useOldLogoRenderSize
|
|
19
20
|
? {
|
|
20
21
|
margin: 'var(--logo-spacing) auto',
|
|
21
22
|
height: `${viewModel?.logoImageHeight || DEFAULT_LOGO_HEIGHT}`,
|
|
@@ -427,7 +427,7 @@ exports[`migration.util > Banner Contents - text Align and Font Family should no
|
|
|
427
427
|
},
|
|
428
428
|
},
|
|
429
429
|
},
|
|
430
|
-
"v":
|
|
430
|
+
"v": 8,
|
|
431
431
|
},
|
|
432
432
|
"useOldLogoRenderSize": true,
|
|
433
433
|
}
|
|
@@ -843,7 +843,7 @@ exports[`migration.util > migrateBrandPageModel should return brand page model w
|
|
|
843
843
|
},
|
|
844
844
|
},
|
|
845
845
|
},
|
|
846
|
-
"v":
|
|
846
|
+
"v": 8,
|
|
847
847
|
},
|
|
848
848
|
"useOldLogoRenderSize": true,
|
|
849
849
|
}
|
|
@@ -1266,7 +1266,7 @@ exports[`migration.util > migrateBrandPageModel should return brand page model w
|
|
|
1266
1266
|
},
|
|
1267
1267
|
},
|
|
1268
1268
|
},
|
|
1269
|
-
"v":
|
|
1269
|
+
"v": 8,
|
|
1270
1270
|
},
|
|
1271
1271
|
"useOldLogoRenderSize": true,
|
|
1272
1272
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_LOGO_VARIATION,
|
|
3
|
+
LOGO_VARIATION,
|
|
4
|
+
DEFAULT_LOGO_WIDTH,
|
|
5
|
+
DEFAULT_LOGO_HEIGHT,
|
|
6
|
+
} from '../constants';
|
|
2
7
|
import type {
|
|
3
8
|
AbstractPageFooterStyles,
|
|
4
9
|
AbstractPageHeaderStyles,
|
|
@@ -334,3 +339,127 @@ export const getOptimalLogoSize = (
|
|
|
334
339
|
return `${Math.round(newSize)}rem`;
|
|
335
340
|
}
|
|
336
341
|
};
|
|
342
|
+
|
|
343
|
+
export const calculateLogoDimensions = (
|
|
344
|
+
logoData: { width: number; height: number },
|
|
345
|
+
maxWidth: string,
|
|
346
|
+
maxHeight: string,
|
|
347
|
+
) => {
|
|
348
|
+
const maxWidthRem = parseFloat(maxWidth);
|
|
349
|
+
const maxHeightRem = parseFloat(maxHeight);
|
|
350
|
+
|
|
351
|
+
const logoAspectRatio = logoData.width / logoData.height;
|
|
352
|
+
|
|
353
|
+
let actualHeight: number;
|
|
354
|
+
|
|
355
|
+
if (logoAspectRatio >= 1) {
|
|
356
|
+
actualHeight = maxWidthRem / logoAspectRatio;
|
|
357
|
+
} else {
|
|
358
|
+
actualHeight = maxHeightRem;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const actualHeightRem = `${Math.ceil(actualHeight)}rem`;
|
|
362
|
+
|
|
363
|
+
return { width: actualHeightRem, height: actualHeightRem };
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
export const calculateOptimizedLogoDimensions = (
|
|
367
|
+
logoData: { width: number; height: number } | null,
|
|
368
|
+
currentWidth: string,
|
|
369
|
+
currentHeight: string,
|
|
370
|
+
) => {
|
|
371
|
+
const currentHeightRem = parseFloat(currentHeight);
|
|
372
|
+
|
|
373
|
+
if (logoData && logoData.width && logoData.height) {
|
|
374
|
+
const logoAspectRatio = logoData.width / logoData.height;
|
|
375
|
+
let newsize = currentHeightRem;
|
|
376
|
+
|
|
377
|
+
// Width-dominant logo (wider than tall)
|
|
378
|
+
if (logoAspectRatio >= 1.75 && logoAspectRatio <= 2) {
|
|
379
|
+
const ratioDiff = 2 - logoAspectRatio;
|
|
380
|
+
|
|
381
|
+
newsize = currentHeightRem - Math.round(ratioDiff * 10);
|
|
382
|
+
|
|
383
|
+
return {
|
|
384
|
+
width: `${newsize}rem`,
|
|
385
|
+
height: `${newsize}rem`,
|
|
386
|
+
};
|
|
387
|
+
} else if (logoAspectRatio > 2) {
|
|
388
|
+
return {
|
|
389
|
+
width: `4rem`,
|
|
390
|
+
height: `4rem`,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return { width: currentWidth, height: currentHeight };
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
export const recalculateLogoContentDimensions = async (
|
|
399
|
+
pageData: any,
|
|
400
|
+
editableLogoVariations?: {
|
|
401
|
+
variationId: number;
|
|
402
|
+
width: number;
|
|
403
|
+
height: number;
|
|
404
|
+
}[],
|
|
405
|
+
) => {
|
|
406
|
+
try {
|
|
407
|
+
const logoContents: {
|
|
408
|
+
content: any;
|
|
409
|
+
pageIndex: number;
|
|
410
|
+
contentIndex: number;
|
|
411
|
+
}[] = [];
|
|
412
|
+
|
|
413
|
+
pageData.pages.forEach((page: any, pageIndex: number) => {
|
|
414
|
+
page.contents.forEach((contentItem: any, contentIndex: number) => {
|
|
415
|
+
const content = contentItem.settings.content;
|
|
416
|
+
|
|
417
|
+
if (isLogoContent(content)) {
|
|
418
|
+
logoContents.push({ content, pageIndex, contentIndex });
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
if (logoContents.length === 0) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
logoContents.forEach(({ content }) => {
|
|
428
|
+
let logoData: { width: number; height: number } | null = null;
|
|
429
|
+
|
|
430
|
+
// First priority: Use editableLogoVariations if available
|
|
431
|
+
if (
|
|
432
|
+
editableLogoVariations &&
|
|
433
|
+
content.logoImage?.logoVariation !== undefined
|
|
434
|
+
) {
|
|
435
|
+
const matchingVariation = editableLogoVariations.find(
|
|
436
|
+
(variation) =>
|
|
437
|
+
variation.variationId === content.logoImage.logoVariation,
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
if (matchingVariation) {
|
|
441
|
+
logoData = {
|
|
442
|
+
width: matchingVariation.width,
|
|
443
|
+
height: matchingVariation.height,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Apply dimensions or fallback logic
|
|
449
|
+
if (logoData && logoData.width && logoData.height) {
|
|
450
|
+
const currentMaxWidth = content.logoImageWidth || DEFAULT_LOGO_WIDTH;
|
|
451
|
+
const currentMaxHeight = content.logoImageHeight || DEFAULT_LOGO_HEIGHT;
|
|
452
|
+
const dimensions = calculateOptimizedLogoDimensions(
|
|
453
|
+
logoData,
|
|
454
|
+
currentMaxWidth,
|
|
455
|
+
currentMaxHeight,
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
content.logoImageHeight = dimensions.height;
|
|
459
|
+
content.logoImageWidth = dimensions.width;
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
} catch (error) {
|
|
463
|
+
console.warn('Failed to recalculate prepurchase logo dimensions:', error);
|
|
464
|
+
}
|
|
465
|
+
};
|
|
@@ -17,6 +17,7 @@ const createTestBrandPageData = (
|
|
|
17
17
|
pageHeaderMobile: defaultLogoConfig,
|
|
18
18
|
pageFooterDesktop: defaultLogoConfig,
|
|
19
19
|
pageFooterMobile: defaultLogoConfig,
|
|
20
|
+
brandPageType: 'brandSite',
|
|
20
21
|
...overrides,
|
|
21
22
|
} as BrandPageData;
|
|
22
23
|
};
|
|
@@ -25,6 +26,7 @@ const createTestBrandPageData = (
|
|
|
25
26
|
const createMigrationData = (brandPageData: BrandPageData): MigrationData => {
|
|
26
27
|
return {
|
|
27
28
|
brandPageModel: new BrandPageModel(brandPageData),
|
|
29
|
+
useOldLogoRenderSize: false,
|
|
28
30
|
} as MigrationData;
|
|
29
31
|
};
|
|
30
32
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BRAND_PAGE_TYPES,
|
|
2
3
|
DEFAULT_LOGO_HEIGHT,
|
|
3
4
|
DEFAULT_LOGO_WIDTH,
|
|
4
5
|
PageFooterDesktop,
|
|
@@ -7,37 +8,19 @@ import {
|
|
|
7
8
|
PageHeaderMobile,
|
|
8
9
|
} from '../..';
|
|
9
10
|
import { FabricRenderClient } from '../../../clients/fabric-render-client';
|
|
11
|
+
import { calculateLogoDimensions } from '../logo.util';
|
|
10
12
|
import type { MigrationData } from '../migration.util';
|
|
11
13
|
|
|
12
|
-
const calculateConstrainedDimensions = (
|
|
13
|
-
logoData: { width: number; height: number },
|
|
14
|
-
maxWidth: string,
|
|
15
|
-
maxHeight: string,
|
|
16
|
-
) => {
|
|
17
|
-
const maxWidthRem = parseFloat(maxWidth);
|
|
18
|
-
const maxHeightRem = parseFloat(maxHeight);
|
|
19
|
-
|
|
20
|
-
const logoAspectRatio = logoData.width / logoData.height;
|
|
21
|
-
|
|
22
|
-
let actualHeight: number;
|
|
23
|
-
|
|
24
|
-
if (logoAspectRatio >= 1) {
|
|
25
|
-
actualHeight = maxWidthRem / logoAspectRatio;
|
|
26
|
-
} else {
|
|
27
|
-
actualHeight = maxHeightRem;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const actualHeightRem = `${Math.ceil(actualHeight)}rem`;
|
|
31
|
-
|
|
32
|
-
return { width: actualHeightRem, height: actualHeightRem };
|
|
33
|
-
};
|
|
34
|
-
|
|
35
14
|
export const migration07 = async (
|
|
36
15
|
migrationResult: MigrationData,
|
|
37
16
|
options: { isServerRender: boolean },
|
|
38
17
|
): Promise<MigrationData> => {
|
|
39
18
|
const { brandPageModel } = migrationResult;
|
|
40
19
|
|
|
20
|
+
if (brandPageModel.brandPageType !== BRAND_PAGE_TYPES.brandSite) {
|
|
21
|
+
return migrationResult;
|
|
22
|
+
}
|
|
23
|
+
|
|
41
24
|
if (options.isServerRender !== undefined && options.isServerRender) {
|
|
42
25
|
migrationResult.useOldLogoRenderSize = true;
|
|
43
26
|
|
|
@@ -87,7 +70,7 @@ export const migration07 = async (
|
|
|
87
70
|
const currentMaxWidth = config.logoImageWidth || DEFAULT_LOGO_WIDTH;
|
|
88
71
|
const currentMaxHeight = config.logoImageHeight || DEFAULT_LOGO_HEIGHT;
|
|
89
72
|
|
|
90
|
-
const dimensions =
|
|
73
|
+
const dimensions = calculateLogoDimensions(
|
|
91
74
|
logoData,
|
|
92
75
|
currentMaxWidth,
|
|
93
76
|
currentMaxHeight,
|
|
@@ -111,7 +94,7 @@ export const migration07 = async (
|
|
|
111
94
|
}
|
|
112
95
|
});
|
|
113
96
|
} catch (error) {
|
|
114
|
-
console.warn('Migration
|
|
97
|
+
console.warn('Migration 07: Failed to fetch logo dimensions:', error);
|
|
115
98
|
migrationResult.useOldLogoRenderSize = true;
|
|
116
99
|
|
|
117
100
|
return migrationResult;
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { describe, test, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { migration08 } from './migration-08';
|
|
3
|
+
import type { MigrationData } from '../migration.util';
|
|
4
|
+
import { BRAND_PAGE_TYPES, type LogoContent } from '../../models';
|
|
5
|
+
import { FabricRenderClient } from '../../../clients/fabric-render-client';
|
|
6
|
+
|
|
7
|
+
// Create a mock instance that will be reused
|
|
8
|
+
const mockFabricClientInstance = {
|
|
9
|
+
getLogoSvgUrlByLogoImageAsync: vi.fn(),
|
|
10
|
+
getLogoSvgUrlByLogoTemplateImageAsync: vi.fn(),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Mock FabricRenderClient
|
|
14
|
+
vi.mock('../../../clients/fabric-render-client', () => ({
|
|
15
|
+
FabricRenderClient: {
|
|
16
|
+
getInstance: vi.fn(() => mockFabricClientInstance),
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
const createTestBrandPageData = (overrides: any = {}) => ({
|
|
21
|
+
v: 7,
|
|
22
|
+
brandPageType: BRAND_PAGE_TYPES.default,
|
|
23
|
+
pages: [
|
|
24
|
+
{
|
|
25
|
+
title: 'Home',
|
|
26
|
+
slug: 'home',
|
|
27
|
+
contents: [
|
|
28
|
+
{
|
|
29
|
+
id: '1',
|
|
30
|
+
type: 'logo',
|
|
31
|
+
logoImage: { logoDraftToken: '', logoVariation: 0 },
|
|
32
|
+
logoImageHeight: '9rem',
|
|
33
|
+
logoImageWidth: '9rem',
|
|
34
|
+
isLogoVisible: true,
|
|
35
|
+
backgroundStyle: {},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
styles: {
|
|
41
|
+
logoStyles: {
|
|
42
|
+
imageStyle: { height: '9rem', width: '9rem' },
|
|
43
|
+
backgroundStyle: {},
|
|
44
|
+
},
|
|
45
|
+
textStyles: { style: { color: '#000' } },
|
|
46
|
+
buttonStyles: {},
|
|
47
|
+
backgroundStyles: { style: { background: '#fff' } },
|
|
48
|
+
galleryStyles: {},
|
|
49
|
+
},
|
|
50
|
+
...overrides,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const createMigrationData = (brandPageData: any): MigrationData => ({
|
|
54
|
+
brandPageModel: brandPageData,
|
|
55
|
+
useOldLogoRenderSize: false,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('migration08', () => {
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
vi.clearAllMocks();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('should skip migration when isServerRender is true', async () => {
|
|
64
|
+
const brandPageData = createTestBrandPageData();
|
|
65
|
+
const migrationData = createMigrationData(brandPageData);
|
|
66
|
+
|
|
67
|
+
const result = await migration08(migrationData, { isServerRender: true });
|
|
68
|
+
|
|
69
|
+
expect(result.useOldLogoRenderSize).toBe(true);
|
|
70
|
+
expect(
|
|
71
|
+
(result.brandPageModel.pages[0].contents[0] as LogoContent)
|
|
72
|
+
.logoImageHeight,
|
|
73
|
+
).toBe('9rem');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('should handle brandPage type with logo content', async () => {
|
|
77
|
+
const brandPageData = createTestBrandPageData({
|
|
78
|
+
brandPageType: BRAND_PAGE_TYPES.default,
|
|
79
|
+
pages: [
|
|
80
|
+
{
|
|
81
|
+
title: 'Home',
|
|
82
|
+
slug: 'home',
|
|
83
|
+
contents: [
|
|
84
|
+
{
|
|
85
|
+
id: '1',
|
|
86
|
+
type: 'logo',
|
|
87
|
+
logoImage: { logoDraftToken: 'test-token', logoVariation: 0 },
|
|
88
|
+
logoImageHeight: '9rem',
|
|
89
|
+
logoImageWidth: '9rem',
|
|
90
|
+
isLogoVisible: true,
|
|
91
|
+
backgroundStyle: {},
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
const migrationData = createMigrationData(brandPageData);
|
|
98
|
+
|
|
99
|
+
// Mock the fabric client response
|
|
100
|
+
mockFabricClientInstance.getLogoSvgUrlByLogoImageAsync.mockResolvedValue({
|
|
101
|
+
width: 120,
|
|
102
|
+
height: 80,
|
|
103
|
+
data: 'test-svg-data',
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const result = await migration08(migrationData, { isServerRender: false });
|
|
107
|
+
|
|
108
|
+
expect(result.useOldLogoRenderSize).toBe(false);
|
|
109
|
+
expect(
|
|
110
|
+
mockFabricClientInstance.getLogoSvgUrlByLogoImageAsync,
|
|
111
|
+
).toHaveBeenCalledWith({
|
|
112
|
+
logoDraftToken: 'test-token',
|
|
113
|
+
logoVariation: 0,
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('should skip brandSite type (brandSite does not have logo content)', async () => {
|
|
118
|
+
const brandPageData = createTestBrandPageData({
|
|
119
|
+
brandPageType: BRAND_PAGE_TYPES.brandSite,
|
|
120
|
+
pages: [
|
|
121
|
+
{
|
|
122
|
+
title: 'Home',
|
|
123
|
+
slug: 'home',
|
|
124
|
+
contents: [
|
|
125
|
+
{
|
|
126
|
+
id: '1',
|
|
127
|
+
type: 'logo',
|
|
128
|
+
logoImage: { logoDraftToken: 'test-token', logoVariation: 0 },
|
|
129
|
+
logoImageHeight: '10rem',
|
|
130
|
+
logoImageWidth: '10rem',
|
|
131
|
+
isLogoVisible: true,
|
|
132
|
+
backgroundStyle: {},
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
const migrationData = createMigrationData(brandPageData);
|
|
139
|
+
const originalLogoHeight = (
|
|
140
|
+
migrationData.brandPageModel.pages[0].contents[0] as LogoContent
|
|
141
|
+
).logoImageHeight;
|
|
142
|
+
const originalLogoWidth = (
|
|
143
|
+
migrationData.brandPageModel.pages[0].contents[0] as LogoContent
|
|
144
|
+
).logoImageWidth;
|
|
145
|
+
|
|
146
|
+
const result = await migration08(migrationData, { isServerRender: false });
|
|
147
|
+
|
|
148
|
+
// Migration should complete successfully but skip processing brandSite
|
|
149
|
+
expect(result.useOldLogoRenderSize).toBe(false);
|
|
150
|
+
|
|
151
|
+
// Logo dimensions should remain unchanged since brandSite is skipped
|
|
152
|
+
expect(
|
|
153
|
+
(result.brandPageModel.pages[0].contents[0] as LogoContent)
|
|
154
|
+
.logoImageHeight,
|
|
155
|
+
).toBe(originalLogoHeight);
|
|
156
|
+
expect(
|
|
157
|
+
(result.brandPageModel.pages[0].contents[0] as LogoContent)
|
|
158
|
+
.logoImageWidth,
|
|
159
|
+
).toBe(originalLogoWidth);
|
|
160
|
+
|
|
161
|
+
// Fabric client should not have been called
|
|
162
|
+
expect(
|
|
163
|
+
mockFabricClientInstance.getLogoSvgUrlByLogoImageAsync,
|
|
164
|
+
).not.toHaveBeenCalled();
|
|
165
|
+
expect(
|
|
166
|
+
mockFabricClientInstance.getLogoSvgUrlByLogoTemplateImageAsync,
|
|
167
|
+
).not.toHaveBeenCalled();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('should handle brandContact type with logo content', async () => {
|
|
171
|
+
const brandPageData = createTestBrandPageData({
|
|
172
|
+
brandPageType: BRAND_PAGE_TYPES.brandContact,
|
|
173
|
+
pages: [
|
|
174
|
+
{
|
|
175
|
+
title: 'Contact',
|
|
176
|
+
slug: 'contact',
|
|
177
|
+
contents: [
|
|
178
|
+
{
|
|
179
|
+
id: '1',
|
|
180
|
+
type: 'logo',
|
|
181
|
+
logoImage: { logoDraftToken: 'test-token', logoVariation: 0 },
|
|
182
|
+
logoImageHeight: '8rem',
|
|
183
|
+
logoImageWidth: '8rem',
|
|
184
|
+
isLogoVisible: true,
|
|
185
|
+
backgroundStyle: {},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
});
|
|
191
|
+
const migrationData = createMigrationData(brandPageData);
|
|
192
|
+
|
|
193
|
+
const result = await migration08(migrationData, { isServerRender: false });
|
|
194
|
+
|
|
195
|
+
expect(result.useOldLogoRenderSize).toBe(false);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('should handle multiple pages with logo content', async () => {
|
|
199
|
+
const brandPageData = createTestBrandPageData({
|
|
200
|
+
brandPageType: BRAND_PAGE_TYPES.default,
|
|
201
|
+
pages: [
|
|
202
|
+
{
|
|
203
|
+
title: 'Home',
|
|
204
|
+
slug: 'home',
|
|
205
|
+
contents: [
|
|
206
|
+
{
|
|
207
|
+
id: '1',
|
|
208
|
+
type: 'logo',
|
|
209
|
+
logoImage: { logoDraftToken: 'test-token-1', logoVariation: 0 },
|
|
210
|
+
logoImageHeight: '9rem',
|
|
211
|
+
logoImageWidth: '9rem',
|
|
212
|
+
isLogoVisible: true,
|
|
213
|
+
backgroundStyle: {},
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
title: 'About',
|
|
219
|
+
slug: 'about',
|
|
220
|
+
contents: [
|
|
221
|
+
{
|
|
222
|
+
id: '2',
|
|
223
|
+
type: 'logo',
|
|
224
|
+
logoImage: { logoDraftToken: 'test-token-2', logoVariation: 0 },
|
|
225
|
+
logoImageHeight: '10rem',
|
|
226
|
+
logoImageWidth: '10rem',
|
|
227
|
+
isLogoVisible: true,
|
|
228
|
+
backgroundStyle: {},
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
});
|
|
234
|
+
const migrationData = createMigrationData(brandPageData);
|
|
235
|
+
|
|
236
|
+
// Mock the fabric client response
|
|
237
|
+
const mockFabricClient = FabricRenderClient.getInstance();
|
|
238
|
+
|
|
239
|
+
vi.mocked(mockFabricClient.getLogoSvgUrlByLogoImageAsync).mockResolvedValue(
|
|
240
|
+
{
|
|
241
|
+
width: 120,
|
|
242
|
+
height: 80,
|
|
243
|
+
data: 'test-svg-data',
|
|
244
|
+
},
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
const result = await migration08(migrationData, { isServerRender: false });
|
|
248
|
+
|
|
249
|
+
expect(result.useOldLogoRenderSize).toBe(false);
|
|
250
|
+
expect(
|
|
251
|
+
mockFabricClient.getLogoSvgUrlByLogoImageAsync,
|
|
252
|
+
).toHaveBeenCalledTimes(2);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('should handle logo content without logo tokens', async () => {
|
|
256
|
+
const brandPageData = createTestBrandPageData({
|
|
257
|
+
brandPageType: BRAND_PAGE_TYPES.default,
|
|
258
|
+
pages: [
|
|
259
|
+
{
|
|
260
|
+
title: 'Home',
|
|
261
|
+
slug: 'home',
|
|
262
|
+
contents: [
|
|
263
|
+
{
|
|
264
|
+
id: '1',
|
|
265
|
+
type: 'logo',
|
|
266
|
+
logoImage: { logoDraftToken: '', logoVariation: 0 },
|
|
267
|
+
logoImageHeight: '15rem',
|
|
268
|
+
logoImageWidth: '15rem',
|
|
269
|
+
isLogoVisible: true,
|
|
270
|
+
backgroundStyle: {},
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
});
|
|
276
|
+
const migrationData = createMigrationData(brandPageData);
|
|
277
|
+
|
|
278
|
+
const result = await migration08(migrationData, { isServerRender: false });
|
|
279
|
+
|
|
280
|
+
// Should apply fallback logic
|
|
281
|
+
expect(
|
|
282
|
+
(result.brandPageModel.pages[0].contents[0] as LogoContent)
|
|
283
|
+
.logoImageHeight,
|
|
284
|
+
).toBe('15rem');
|
|
285
|
+
expect(
|
|
286
|
+
(result.brandPageModel.pages[0].contents[0] as LogoContent)
|
|
287
|
+
.logoImageWidth,
|
|
288
|
+
).toBe('15rem');
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test('should handle logo template images', async () => {
|
|
292
|
+
const brandPageData = createTestBrandPageData({
|
|
293
|
+
brandPageType: BRAND_PAGE_TYPES.default,
|
|
294
|
+
pages: [
|
|
295
|
+
{
|
|
296
|
+
title: 'Home',
|
|
297
|
+
slug: 'home',
|
|
298
|
+
contents: [
|
|
299
|
+
{
|
|
300
|
+
id: '1',
|
|
301
|
+
type: 'logo',
|
|
302
|
+
logoTemplateImage: { logoTemplateToken: 'template-token' },
|
|
303
|
+
logoImageHeight: '9rem',
|
|
304
|
+
logoImageWidth: '9rem',
|
|
305
|
+
isLogoVisible: true,
|
|
306
|
+
backgroundStyle: {},
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
});
|
|
312
|
+
const migrationData = createMigrationData(brandPageData);
|
|
313
|
+
|
|
314
|
+
// Mock the fabric client response
|
|
315
|
+
const mockFabricClient = FabricRenderClient.getInstance();
|
|
316
|
+
|
|
317
|
+
vi.mocked(
|
|
318
|
+
mockFabricClient.getLogoSvgUrlByLogoTemplateImageAsync,
|
|
319
|
+
).mockResolvedValue({
|
|
320
|
+
width: 200,
|
|
321
|
+
height: 100,
|
|
322
|
+
data: 'test-template-svg-data',
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
const result = await migration08(migrationData, { isServerRender: false });
|
|
326
|
+
|
|
327
|
+
expect(
|
|
328
|
+
mockFabricClient.getLogoSvgUrlByLogoTemplateImageAsync,
|
|
329
|
+
).toHaveBeenCalledWith({
|
|
330
|
+
logoTemplateToken: 'template-token',
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test('should handle error gracefully', async () => {
|
|
335
|
+
const brandPageData = createTestBrandPageData({
|
|
336
|
+
brandPageType: BRAND_PAGE_TYPES.default,
|
|
337
|
+
pages: [
|
|
338
|
+
{
|
|
339
|
+
title: 'Home',
|
|
340
|
+
slug: 'home',
|
|
341
|
+
contents: [
|
|
342
|
+
{
|
|
343
|
+
id: '1',
|
|
344
|
+
type: 'logo',
|
|
345
|
+
logoImage: { logoDraftToken: 'test-token', logoVariation: 0 },
|
|
346
|
+
logoImageHeight: '9rem',
|
|
347
|
+
logoImageWidth: '9rem',
|
|
348
|
+
isLogoVisible: true,
|
|
349
|
+
backgroundStyle: {},
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
});
|
|
355
|
+
const migrationData = createMigrationData(brandPageData);
|
|
356
|
+
|
|
357
|
+
// Mock the fabric client to throw an error
|
|
358
|
+
const mockFabricClient = FabricRenderClient.getInstance();
|
|
359
|
+
|
|
360
|
+
vi.mocked(mockFabricClient.getLogoSvgUrlByLogoImageAsync).mockRejectedValue(
|
|
361
|
+
new Error('API Error'),
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
const result = await migration08(migrationData, { isServerRender: false });
|
|
365
|
+
|
|
366
|
+
expect(result.useOldLogoRenderSize).toBe(true);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
test('should ignore non-logo content', async () => {
|
|
370
|
+
const brandPageData = createTestBrandPageData({
|
|
371
|
+
brandPageType: BRAND_PAGE_TYPES.default,
|
|
372
|
+
pages: [
|
|
373
|
+
{
|
|
374
|
+
title: 'Home',
|
|
375
|
+
slug: 'home',
|
|
376
|
+
contents: [
|
|
377
|
+
{
|
|
378
|
+
id: '1',
|
|
379
|
+
type: 'text',
|
|
380
|
+
text: 'Hello World',
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
id: '2',
|
|
384
|
+
type: 'image',
|
|
385
|
+
imageUrl: 'test-image.jpg',
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
},
|
|
389
|
+
],
|
|
390
|
+
});
|
|
391
|
+
const migrationData = createMigrationData(brandPageData);
|
|
392
|
+
|
|
393
|
+
const result = await migration08(migrationData, { isServerRender: false });
|
|
394
|
+
|
|
395
|
+
expect(result.useOldLogoRenderSize).toBe(false);
|
|
396
|
+
expect(result.brandPageModel.pages[0].contents.length).toBe(2);
|
|
397
|
+
});
|
|
398
|
+
});
|