Skip to content

Commit

Permalink
#25901 Retrieve Contentlet created in Variant in the Palette Sidebar (#…
Browse files Browse the repository at this point in the history
…26338)

* #25901 testing lucent query

* Not include variant filter if the lucene query already is filtering by variant

* Sending Variant attribute

* #25901 handle the variant field

* #25901 remove the default duplicated contentlet in a variant

* #25901 fix comments

* #25901 fix comments

* #25901 fix comments

* fix test

---------

Co-authored-by: freddyucv <[email protected]>
  • Loading branch information
oidacra and freddyDOTCMS authored Oct 12, 2023
1 parent 4538277 commit 534774e
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 20 deletions.
7 changes: 5 additions & 2 deletions core-web/apps/dotcms-ui/proxy-dev.conf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ export default [
'/DotAjaxDirector',
'/contentAsset',
'/application',
'/assets/seo/page-tools.json'
'/assets'
],
target: 'http://localhost:8080',
secure: false,
logLevel: 'debug'
logLevel: 'debug',
pathRewrite: {
'^/assets': '/dotAdmin/assets'
}
}
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@
<div [@inOut]="vm.viewContentlet" (@inOut.done)="onAnimationDone($event)" data-testId="wrapper">
<dot-palette-content-type
#contentTypes
(selected)="switchView($event)"
[items]="vm.contentTypes"
[loading]="vm.loading"
[viewContentlet]="vm.viewContentlet"
(selected)="switchView($event)"
(filter)="filterContentTypes($event)"
></dot-palette-content-type>
(selected)="switchView($event)"></dot-palette-content-type>
<dot-palette-contentlets
#contentlets
[items]="vm.contentlets"
[loading]="vm.loading"
[totalRecords]="vm.totalRecords"
(back)="switchView()"
(filter)="filterContentlets($event)"
(paginate)="paginateContentlets($event)"
></dot-palette-contentlets>
(paginate)="paginateContentlets($event)"></dot-palette-contentlets>
</div>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { DEFAULT_VARIANT_ID, DotCMSContentlet } from '@dotcms/dotcms-models';

const IDENTIFIER = '0af1efad-6f3c-480e-bb91-fe786a4b6dfe';
export const VARIANT_ID_MOCK = 'dotexperiment-3759acc113-variant-1';

export const ContentletWithDuplicatedMock: Array<DotCMSContentlet> = [
{
hostName: 'demo.dotcms.com',
modDate: '2023-10-03 17:47:16.198',
publishDate: '2023-10-03 17:47:16.198',
title: 'Travel Blog Header [MODIFIED]',
body: '<h1>Travel Blog MODIFIED</h1>',
baseType: 'CONTENT',
inode: 'cf2af7da-6968-48ef-97fa-d638ba7def01',
archived: false,
host: '48190c8c-42c4-46af-8d1a-0cd5db894797',
working: true,
locked: false,
stInode: '2a3e91e4-fbbf-4876-8c5b-2233c1739b05',
contentType: 'webPageContent',
live: true,
owner: 'dotcms.org.1',
identifier: IDENTIFIER,
languageId: 1,
url: '/content.5f3ba352-0139-425e-880f-c8bbfafcea7d',
titleImage: 'TITLE_IMAGE_NOT_FOUND',
modUserName: 'Admin User',
hasLiveVersion: true,
folder: 'SYSTEM_FOLDER',
hasTitleImage: false,
sortOrder: 0,
modUser: 'dotcms.org.1',
__icon__: 'contentIcon',
contentTypeIcon: 'wysiwyg',
variant: VARIANT_ID_MOCK
},

{
hostName: 'demo.dotcms.com',
modDate: '2020-09-02 16:45:50.663',
publishDate: '2020-09-02 16:45:50.663',
title: 'Travel Blog Header [Original]',
body: '<h1>Travel Blog ORIGINAL</h1>',
baseType: 'CONTENT',
inode: '782c7e2c-5c95-41fd-83aa-d3ff8cb143d3',
archived: false,
host: '48190c8c-42c4-46af-8d1a-0cd5db894797',
working: true,
locked: false,
stInode: '2a3e91e4-fbbf-4876-8c5b-2233c1739b05',
contentType: 'webPageContent',
live: true,
owner: 'dotcms.org.1',
identifier: IDENTIFIER,
languageId: 1,
url: '/content.5f3ba352-0139-425e-880f-c8bbfafcea7d',
titleImage: 'TITLE_IMAGE_NOT_FOUND',
modUserName: 'Admin User',
hasLiveVersion: true,
folder: 'SYSTEM_FOLDER',
hasTitleImage: false,
sortOrder: 0,
modUser: 'dotcms.org.1',
__icon__: 'contentIcon',
contentTypeIcon: 'wysiwyg',
variant: DEFAULT_VARIANT_ID
}
];

