Skip to content

Commit b162278

Browse files
committed
Custom Metadata rendering tests
1 parent b760ebd commit b162278

File tree

7 files changed

+107
-12
lines changed

7 files changed

+107
-12
lines changed

src/core/changelog/__test__/processing-changelog.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class CustomObjectMetadataBuilder {
5757
name: 'MyObject',
5858
description: null,
5959
fields: this.fields,
60+
metadataRecords: [],
6061
};
6162
}
6263
}

src/core/markdown/__test__/generating-custom-object-docs.spec.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { extendExpect } from './expect-extensions';
22
import { customFieldPickListValues, generateDocs, unparsedObjectBundleFromRawString } from './test-helpers';
33
import { assertEither } from '../../test-helpers/assert-either';
4-
import { unparsedFieldBundleFromRawString } from '../../test-helpers/test-data-builders';
4+
import {
5+
unparsedCustomMetadataFromRawString,
6+
unparsedFieldBundleFromRawString,
7+
} from '../../test-helpers/test-data-builders';
58
import { CustomObjectXmlBuilder } from '../../test-helpers/test-data-builders/custom-object-xml-builder';
69

710
describe('Generates Custom Object documentation', () => {
@@ -136,5 +139,73 @@ describe('Generates Custom Object documentation', () => {
136139
expect(result).documentationBundleHasLength(1);
137140
assertEither(result, (data) => expect(data).firstDocContains('`TestField__c`'));
138141
});
142+
143+
describe('when documenting Custom Metadata Types', () => {
144+
it('displays the Records heading if fields are present', async () => {
145+
const customObjectBundle = unparsedObjectBundleFromRawString({
146+
name: 'TestObject__mdt',
147+
rawContent: new CustomObjectXmlBuilder().build(),
148+
filePath: 'src/object/TestObject__mdt.object-meta.xml',
149+
});
150+
151+
const customMetadataBundle = unparsedCustomMetadataFromRawString({
152+
filePath: 'src/customMetadata/TestField__c.field-meta.xml',
153+
parentName: 'TestObject',
154+
apiName: 'TestObject.TestField__c',
155+
});
156+
157+
const result = await generateDocs([customObjectBundle, customMetadataBundle])();
158+
expect(result).documentationBundleHasLength(1);
159+
assertEither(result, (data) => expect(data).firstDocContains('## Records'));
160+
});
161+
162+
it('does not display the Records heading if no records are present', async () => {
163+
const input = unparsedObjectBundleFromRawString({
164+
name: 'TestObject__mdt',
165+
rawContent: new CustomObjectXmlBuilder().build(),
166+
filePath: 'src/object/TestObject__c.object-meta.xml',
167+
});
168+
169+
const result = await generateDocs([input])();
170+
expect(result).documentationBundleHasLength(1);
171+
assertEither(result, (data) => expect(data).not.firstDocContains('## Records'));
172+
});
173+
174+
it('displays the record label as a heading', async () => {
175+
const customObjectBundle = unparsedObjectBundleFromRawString({
176+
name: 'TestObject__mdt',
177+
rawContent: new CustomObjectXmlBuilder().build(),
178+
filePath: 'src/object/TestObject__mdt.object-meta.xml',
179+
});
180+
181+
const customMetadataBundle = unparsedCustomMetadataFromRawString({
182+
filePath: 'src/customMetadata/TestField__c.field-meta.xml',
183+
parentName: 'TestObject',
184+
apiName: 'TestObject.TestField__c',
185+
});
186+
187+
const result = await generateDocs([customObjectBundle, customMetadataBundle])();
188+
expect(result).documentationBundleHasLength(1);
189+
assertEither(result, (data) => expect(data).firstDocContains('## Test Metadata'));
190+
});
191+
192+
it('displays the record api name', async () => {
193+
const customObjectBundle = unparsedObjectBundleFromRawString({
194+
name: 'TestObject__mdt',
195+
rawContent: new CustomObjectXmlBuilder().build(),
196+
filePath: 'src/object/TestObject__mdt.object-meta.xml',
197+
});
198+
199+
const customMetadataBundle = unparsedCustomMetadataFromRawString({
200+
filePath: 'src/customMetadata/TestField__c.field-meta.xml',
201+
parentName: 'TestObject',
202+
apiName: 'TestObject.TestField__c',
203+
});
204+
205+
const result = await generateDocs([customObjectBundle, customMetadataBundle])();
206+
expect(result).documentationBundleHasLength(1);
207+
assertEither(result, (data) => expect(data).firstDocContains('TestObject.TestField__c'));
208+
});
209+
});
139210
});
140211
});

