Skip to content

Commit

Permalink
fix: ensure retrieval and deployment of views with screen aware varia…
Browse files Browse the repository at this point in the history
…nts (#930)

Signed-off-by: adityabisht31 <aditya.bisht@salesforce.com>
  • Loading branch information
adityabisht31 authored Apr 6, 2023
1 parent bac3cae commit ae6bb43
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/resolve/adapters/digitalExperienceSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ import { BundleSourceAdapter } from './bundleSourceAdapter';
* | | | ├── _meta.json
* | | | ├── content.json
* | | | ├── ar.json
* | | ├── view3/
* | | | ├── _meta.json
* | | | ├── content.json
* | | | ├── mobile/
* | | | | ├──mobile.json
* | | | ├── tablet/
* | | | | ├──tablet.json
* | ├── foos.digitalExperience-meta.xml
* content/
* ├── bars/
Expand All @@ -58,7 +65,20 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
if (this.isBundleType()) {
return;
}
return dirname(path);
const pathToContent = dirname(path);
const parts = pathToContent.split(sep);
/* Handle mobile or tablet variants.Eg- digitalExperiences/site/lwr11/sfdc_cms__view/home/mobile/mobile.json
Go back to one level in that case
Bundle hierarchy baseType/spaceApiName/contentType/contentApiName/variantFolders/file */
const digitalExperiencesIndex = parts.indexOf('digitalExperiences');
if (digitalExperiencesIndex > -1) {
const depth = parts.length - digitalExperiencesIndex - 1;
if (depth === digitalExperienceBundleWithVariantsDepth) {
parts.pop();
return parts.join(sep);
}
}
return pathToContent;
}

protected populate(trigger: string, component?: SourceComponent): SourceComponent {
Expand Down Expand Up @@ -131,3 +151,6 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
* @returns name of type/apiName format
*/
const calculateNameFromPath = (contentPath: string): string => `${parentName(contentPath)}/${baseName(contentPath)}`;

// Bundle hierarchy baseType/spaceApiName/contentType/contentApiName/variantFolders/file
const digitalExperienceBundleWithVariantsDepth = 5;
17 changes: 17 additions & 0 deletions test/resolve/adapters/digitalExperienceSourceAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ describe('DigitalExperienceSourceAdapter', () => {

const HOME_VIEW_NAME = 'sfdc_cms__view/home';
const HOME_VIEW_PATH = join(BUNDLE_PATH, 'sfdc_cms__view', 'home');
const HOME_VIEW_MOBILE_PATH = join(HOME_VIEW_PATH, 'mobile');
const HOME_VIEW_TABLET_PATH = join(HOME_VIEW_PATH, 'tablet');

const HOME_VIEW_CONTENT_FILE = join(HOME_VIEW_PATH, 'content.json');
const HOME_VIEW_META_FILE = join(HOME_VIEW_PATH, DE_METAFILE);
const HOME_VIEW_FRENCH_VARIANT_FILE = join(HOME_VIEW_PATH, 'fr.json');
const HOME_VIEW_MOBILE_VARIANT_FILE = join(HOME_VIEW_MOBILE_PATH, 'mobile.json');
const HOME_VIEW_TABLET_VARIANT_FILE = join(HOME_VIEW_TABLET_PATH, 'tablet.json');

const registryAccess = new RegistryAccess();
const forceIgnore = new ForceIgnore();
Expand All @@ -31,6 +36,8 @@ describe('DigitalExperienceSourceAdapter', () => {
HOME_VIEW_CONTENT_FILE,
HOME_VIEW_META_FILE,
HOME_VIEW_FRENCH_VARIANT_FILE,
HOME_VIEW_MOBILE_VARIANT_FILE,
HOME_VIEW_TABLET_VARIANT_FILE,
]);

const bundleAdapter = new DigitalExperienceSourceAdapter(
Expand Down Expand Up @@ -67,6 +74,11 @@ describe('DigitalExperienceSourceAdapter', () => {
expect(bundleAdapter.getComponent(HOME_VIEW_FRENCH_VARIANT_FILE)).to.deep.equal(component);
});

it('should return a SourceComponent for mobile and tablet variant json', () => {
expect(bundleAdapter.getComponent(HOME_VIEW_MOBILE_VARIANT_FILE)).to.deep.equal(component);
expect(bundleAdapter.getComponent(HOME_VIEW_TABLET_VARIANT_FILE)).to.deep.equal(component);
});

it('should return a SourceComponent when a bundle path is provided', () => {
expect(bundleAdapter.getComponent(HOME_VIEW_PATH)).to.deep.equal(component);
expect(bundleAdapter.getComponent(BUNDLE_PATH)).to.deep.equal(component);
Expand Down Expand Up @@ -100,5 +112,10 @@ describe('DigitalExperienceSourceAdapter', () => {
expect(digitalExperienceAdapter.getComponent(HOME_VIEW_META_FILE)).to.deep.equal(component);
expect(digitalExperienceAdapter.getComponent(HOME_VIEW_FRENCH_VARIANT_FILE)).to.deep.equal(component);
});

it('should return a SourceComponent for mobile and tablet variant json', () => {
expect(digitalExperienceAdapter.getComponent(HOME_VIEW_MOBILE_VARIANT_FILE)).to.deep.equal(component);
expect(digitalExperienceAdapter.getComponent(HOME_VIEW_TABLET_VARIANT_FILE)).to.deep.equal(component);
});
});
});

0 comments on commit ae6bb43

Please sign in to comment.