export const NotDuplicatedContentletMock: Array<DotCMSContentlet> = [
{
hostName: 'demo.dotcms.com',
modDate: '2020-09-02 16:45:53.832',
publishDate: '2020-09-02 16:45:53.832',
title: 'Thank You [ORIGINAL]',
body: '<h1 style="text-align: center;">Thank You</h1>\n<p>Thank you for your interest in TravelLux, the industry leader in luxury adventure travel. We have received your information and are reviewing it. One of our team members will reach out to you shortly. If you need immediate assistance please call us at 1-800-LUX-TRAV.</p>\n<div class="hr-logo"></div>\n<p></p>',
baseType: 'CONTENT',
inode: 'b614f0a1-02fd-4a09-b62c-81e7973eeb40',
archived: false,
host: '48190c8c-42c4-46af-8d1a-0cd5db894797',
working: true,
locked: false,
stInode: '2a3e91e4-fbbf-4876-8c5b-2233c1739b05',
contentType: 'webPageContent',
live: true,
owner: 'dotcms.org.1',
identifier: 'e3988576-cf62-437b-ac93-6237baf519c5',
languageId: 1,
url: '/content.c1831446-8eb9-4b15-b7ea-43d6301f51b5',
titleImage: 'TITLE_IMAGE_NOT_FOUND',
modUserName: 'Admin User',
hasLiveVersion: true,
folder: 'SYSTEM_FOLDER',
hasTitleImage: false,
sortOrder: 0,
modUser: 'dotcms.org.1',
__icon__: 'contentIcon',
contentTypeIcon: 'wysiwyg',
variant: DEFAULT_VARIANT_ID
}
];

export const NewVariantContentletMock: Array<DotCMSContentlet> = [
{
hostName: 'demo.dotcms.com',
modDate: '2023-10-04 17:14:25.153',
publishDate: '2023-10-04 17:14:25.153',
title: 'New Variant Contentlet',
body: '<p>TEST Rich 2</p>',
baseType: 'CONTENT',
inode: 'd1fdadf0-2782-4680-986c-caf63b40a787',
archived: false,
host: '48190c8c-42c4-46af-8d1a-0cd5db894797',
working: true,
locked: false,
stInode: '2a3e91e4-fbbf-4876-8c5b-2233c1739b05',
contentType: 'webPageContent',
live: true,
owner: 'dotcms.org.1',
identifier: '7de976503e17c7f51f6b24433187365c',
languageId: 1,
url: '/content.3dd13f81-68a7-4690-ae05-9ce03b830cf2',
titleImage: 'TITLE_IMAGE_NOT_FOUND',
modUserName: 'Admin User',
hasLiveVersion: true,
folder: 'SYSTEM_FOLDER',
hasTitleImage: false,
sortOrder: 0,
modUser: 'dotcms.org.1',
__icon__: 'contentIcon',
contentTypeIcon: 'wysiwyg',
variant: VARIANT_ID_MOCK
}
];
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ import { Observable, of } from 'rxjs';
import { Injectable } from '@angular/core';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';

import { DotContentTypeService, DotESContentService, PaginatorService } from '@dotcms/data-access';
import {
DotContentTypeService,
DotESContentService,
DotSessionStorageService,
PaginatorService
} from '@dotcms/data-access';
import { DotCMSContentlet, DotCMSContentType, ESContent } from '@dotcms/dotcms-models';
import {
ContentletWithDuplicatedMock,
NewVariantContentletMock,
NotDuplicatedContentletMock,
VARIANT_ID_MOCK
} from '@portlets/dot-edit-page/components/dot-palette/mocks/contentlets.mock';

import { DotPaletteStore } from './dot-palette.store';

