@designcrowd/library.brand-page 6.2.1 → 6.2.2
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-CtvPtYF6.js → CreatedOnBrandCrowd-de-de-7P2gNr-R.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-en-us-eGF-EjAX.js → CreatedOnBrandCrowd-en-us-Dl7BymW6.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-es-es-CSemsOtT.js → CreatedOnBrandCrowd-es-es-CO4FvWVw.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-fr-DzylX-AT.js → CreatedOnBrandCrowd-fr-ca-DHNqakQu.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-ca-DzylX-AT.js → CreatedOnBrandCrowd-fr-fr-DHNqakQu.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-pt-QMUxXQsE.js → CreatedOnBrandCrowd-pt-br-CGUC-ZbP.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-br-QMUxXQsE.js → CreatedOnBrandCrowd-pt-pt-CGUC-ZbP.js} +1 -1
- package/lib/src/{CreatedOnDcom-de-de-M7OoJt-1.js → CreatedOnDcom-de-de-Dvds-Vmy.js} +1 -1
- package/lib/src/{CreatedOnDcom-en-us-D7hMM0AI.js → CreatedOnDcom-en-us-fd3C-8Tp.js} +1 -1
- package/lib/src/{CreatedOnDcom-es-es-CLw-BLp2.js → CreatedOnDcom-es-es-DTXZW35-.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-ca-BRu_kmeu.js → CreatedOnDcom-fr-ca-DRCYOKPs.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-fr-IMnEv_yM.js → CreatedOnDcom-fr-fr-DpIB8x2x.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-br-Bt6v1p27.js → CreatedOnDcom-pt-br-Esnxy8wX.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-pt-BVsFJIJg.js → CreatedOnDcom-pt-pt-CaiVHFXR.js} +1 -1
- package/lib/src/brand-page-maker/components/brand-page-maker/BrandPageMaker.mixin.d.ts +7 -1
- package/lib/src/brand-page-maker/components/brandpage-maker-page/BrandPageMakerPage.mixin.d.ts +6 -0
- package/lib/src/brand-page-maker/composables/useEventTracker.d.ts +3 -0
- package/lib/src/brand-page-maker/composables/useEventTracker.js +10 -0
- package/lib/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.js +2 -4
- package/lib/src/{bundled-translations-KY0aSmMp.js → bundled-translations-BYUfWBT3.js} +9 -9
- package/lib/src/{bundled-translations.de-DE-BIFi4bYj.js → bundled-translations.de-DE-MmzUu1tt.js} +13 -13
- package/lib/src/{bundled-translations.es-ES-CHlKuPLO.js → bundled-translations.es-ES-D-tG33XL.js} +1 -1
- package/lib/src/{bundled-translations.fr-CA-DR1fvm8e.js → bundled-translations.fr-CA-CNc1H1h3.js} +1 -1
- package/lib/src/{bundled-translations.fr-FR-DnpWVIQg.js → bundled-translations.fr-FR-DX0-yepT.js} +1 -1
- package/lib/src/{bundled-translations.pt-BR-p8szTOiT.js → bundled-translations.pt-BR-ih1-LRgy.js} +9 -9
- package/lib/src/{bundled-translations.pt-PT-DEk39NhW.js → bundled-translations.pt-PT-Dq2CmD1p.js} +1 -1
- package/lib/src/bundles/bundled-translations.de-DE.json +3 -1
- package/lib/src/bundles/bundled-translations.es-ES.json +3 -1
- package/lib/src/bundles/bundled-translations.fr-CA.json +3 -1
- package/lib/src/bundles/bundled-translations.fr-FR.json +3 -1
- package/lib/src/bundles/bundled-translations.json +3 -1
- package/lib/src/bundles/bundled-translations.pt-BR.json +3 -1
- package/lib/src/bundles/bundled-translations.pt-PT.json +3 -1
- package/lib/src/composables/useTranslate.d.ts +1 -1
- package/lib/src/composables/useTranslate.js +1 -1
- package/lib/src/css/library.brand-page-brandCrowd.min.css +4 -4
- package/lib/src/css/library.brand-page-brandPage.min.css +4 -4
- package/lib/src/css/library.brand-page-designCom.min.css +4 -4
- package/lib/src/css/library.brand-page-preview.min.css +4 -4
- package/lib/src/index.mjs +2 -2
- package/lib/src/{lib-B38VVCSw.js → lib-V7aqfuiB.js} +18106 -17965
- package/lib/src/metadata-builder/builders/item-id-utils.d.ts +2 -0
- package/lib/src/metadata-builder/builders/item-id-utils.js +8 -2
- package/lib/src/shared/content-settings/components/content-settings/ContentSettings.mixin.d.ts +8 -1
- package/lib/src/shared/content-settings/components/content-settings/ReplaceImageSettingsForContent.mixin.d.ts +6 -0
- package/lib/src/shared/content-settings/components/content-settings-item/ContentSettingsItem.mixin.d.ts +1 -0
- package/lib/src/shared/content-settings/components/content-settings-item/ContentSettingsItemField.mixin.d.ts +5 -0
- package/lib/src/shared/content-settings/components/payment-config-field/PaymentConfigField.mixin.d.ts +5 -0
- package/lib/src/shared/ecommerce-settings/util/refreshDuplicatedMetadata.d.ts +9 -1
- package/lib/src/shared/ecommerce-settings/util/refreshDuplicatedMetadata.js +31 -9
- package/lib/src/shared/logo-settings/components/EditLogoSettings.mixin.d.ts +1 -0
- package/lib/src/shared/logo-settings/components/LogoSettings.mixin.d.ts +5 -0
- package/lib/src/shared/page-navigation/store/page-navigation-store.d.ts +2 -1
- package/lib/src/shared/page-navigation/store/page-navigation-store.js +22 -9
- package/lib/src/shared/page-settings/components/new-page-modal/NewPageModal.mixin.d.ts +7 -1
- package/lib/src/shared/page-settings/components/page-settings/PageSettings.mixin.d.ts +10 -1
- package/lib/src/shared/page-settings/components/page-settings/PageSettings.mixin.js +12 -35
- package/lib/src/shared/page-settings/components/page-settings-section-styles/PageSettingsSectionStyles.mixin.d.ts +6 -0
- package/lib/src/shared/page-settings/duplicate-page.util.d.ts +4 -0
- package/lib/src/shared/page-settings/duplicate-page.util.js +82 -0
- package/lib/src/shared/page-settings/models.d.ts +1 -0
- package/lib/src/shared/page-settings/store/page-settings-store.d.ts +5 -0
- package/lib/src/shared/page-settings/store/page-settings-store.js +90 -7
- package/lib/src/shared/page-settings/utils.d.ts +3 -0
- package/lib/src/shared/page-settings/utils.js +6 -0
- package/lib/src/shared/publish-brand-page-with-state/PublishBrandPageModalWithState.mixin.d.ts +1 -0
- package/lib/src/shared/side-bar/components/SideBarTabButton.mixin.d.ts +1 -0
- package/lib/src/shared/style-settings/components/StyleSettings.mixin.d.ts +1 -0
- package/lib/src/shared/template-settings/components/TemplatesSettings.mixin.d.ts +1 -0
- package/lib/src/tracker.mjs +1 -1
- package/lib/src/{useEventTracker-C5Ql5p7u.js → useEventTracker-DwPTmzpa.js} +13 -3
- package/package.json +1 -1
- package/src/brand-page-maker/composables/useEventTracker.ts +13 -0
- package/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.ts +2 -4
- package/src/bundles/bundled-translations.de-DE.json +3 -1
- package/src/bundles/bundled-translations.es-ES.json +3 -1
- package/src/bundles/bundled-translations.fr-CA.json +3 -1
- package/src/bundles/bundled-translations.fr-FR.json +3 -1
- package/src/bundles/bundled-translations.json +3 -1
- package/src/bundles/bundled-translations.pt-BR.json +3 -1
- package/src/bundles/bundled-translations.pt-PT.json +3 -1
- package/src/composables/useTranslate.ts +2 -1
- package/src/metadata-builder/builders/item-id-utils.ts +9 -2
- package/src/shared/ecommerce-settings/components/product-config-field/ProductConfigOption.vue +0 -2
- package/src/shared/ecommerce-settings/util/refreshDuplicatedMetadata.ts +32 -10
- package/src/shared/page-navigation/store/page-navigation-store.ts +41 -13
- package/src/shared/page-settings/components/page-settings/NestedDraggable.vue +3 -0
- package/src/shared/page-settings/components/page-settings/PageElement.vue +2 -0
- package/src/shared/page-settings/components/page-settings/PageSettingMenu.test.ts +105 -0
- package/src/shared/page-settings/components/page-settings/PageSettingMenu.vue +16 -0
- package/src/shared/page-settings/components/page-settings/PageSettings.duplicate.test.ts +108 -0
- package/src/shared/page-settings/components/page-settings/PageSettings.mixin.ts +22 -50
- package/src/shared/page-settings/components/page-settings/PageSettings.vue +1 -0
- package/src/shared/page-settings/components/page-settings/i18n/page-settings.de-DE.json +3 -1
- package/src/shared/page-settings/components/page-settings/i18n/page-settings.es-ES.json +3 -1
- package/src/shared/page-settings/components/page-settings/i18n/page-settings.fr-CA.json +3 -1
- package/src/shared/page-settings/components/page-settings/i18n/page-settings.fr-FR.json +3 -1
- package/src/shared/page-settings/components/page-settings/i18n/page-settings.json +3 -1
- package/src/shared/page-settings/components/page-settings/i18n/page-settings.pt-BR.json +3 -1
- package/src/shared/page-settings/components/page-settings/i18n/page-settings.pt-PT.json +3 -1
- package/src/shared/page-settings/duplicate-page.util.test.ts +382 -0
- package/src/shared/page-settings/duplicate-page.util.ts +124 -0
- package/src/shared/page-settings/models.ts +1 -0
- package/src/shared/page-settings/store/page-settings-store.test.ts +512 -1
- package/src/shared/page-settings/store/page-settings-store.ts +145 -11
- package/src/shared/page-settings/utils.ts +10 -0
|
@@ -3,13 +3,14 @@ import type Vue from 'vue';
|
|
|
3
3
|
import { createApp } from 'vue';
|
|
4
4
|
import { createPinia, setActivePinia } from 'pinia';
|
|
5
5
|
import type { ContentPage } from '../models';
|
|
6
|
-
import type { TextContent } from '@brand-page';
|
|
6
|
+
import type { Content, TextContent } from '@brand-page';
|
|
7
7
|
import type { ContentItem } from '../../content-settings/models';
|
|
8
8
|
import {
|
|
9
9
|
UNLIMITED_MAX_NUM_OF_PAGES,
|
|
10
10
|
useBrandPageContainerStore,
|
|
11
11
|
useBrandPageMakerStore,
|
|
12
12
|
useBrandPageMakerUserStore,
|
|
13
|
+
useUiStore,
|
|
13
14
|
} from '@brand-page-maker/stores';
|
|
14
15
|
import {
|
|
15
16
|
INITIALISE_PAYLOAD,
|
|
@@ -19,6 +20,10 @@ import { useUiPageSettingsStore } from './index';
|
|
|
19
20
|
import { FabricRenderClient } from '../../../clients/fabric-render-client';
|
|
20
21
|
import { setLocaleAsync } from '@src/composables/useTranslate';
|
|
21
22
|
import { usePageNavigationStore } from '@src/shared/page-navigation/store/page-navigation-store';
|
|
23
|
+
import { useShopConfigStore } from '@shared/ecommerce-settings/store/shop-settings-store';
|
|
24
|
+
import { useEventTracker } from '@brand-page-maker/composables/useEventTracker';
|
|
25
|
+
import { useHistoryStore } from '@brand-page-maker/stores/history/history-store';
|
|
26
|
+
import { toPageModels } from '../utils';
|
|
22
27
|
|
|
23
28
|
vi.mock('../../../clients/brand-page-client', () => ({
|
|
24
29
|
default: {
|
|
@@ -371,3 +376,509 @@ describe('page store module', () => {
|
|
|
371
376
|
});
|
|
372
377
|
});
|
|
373
378
|
});
|
|
379
|
+
|
|
380
|
+
describe('duplicatePage', () => {
|
|
381
|
+
const initialiseAsync = async () => {
|
|
382
|
+
const store = useBrandPageMakerStore();
|
|
383
|
+
const userStore = useBrandPageMakerUserStore();
|
|
384
|
+
const pageSettingsStore = useUiPageSettingsStore();
|
|
385
|
+
|
|
386
|
+
userStore.setUserState({
|
|
387
|
+
features: {
|
|
388
|
+
...USER_FEATURES,
|
|
389
|
+
maxNumOfPages: UNLIMITED_MAX_NUM_OF_PAGES,
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// No setPages here: injecting route-less pages would leave `pages` and
|
|
394
|
+
// `nav.orders` describing different sites, and duplicatePage re-derives
|
|
395
|
+
// one from the other.
|
|
396
|
+
await store.initialise(INITIALISE_PAYLOAD);
|
|
397
|
+
|
|
398
|
+
return {
|
|
399
|
+
pageSettingsStore,
|
|
400
|
+
pageNavigationStore: usePageNavigationStore(),
|
|
401
|
+
userStore,
|
|
402
|
+
};
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
beforeAll(async () => {
|
|
406
|
+
FabricRenderClient.setInstance({ baseUrl: 'http://localhost:3000' });
|
|
407
|
+
|
|
408
|
+
setActivePinia(createPinia());
|
|
409
|
+
|
|
410
|
+
await setLocaleAsync('en-US');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
test('inserts the copy directly below the source page', async () => {
|
|
414
|
+
const { pageSettingsStore } = await initialiseAsync();
|
|
415
|
+
|
|
416
|
+
const source = pageSettingsStore.addNewPage({ title: 'About' });
|
|
417
|
+
|
|
418
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
419
|
+
|
|
420
|
+
const ids = pageSettingsStore.pages.map((p) => p.id);
|
|
421
|
+
|
|
422
|
+
expect(ids.indexOf(copy!.id)).toEqual(ids.indexOf(source.id) + 1);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
test('inserts the copy directly below the source route in orders', async () => {
|
|
426
|
+
const { pageSettingsStore, pageNavigationStore } = await initialiseAsync();
|
|
427
|
+
|
|
428
|
+
const source = pageSettingsStore.addNewPage({ title: 'About' });
|
|
429
|
+
const sourceRoute = pageNavigationStore.routes.find(
|
|
430
|
+
(r) => r.pageId === source.id,
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
434
|
+
|
|
435
|
+
const copyRoute = pageNavigationStore.routes.find(
|
|
436
|
+
(r) => r.pageId === copy?.id,
|
|
437
|
+
);
|
|
438
|
+
const sourceOrderIndex = pageNavigationStore.orders.findIndex(
|
|
439
|
+
(o) => o.routeId === sourceRoute?.id,
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
expect(pageNavigationStore.orders[sourceOrderIndex + 1].routeId).toEqual(
|
|
443
|
+
copyRoute?.id,
|
|
444
|
+
);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
test('names the copy after the source and derives its slug', async () => {
|
|
448
|
+
const { pageSettingsStore, pageNavigationStore } = await initialiseAsync();
|
|
449
|
+
|
|
450
|
+
const source = pageSettingsStore.addNewPage({ title: 'About' });
|
|
451
|
+
|
|
452
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
453
|
+
|
|
454
|
+
expect(copy?.title).toEqual('About Copy');
|
|
455
|
+
expect(
|
|
456
|
+
pageNavigationStore.routes.find((r) => r.pageId === copy?.id)?.pageSlug,
|
|
457
|
+
).toEqual('about-copy');
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
test('indexes the title when the same page is duplicated twice', async () => {
|
|
461
|
+
const { pageSettingsStore } = await initialiseAsync();
|
|
462
|
+
|
|
463
|
+
const source = pageSettingsStore.addNewPage({ title: 'About' });
|
|
464
|
+
|
|
465
|
+
await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
466
|
+
|
|
467
|
+
const second = await pageSettingsStore.duplicatePage({
|
|
468
|
+
pageId: source.id,
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
expect(second?.title).toEqual('About Copy 2');
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
test('deep clones contents with fresh ids', async () => {
|
|
475
|
+
const { pageSettingsStore } = await initialiseAsync();
|
|
476
|
+
|
|
477
|
+
const source = pageSettingsStore.addNewPage({ title: 'About' });
|
|
478
|
+
|
|
479
|
+
pageSettingsStore.setPageContents({
|
|
480
|
+
pageId: source.id,
|
|
481
|
+
contents: [
|
|
482
|
+
{
|
|
483
|
+
id: 'content-1',
|
|
484
|
+
type: 'text',
|
|
485
|
+
settings: { content: { id: 'content-1', text: 'hello' } },
|
|
486
|
+
} as unknown as ContentItem<TextContent>,
|
|
487
|
+
],
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
491
|
+
|
|
492
|
+
expect(copy?.contents).toHaveLength(1);
|
|
493
|
+
expect(copy?.contents[0].id).not.toEqual('content-1');
|
|
494
|
+
expect(copy?.contents[0].id).toEqual(copy?.contents[0].settings.content.id);
|
|
495
|
+
|
|
496
|
+
const sourcePage = pageSettingsStore.pages.find((p) => p.id === source.id);
|
|
497
|
+
|
|
498
|
+
expect(sourcePage?.contents[0].id).toEqual('content-1');
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
test('keeps a duplicated sub-page under the same parent', async () => {
|
|
502
|
+
const { pageSettingsStore, pageNavigationStore } = await initialiseAsync();
|
|
503
|
+
|
|
504
|
+
const parent = pageSettingsStore.addNewPage({ title: 'Portfolio' });
|
|
505
|
+
const child = pageSettingsStore.addNewPage({
|
|
506
|
+
title: 'Portfolio 1',
|
|
507
|
+
newPageParentId: parent.id,
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: child.id });
|
|
511
|
+
|
|
512
|
+
expect(copy?.title).toEqual('Portfolio 1 Copy');
|
|
513
|
+
expect(
|
|
514
|
+
pageNavigationStore.getParentRouteIdForPage(copy?.id as string),
|
|
515
|
+
).toEqual(pageNavigationStore.getParentRouteIdForPage(child.id));
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
test('duplicating a parent copies only the parent', async () => {
|
|
519
|
+
const { pageSettingsStore, pageNavigationStore } = await initialiseAsync();
|
|
520
|
+
|
|
521
|
+
const parent = pageSettingsStore.addNewPage({ title: 'Portfolio' });
|
|
522
|
+
|
|
523
|
+
pageSettingsStore.addNewPage({
|
|
524
|
+
title: 'Portfolio 1',
|
|
525
|
+
newPageParentId: parent.id,
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: parent.id });
|
|
529
|
+
|
|
530
|
+
const copyRoute = pageNavigationStore.routes.find(
|
|
531
|
+
(r) => r.pageId === copy?.id,
|
|
532
|
+
);
|
|
533
|
+
const copyOrder = pageNavigationStore.orders.find(
|
|
534
|
+
(o) => o.routeId === copyRoute?.id,
|
|
535
|
+
);
|
|
536
|
+
|
|
537
|
+
expect(copyOrder?.subRoutes).toEqual([]);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
test("a parent copy is the source's next sibling in orders", async () => {
|
|
541
|
+
const { pageSettingsStore, pageNavigationStore } = await initialiseAsync();
|
|
542
|
+
|
|
543
|
+
const parent = pageSettingsStore.addNewPage({ title: 'Portfolio' });
|
|
544
|
+
|
|
545
|
+
pageSettingsStore.addNewPage({
|
|
546
|
+
title: 'Portfolio 1',
|
|
547
|
+
newPageParentId: parent.id,
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
const parentRoute = pageNavigationStore.routes.find(
|
|
551
|
+
(r) => r.pageId === parent.id,
|
|
552
|
+
);
|
|
553
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: parent.id });
|
|
554
|
+
const copyRoute = pageNavigationStore.routes.find(
|
|
555
|
+
(r) => r.pageId === copy?.id,
|
|
556
|
+
);
|
|
557
|
+
|
|
558
|
+
const parentOrderIndex = pageNavigationStore.orders.findIndex(
|
|
559
|
+
(o) => o.routeId === parentRoute?.id,
|
|
560
|
+
);
|
|
561
|
+
|
|
562
|
+
expect(pageNavigationStore.orders[parentOrderIndex + 1].routeId).toEqual(
|
|
563
|
+
copyRoute?.id,
|
|
564
|
+
);
|
|
565
|
+
|
|
566
|
+
// pages is flat and must stay depth-first with orders, so the copy sits
|
|
567
|
+
// after the source's sub-tree - not between the parent and its children.
|
|
568
|
+
const titles = pageSettingsStore.pages.map((p) => p.title);
|
|
569
|
+
|
|
570
|
+
expect(titles.indexOf('Portfolio Copy')).toEqual(
|
|
571
|
+
titles.indexOf('Portfolio 1') + 1,
|
|
572
|
+
);
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
test('a hidden page yields a hidden copy that stays beside it', async () => {
|
|
576
|
+
const { pageSettingsStore, pageNavigationStore } = await initialiseAsync();
|
|
577
|
+
|
|
578
|
+
const source = pageSettingsStore.addNewPage({ title: 'About' });
|
|
579
|
+
const sourceRoute = pageNavigationStore.routes.find(
|
|
580
|
+
(r) => r.pageId === source.id,
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
pageSettingsStore.setPageVisibility({ isHidden: true, pageId: source.id });
|
|
584
|
+
pageNavigationStore.updateRouteVisibility(sourceRoute?.id as string, true);
|
|
585
|
+
|
|
586
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
587
|
+
|
|
588
|
+
const copyRoute = pageNavigationStore.routes.find(
|
|
589
|
+
(r) => r.pageId === copy?.id,
|
|
590
|
+
);
|
|
591
|
+
|
|
592
|
+
expect(copy?.isHidden).toBe(true);
|
|
593
|
+
expect(copyRoute?.isHidden).toBe(true);
|
|
594
|
+
|
|
595
|
+
// reorderVisibleAndHiddenRoutes partitions root orders by visibility, so a
|
|
596
|
+
// visible copy of a hidden page would be pulled away from its source.
|
|
597
|
+
const sourceOrderIndex = pageNavigationStore.orders.findIndex(
|
|
598
|
+
(o) => o.routeId === sourceRoute?.id,
|
|
599
|
+
);
|
|
600
|
+
|
|
601
|
+
expect(pageNavigationStore.orders[sourceOrderIndex + 1].routeId).toEqual(
|
|
602
|
+
copyRoute?.id,
|
|
603
|
+
);
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
test('makes the copy the active page', async () => {
|
|
607
|
+
const { pageSettingsStore, pageNavigationStore } = await initialiseAsync();
|
|
608
|
+
|
|
609
|
+
const source = pageSettingsStore.addNewPage({ title: 'About' });
|
|
610
|
+
|
|
611
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
612
|
+
|
|
613
|
+
expect(pageNavigationStore.activePageId).toEqual(copy?.id);
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
test('at the page limit adds nothing and attributes the upsell to duplicate_page', async () => {
|
|
617
|
+
const { pageSettingsStore, userStore } = await initialiseAsync();
|
|
618
|
+
|
|
619
|
+
userStore.setUserState({
|
|
620
|
+
features: {
|
|
621
|
+
...USER_FEATURES,
|
|
622
|
+
maxNumOfPages: pageSettingsStore.pages.length,
|
|
623
|
+
},
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
const pageCount = pageSettingsStore.pages.length;
|
|
627
|
+
|
|
628
|
+
const uiStore = useUiStore();
|
|
629
|
+
const modalSpy = vi
|
|
630
|
+
.spyOn(uiStore, 'showUpgradeModalAndSaveAsync')
|
|
631
|
+
.mockResolvedValue(undefined as never);
|
|
632
|
+
|
|
633
|
+
const copy = await pageSettingsStore.duplicatePage({
|
|
634
|
+
pageId: pageSettingsStore.pages[0].id,
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
expect(copy).toBeUndefined();
|
|
638
|
+
expect(pageSettingsStore.pages).toHaveLength(pageCount);
|
|
639
|
+
expect(modalSpy).toHaveBeenCalled();
|
|
640
|
+
|
|
641
|
+
// Attribution is the reason DUPLICATE_PAGE exists - without this the funnel
|
|
642
|
+
// can silently regress to add_new_page and still look fine. The bridge
|
|
643
|
+
// state is module-level, so it is read back through a published event.
|
|
644
|
+
const eventTracker = useEventTracker();
|
|
645
|
+
const events: { eventProps: { cta_location?: string } }[] = [];
|
|
646
|
+
|
|
647
|
+
eventTracker.subscribe((e) => events.push(e));
|
|
648
|
+
// sendUpsellOpenEvent would overwrite cta_location with its own optional arg.
|
|
649
|
+
eventTracker.sendUpsellContinuationEvent('exit');
|
|
650
|
+
|
|
651
|
+
expect(events[events.length - 1]?.eventProps.cta_location).toEqual(
|
|
652
|
+
'duplicate_page',
|
|
653
|
+
);
|
|
654
|
+
|
|
655
|
+
modalSpy.mockRestore();
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
test("the copy's page and nav route both live in brandPageData", async () => {
|
|
659
|
+
// Undo restores brandPageData wholesale, so anything not in it survives an
|
|
660
|
+
// undo. Both halves of a duplicate have to be in there or undo would drop
|
|
661
|
+
// the page and strand its nav entry.
|
|
662
|
+
const { pageSettingsStore } = await initialiseAsync();
|
|
663
|
+
const makerStore = useBrandPageMakerStore();
|
|
664
|
+
|
|
665
|
+
const source = pageSettingsStore.addNewPage({ title: 'About' });
|
|
666
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
667
|
+
|
|
668
|
+
const snapshot = makerStore.brandPageData;
|
|
669
|
+
|
|
670
|
+
expect(snapshot.pages.some((p) => p.id === copy?.id)).toBe(true);
|
|
671
|
+
expect(snapshot.nav.routes.some((r) => r.pageId === copy?.id)).toBe(true);
|
|
672
|
+
expect(
|
|
673
|
+
snapshot.nav.orders.some((o) =>
|
|
674
|
+
snapshot.nav.routes.some(
|
|
675
|
+
(r) => r.id === o.routeId && r.pageId === copy?.id,
|
|
676
|
+
),
|
|
677
|
+
),
|
|
678
|
+
).toBe(true);
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
test("deleting the copy's product leaves the source's product alone", async () => {
|
|
682
|
+
// The consequence the id rotation exists to prevent. `deleteProduct` filters
|
|
683
|
+
// the site-wide catalogue BY ID, so a copy that kept the source's ids would
|
|
684
|
+
// take the original's row down with it - silently, until the next save.
|
|
685
|
+
const { pageSettingsStore } = await initialiseAsync();
|
|
686
|
+
const shopConfigStore = useShopConfigStore();
|
|
687
|
+
|
|
688
|
+
const source = pageSettingsStore.addNewPage({ title: 'Shop' });
|
|
689
|
+
|
|
690
|
+
pageSettingsStore.setPageContents({
|
|
691
|
+
pageId: source.id,
|
|
692
|
+
contents: [
|
|
693
|
+
{
|
|
694
|
+
id: 'shop-1',
|
|
695
|
+
type: 'shop-section',
|
|
696
|
+
settings: {
|
|
697
|
+
content: {
|
|
698
|
+
id: 'shop-1',
|
|
699
|
+
type: 'shop-section',
|
|
700
|
+
products: [
|
|
701
|
+
{ id: 'product-1', name: 'Latte', variant: [], skus: [] },
|
|
702
|
+
],
|
|
703
|
+
shopPaymentConfig: { paymentConfig: { id: 'stripe-1' } },
|
|
704
|
+
},
|
|
705
|
+
},
|
|
706
|
+
} as unknown as ContentItem<Content>,
|
|
707
|
+
],
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
shopConfigStore.initialiseShopStore({
|
|
711
|
+
paymentConfig: { id: 'stripe-1' } as never,
|
|
712
|
+
pages: toPageModels(pageSettingsStore.pages) as never,
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
716
|
+
|
|
717
|
+
const copyProductId = (
|
|
718
|
+
copy?.contents[0].settings.content as unknown as {
|
|
719
|
+
products: { id: string }[];
|
|
720
|
+
}
|
|
721
|
+
).products[0].id;
|
|
722
|
+
|
|
723
|
+
shopConfigStore.deleteProduct(copyProductId);
|
|
724
|
+
|
|
725
|
+
expect(shopConfigStore.products.map((p) => p.id)).toEqual(['product-1']);
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
test('adds the copy shop products to the site-wide catalogue', async () => {
|
|
729
|
+
// The catalogue is derived from the shop blocks and is what the save
|
|
730
|
+
// upserts. Without a re-derive the copy's fresh product ids never reach the
|
|
731
|
+
// backend and checkout cannot resolve them on the copied page.
|
|
732
|
+
const { pageSettingsStore } = await initialiseAsync();
|
|
733
|
+
const shopConfigStore = useShopConfigStore();
|
|
734
|
+
|
|
735
|
+
const source = pageSettingsStore.addNewPage({ title: 'Shop' });
|
|
736
|
+
|
|
737
|
+
pageSettingsStore.setPageContents({
|
|
738
|
+
pageId: source.id,
|
|
739
|
+
contents: [
|
|
740
|
+
{
|
|
741
|
+
id: 'shop-1',
|
|
742
|
+
type: 'shop-section',
|
|
743
|
+
settings: {
|
|
744
|
+
content: {
|
|
745
|
+
id: 'shop-1',
|
|
746
|
+
type: 'shop-section',
|
|
747
|
+
products: [
|
|
748
|
+
{ id: 'product-1', name: 'Latte', variant: [], skus: [] },
|
|
749
|
+
],
|
|
750
|
+
shopPaymentConfig: { paymentConfig: { id: 'stripe-1' } },
|
|
751
|
+
},
|
|
752
|
+
},
|
|
753
|
+
} as unknown as ContentItem<Content>,
|
|
754
|
+
],
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
shopConfigStore.initialiseShopStore({
|
|
758
|
+
paymentConfig: { id: 'stripe-1' } as never,
|
|
759
|
+
pages: toPageModels(pageSettingsStore.pages) as never,
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
expect(shopConfigStore.products).toHaveLength(1);
|
|
763
|
+
|
|
764
|
+
await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
765
|
+
|
|
766
|
+
expect(shopConfigStore.products).toHaveLength(2);
|
|
767
|
+
|
|
768
|
+
const ids = shopConfigStore.products.map((p) => p.id);
|
|
769
|
+
|
|
770
|
+
expect(new Set(ids).size).toBe(2);
|
|
771
|
+
expect(shopConfigStore.paymentConfig?.id).toEqual('stripe-1');
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
test('undo removes both halves of a duplicate', async () => {
|
|
775
|
+
// duplicatePage writes to two stores - the page into page-settings, the
|
|
776
|
+
// route into page-navigation. A snapshot that caught only one would leave
|
|
777
|
+
// an orphan behind on undo.
|
|
778
|
+
const { pageSettingsStore, pageNavigationStore } = await initialiseAsync();
|
|
779
|
+
const historyStore = useHistoryStore();
|
|
780
|
+
|
|
781
|
+
const source = pageSettingsStore.addNewPage({ title: 'About' });
|
|
782
|
+
|
|
783
|
+
historyStore.captureBaseline();
|
|
784
|
+
|
|
785
|
+
const copy = await pageSettingsStore.duplicatePage({ pageId: source.id });
|
|
786
|
+
|
|
787
|
+
historyStore.capture({ source: 'manual_edit', actor: 'user' });
|
|
788
|
+
|
|
789
|
+
await historyStore.undo();
|
|
790
|
+
|
|
791
|
+
expect(pageSettingsStore.pages.map((p) => p.id)).not.toContain(copy?.id);
|
|
792
|
+
expect(pageNavigationStore.routes.some((r) => r.pageId === copy?.id)).toBe(
|
|
793
|
+
false,
|
|
794
|
+
);
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
test('is a no-op for an unknown page id', async () => {
|
|
798
|
+
const { pageSettingsStore } = await initialiseAsync();
|
|
799
|
+
|
|
800
|
+
const pageCount = pageSettingsStore.pages.length;
|
|
801
|
+
|
|
802
|
+
const copy = await pageSettingsStore.duplicatePage({
|
|
803
|
+
pageId: 'does-not-exist',
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
expect(copy).toBeUndefined();
|
|
807
|
+
expect(pageSettingsStore.pages).toHaveLength(pageCount);
|
|
808
|
+
});
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
describe('syncPagesWithOrders', () => {
|
|
812
|
+
const initialiseAsync = async () => {
|
|
813
|
+
const store = useBrandPageMakerStore();
|
|
814
|
+
const userStore = useBrandPageMakerUserStore();
|
|
815
|
+
const pageSettingsStore = useUiPageSettingsStore();
|
|
816
|
+
|
|
817
|
+
userStore.setUserState({
|
|
818
|
+
features: {
|
|
819
|
+
...USER_FEATURES,
|
|
820
|
+
maxNumOfPages: UNLIMITED_MAX_NUM_OF_PAGES,
|
|
821
|
+
},
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
await store.initialise(INITIALISE_PAYLOAD);
|
|
825
|
+
|
|
826
|
+
return { pageSettingsStore, pageNavigationStore: usePageNavigationStore() };
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
beforeAll(async () => {
|
|
830
|
+
FabricRenderClient.setInstance({ baseUrl: 'http://localhost:3000' });
|
|
831
|
+
|
|
832
|
+
setActivePinia(createPinia());
|
|
833
|
+
|
|
834
|
+
await setLocaleAsync('en-US');
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
test('reorders pages to match the order of their routes', async () => {
|
|
838
|
+
const { pageSettingsStore, pageNavigationStore } = await initialiseAsync();
|
|
839
|
+
|
|
840
|
+
pageSettingsStore.addNewPage({ title: 'About' });
|
|
841
|
+
pageSettingsStore.addNewPage({ title: 'Contact' });
|
|
842
|
+
|
|
843
|
+
pageNavigationStore.orders.reverse();
|
|
844
|
+
|
|
845
|
+
pageSettingsStore.syncPagesWithOrders();
|
|
846
|
+
|
|
847
|
+
const orderedPageIds = pageNavigationStore.orders.map(
|
|
848
|
+
(order) =>
|
|
849
|
+
pageNavigationStore.routes.find((r) => r.id === order.routeId)?.pageId,
|
|
850
|
+
);
|
|
851
|
+
|
|
852
|
+
expect(pageSettingsStore.pages.map((p) => p.id)).toEqual(orderedPageIds);
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
test('keeps a page that has no route yet', async () => {
|
|
856
|
+
const { pageSettingsStore } = await initialiseAsync();
|
|
857
|
+
|
|
858
|
+
const orphan = { ...pageSettingsStore.pages[0], id: 'no-route-yet' };
|
|
859
|
+
|
|
860
|
+
pageSettingsStore.setPages({
|
|
861
|
+
pages: [...pageSettingsStore.pages, orphan],
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
pageSettingsStore.syncPagesWithOrders();
|
|
865
|
+
|
|
866
|
+
expect(pageSettingsStore.pages.map((p) => p.id)).toContain('no-route-yet');
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
test('leaves pages untouched when no route resolves to a page', async () => {
|
|
870
|
+
const { pageSettingsStore, pageNavigationStore } = await initialiseAsync();
|
|
871
|
+
|
|
872
|
+
pageSettingsStore.addNewPage({ title: 'About' });
|
|
873
|
+
|
|
874
|
+
const before = pageSettingsStore.pages.map((p) => p.id);
|
|
875
|
+
|
|
876
|
+
// Mid-flight state: orders exist but none of them names a page yet.
|
|
877
|
+
// Re-deriving from that would wipe the site.
|
|
878
|
+
pageNavigationStore.routes = [];
|
|
879
|
+
|
|
880
|
+
pageSettingsStore.syncPagesWithOrders();
|
|
881
|
+
|
|
882
|
+
expect(pageSettingsStore.pages.map((p) => p.id)).toEqual(before);
|
|
883
|
+
});
|
|
884
|
+
});
|