src/core/markdown/__test__/test-helpers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ export function unparsedApexBundleFromRawString(raw: string, rawMetadata?: strin
1515
export function unparsedObjectBundleFromRawString(meta: {
1616
rawContent: string;
1717
filePath: string;
18+
name?: string;
1819
}): UnparsedCustomObjectBundle {
1920
return {
2021
type: 'customobject',
21-
name: 'TestObject__c',
22+
name: meta.name ?? 'TestObject__c',
2223
filePath: meta.filePath,
2324
content: meta.rawContent,
2425
};
2526
}
2627

27-
export function generateDocs(apexBundles: UnparsedSourceBundle[], config?: Partial<MarkdownGeneratorConfig>) {
28-
return gen(apexBundles, {
28+
export function generateDocs(bundles: UnparsedSourceBundle[], config?: Partial<MarkdownGeneratorConfig>) {
29+
return gen(bundles, {
2930
targetDir: 'target',
3031
scope: ['global', 'public'],
3132
defaultGroupName: 'Miscellaneous',

src/core/markdown/adapters/type-to-renderable.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ function customMetadataToRenderable(metadata: CustomMetadataMetadata, headingLev
305305
type: 'metadata',
306306
headingLevel: headingLevel,
307307
heading: metadata.label ?? metadata.name,
308-
description: metadata.description ? [metadata.description] : [],
309308
apiName: metadata.apiName,
310309
label: metadata.label ?? metadata.name,
311310
protected: metadata.protected,

src/core/reflection/sobject/reflect-custom-metadata-source.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ export type CustomMetadataMetadata = {
1212
apiName: string;
1313
name: string;
1414
label?: string | null;
15-
description: string | null;
1615
parentName: string;
17-
// TODO: Reflect values
1816
};
1917

2018
export function reflectCustomMetadataSources(
@@ -57,9 +55,8 @@ function toCustomMetadataMetadata(parserResult: { CustomMetadata: unknown }): Cu
5755
parserResult?.CustomMetadata != null && typeof parserResult.CustomMetadata === 'object'
5856
? parserResult.CustomMetadata
5957
: {};
60-
const defaultValues = {
58+
const defaultValues: Partial<CustomMetadataMetadata> = {
6159
label: null,
62-
description: null,
6360
};
6461

6562
return {

src/core/renderables/types.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,9 @@ export type RenderableCustomMetadata = {
201201
headingLevel: number;
202202
heading: string;
203203
apiName: string;
204-
description: RenderableContent[];
205204
type: 'metadata';
206205
label: string;
207206
protected: boolean;
208-
// TODO: Add values?
209207
};
210208

211209
export type Renderable = (RenderableClass | RenderableInterface | RenderableEnum | RenderableCustomObject) & {

src/core/test-helpers/test-data-builders.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UnparsedCustomFieldBundle } from '../shared/types';
1+
import { UnparsedCustomFieldBundle, UnparsedCustomMetadataBundle } from '../shared/types';
22

33
export const customField = `
44
<?xml version="1.0" encoding="UTF-8"?>
@@ -25,3 +25,31 @@ export function unparsedFieldBundleFromRawString(meta: {
2525
parentName: meta.parentName,
2626
};
2727
}
28+
29+
export const customMetadata = `
30+
<?xml version="1.0" encoding="UTF-8"?>
31+
<CustomMetadata xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
32+
<label>Test Metadata</label>
33+
<protected>true</protected>
34+
<values>
35+
<field>Field1__c</field>
36+
<value xsi:type="xsd:string">Sample Value</value>
37+
</values>
38+
</CustomMetadata>
39+
`;
40+
41+
export function unparsedCustomMetadataFromRawString(meta: {
42+
rawContent?: string;
43+
filePath: string;
44+
apiName: string;
45+
parentName: string;
46+
}): UnparsedCustomMetadataBundle {
47+
return {
48+
type: 'custommetadata',
49+
name: meta.apiName,
50+
filePath: meta.filePath,
51+
content: meta.rawContent ?? customMetadata,
52+
apiName: meta.apiName,
53+
parentName: meta.parentName,
54+
};
55+
}

0 commit comments

Comments
 (0)