Expand Down Expand Up @@ -104,11 +115,13 @@ describe('DotPaletteStore', () => {
let paginatorService: PaginatorService;
let dotContentTypeService: DotContentTypeService;
let dotESContentService: DotESContentService;
let dotSessionStorageService: DotSessionStorageService;

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
DotPaletteStore,
DotSessionStorageService,
{ provide: PaginatorService, useClass: MockPaginatorService },
{ provide: DotContentTypeService, useClass: MockContentTypeService },
{ provide: DotESContentService, useClass: MockESPaginatorService }
Expand All @@ -118,6 +131,7 @@ describe('DotPaletteStore', () => {
paginatorService = TestBed.inject(PaginatorService);
dotContentTypeService = TestBed.inject(DotContentTypeService);
dotESContentService = TestBed.inject(DotESContentService);
dotSessionStorageService = TestBed.inject(DotSessionStorageService);
});

// Updaters
Expand Down Expand Up @@ -240,7 +254,7 @@ describe('DotPaletteStore', () => {
] as unknown as DotCMSContentlet[]);
expect(data.filter).toEqual('');
expect(data.loading).toEqual(false);
expect(data.totalRecords).toEqual(20);
expect(data.totalRecords).toEqual(1); // changed due a filter the data in the store and the totalRecords now have the real amount of the array
done();
});
});
Expand Down Expand Up @@ -303,4 +317,87 @@ describe('DotPaletteStore', () => {
expect(dotContentTypeService.filterContentTypes).not.toHaveBeenCalled();
expect(dotContentTypeService.getContentTypes).not.toHaveBeenCalled();
}));

describe('handle variant contentlets', () => {
beforeEach(() => {
spyOn(dotSessionStorageService, 'getVariationId').and.returnValue(VARIANT_ID_MOCK);
});
it('should remove the `DEFAULT` Contentlets and leave the copied', (done) => {
spyOn(dotESContentService, 'get').and.returnValue(
of({
contentTook: 0,
jsonObjectView: {
contentlets: [
...ContentletWithDuplicatedMock,
...NotDuplicatedContentletMock
]
},
queryTook: 1,
resultsSize: 20
})
);

dotPaletteStore.loadContentlets('');

dotPaletteStore.vm$.subscribe(({ contentlets }) => {
expect(contentlets.length).toEqual(2);

const contentlet = contentlets[0] as DotCMSContentlet;
expect(ContentletWithDuplicatedMock[0].inode).toEqual(contentlet.inode);
done();
});
});
it('should leave the created contentled in the variant', (done) => {
spyOn(dotESContentService, 'get').and.returnValue(
of({
contentTook: 0,
jsonObjectView: {
contentlets: [...NotDuplicatedContentletMock, ...NewVariantContentletMock]
},
queryTook: 1,
resultsSize: 20
})
);

dotPaletteStore.loadContentlets('');

dotPaletteStore.vm$.subscribe(({ contentlets }) => {
expect(contentlets.length).toEqual(2);

const contentletsStore = contentlets as DotCMSContentlet[];
expect(NotDuplicatedContentletMock[0].inode).toEqual(contentletsStore[0].inode);
expect(NewVariantContentletMock[0].inode).toEqual(contentletsStore[1].inode);
done();
});
});

it('should leave the created variant contentled and delete the `DEFAULT` Contentlets modified ', (done) => {
spyOn(dotESContentService, 'get').and.returnValue(
of({
contentTook: 0,
jsonObjectView: {
contentlets: [
...ContentletWithDuplicatedMock,
...NotDuplicatedContentletMock,
...NewVariantContentletMock
]
},
queryTook: 1,
resultsSize: 20
})
);

dotPaletteStore.loadContentlets('');

dotPaletteStore.vm$.subscribe(({ contentlets }) => {
expect(contentlets.length).toEqual(3);

const contentletsStore = contentlets as DotCMSContentlet[];
expect(ContentletWithDuplicatedMock[0].inode).toEqual(contentletsStore[0].inode);
expect(NotDuplicatedContentletMock[0].inode).toEqual(contentletsStore[1].inode);
expect(NewVariantContentletMock[0].inode).toEqual(contentletsStore[2].inode);
done();
});
});
});
});
Loading

0 comments on commit 534774e

Please sign in to comment.