Skip to content

Commit

Permalink
fix: resolve CustomFieldTranslations properly (#461)
Browse files Browse the repository at this point in the history
Co-authored-by: Willie Ruemmele <willieruemmele@gmail.com>
  • Loading branch information
shetzel and WillieRuemmele authored Sep 30, 2021
1 parent 257c879 commit cf764bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/resolve/adapters/decomposedSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export class DecomposedSourceAdapter extends MixedContentSourceAdapter {
if (metaXml) {
const pathToContent = this.trimPathToContent(trigger);
const childTypeId = this.type.children.suffixes[metaXml.suffix];
const triggerIsAChild = !!childTypeId;

// If the child is explicitly not addressable, return the parent SourceComponent.
const triggerIsAChild =
!!childTypeId && this.type.children.types[childTypeId].isAddressable !== false;
const strategy = this.type.strategies.decomposition;
if (
triggerIsAChild &&
Expand Down
28 changes: 23 additions & 5 deletions test/resolve/adapters/decomposedSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import {
decomposedtoplevel,
mockRegistryData,
xmlInFolder,
matchingContentFile,
} from '../../mock/registry';
import { assert, expect } from 'chai';
import { VirtualTreeContainer, SourceComponent } from '../../../src';
import { expect } from 'chai';
import { VirtualTreeContainer, SourceComponent, MetadataType } from '../../../src';
import { RegistryTestUtil } from '../registryTestUtil';
import { join } from 'path';
import { META_XML_SUFFIX } from '../../../src/common';
import { TypeInferenceError } from '../../../src/errors';
import { nls } from '../../../src/i18n';

describe('DecomposedSourceAdapter', () => {
const type = mockRegistryData.types.decomposed;
Expand All @@ -39,6 +36,27 @@ describe('DecomposedSourceAdapter', () => {
);
});

it('should return parent SourceComponent when given a child xml of non-addressable type', () => {
const nonAddressableType = JSON.parse(
JSON.stringify(mockRegistryData.types.decomposedtoplevel)
) as MetadataType;
nonAddressableType.children.types.g.isAddressable = false;
const decompTree = new VirtualTreeContainer(decomposedtoplevel.DECOMPOSED_VIRTUAL_FS);
const decompAdapter = new DecomposedSourceAdapter(
nonAddressableType,
mockRegistry,
undefined,
decompTree
);
const expectedComp = new SourceComponent(
decomposedtoplevel.DECOMPOSED_TOP_LEVEL_COMPONENT,
decompTree
);
expectedComp.type.children.types.g.isAddressable = false;
const childComp = decomposedtoplevel.DECOMPOSED_TOP_LEVEL_CHILD_XML_PATHS[0];
expect(decompAdapter.getComponent(childComp)).to.deep.equal(expectedComp);
});

it('should return expected SourceComponent when given a child xml in its decomposed folder', () => {
const expectedChild = children.find((c) => c.xml === decomposed.DECOMPOSED_CHILD_XML_PATH_2);
expect(adapter.getComponent(decomposed.DECOMPOSED_CHILD_XML_PATH_2)).to.deep.equal(
Expand Down

0 comments on commit cf764bb

Please sign in to comment.