Skip to content

Commit

Permalink
feat: add analytics dashboard lwc templates (#325)
Browse files Browse the repository at this point in the history
* feat: support aura/lwc component templates

@W-9191596@

* feat: analytics dashboard lwc templates

@W-9191596@

* fix: update to union type on LightningComponentOptions

and also use a hard-coded list on the options flag config for --template to
match for consistency.
  • Loading branch information
smithgp authored and jag-j committed Jun 3, 2021
1 parent b181384 commit b6b6e0f
Show file tree
Hide file tree
Showing 26 changed files with 434 additions and 76 deletions.
1 change: 1 addition & 0 deletions packages/plugin-templates/messages/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"MissingAuraFolder": "Lightning bundles must have a parent folder named 'aura'.",
"MissingAppname": "Missing required flag:\n -n, --appname APPNAME name of the generated Lightning app\nSee more help with --help\n",
"MissingComponentName": "Missing required flag:\n -n, --componentname COMPONENTNAME name of the generated Lightning component\nSee more help with --help\n",
"MissingLightningComponentTemplate": "Template %s not available for component type %s.",
"MissingLWCFolder": "Lightning bundles must have a parent folder named 'lwc'.",
"MissingEventname": "Missing required flag:\n -n, --eventname EVENTNAME name of the generated Lightning event\nSee more help with --help\n",
"MissingInterfacename": "Missing required flag:\n -n, --interfacename INTERFACENAME name of the generated Lightning interface\nSee more help with --help\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

import { flags } from '@salesforce/command';
import LightningComponentGenerator from '@salesforce/templates/lib/generators/lightningComponentGenerator';
import { CreateUtil } from '@salesforce/templates/lib/utils';
import { AnyJson } from '@salesforce/ts-types';
import { MessageUtil, TemplateCommand } from '../../../../utils';

const lightningComponentFileSuffix = /.cmp$/;
const BUNDLE_TYPE = MessageUtil.get('Component');

export default class LightningComponent extends TemplateCommand {
Expand Down Expand Up @@ -53,11 +51,10 @@ export default class LightningComponent extends TemplateCommand {
char: 't',
description: MessageUtil.get('TemplateFlagDescription'),
longDescription: MessageUtil.get('TemplateFlagLongDescription'),
default: 'DefaultLightningCmp',
options: CreateUtil.getCommandTemplatesForFiletype(
lightningComponentFileSuffix,
'lightningcomponent'
)
default: 'default',
// Note: keep this list here and LightningComponentOptions#template in-sync with the
// templates/lightningcomponents/[aura|lwc]/* folders
options: ['default', 'analyticsDashboard', 'analyticsDashboardWithStep']
}),
outputdir: flags.string({
char: 'd',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ describe('Lightning component creation tests:', () => {
);
}
);

test
.withOrg()
.withProject()
.stdout()
.command([
'force:lightning:component:create',
'--componentname',
'foo',
'--outputdir',
'aura',
'--template',
'default'
])
.it(
'should create lightning aura component files from default template in the aura output directory',
ctx => {
assert.file(AuraLightningTestFormatter.fileformatter('foo', 'foo'));
assert.file(path.join('aura', 'foo', 'foo.cmp-meta.xml'));
assert.fileContent(
path.join('aura', 'foo', 'foo.cmp-meta.xml'),
'<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">'
);
}
);
});

describe('Check lightning aura components creation without -meta.xml file', () => {
Expand Down Expand Up @@ -112,12 +137,12 @@ describe('Lightning component creation tests:', () => {
.it(
'should create lightning web component files in the lwc output directory with the internal flag for disabling -meta.xml files',
ctx => {
assert.file(
path.join('lwc', 'internallwctest', 'internallwctest.html')
);
assert.noFile(
path.join('lwc', 'internallwctest', 'internallwctest.js-meta.xml')
);
assert.file(
path.join('lwc', 'internallwctest', 'internallwctest.html')
);
assert.file(
path.join('lwc', 'internallwctest', 'internallwctest.js')
);
Expand All @@ -144,9 +169,119 @@ describe('Lightning component creation tests:', () => {
'lwc'
])
.it(
'should create lightning web component files in the lwc output directory with the internal flag for disabling -meta.xml files',
'should create lightning web component files in the lwc output directory',
ctx => {
assert.file(path.join('lwc', 'foo', 'foo.js-meta.xml'));
assert.file(path.join('lwc', 'foo', 'foo.html'));
assert.file(path.join('lwc', 'foo', 'foo.js'));
assert.fileContent(
path.join('lwc', 'foo', 'foo.js'),
'export default class Foo extends LightningElement {}'
);
}
);

test
.withOrg()
.withProject()
.stdout()
.command([
'force:lightning:component:create',
'--componentname',
'foo',
'--outputdir',
'lwc',
'--type',
'lwc',
'--template',
'default'
])
.it(
'should create lightning web component files from default template in the lwc output directory',
ctx => {
assert.file(path.join('lwc', 'foo', 'foo.js-meta.xml'));
assert.file(path.join('lwc', 'foo', 'foo.html'));
assert.file(path.join('lwc', 'foo', 'foo.js'));
assert.fileContent(
path.join('lwc', 'foo', 'foo.js'),
'export default class Foo extends LightningElement {}'
);
}
);
});

describe('Check analytics dashboard lwc creation', () => {
test
.withOrg()
.withProject()
.stdout()
.command([
'force:lightning:component:create',
'--componentname',
'foo',
'--outputdir',
'lwc',
'--type',
'lwc',
'--template',
'analyticsDashboard'
])
.it(
'should create analyticsDashboard lwc files in the lwc output directory',
ctx => {
const jsFile = path.join('lwc', 'foo', 'foo.js');
const metaFile = path.join('lwc', 'foo', 'foo.js-meta.xml');
assert.file(metaFile);
assert.file(path.join('lwc', 'foo', 'foo.html'));
assert.file(jsFile);
assert.fileContent(metaFile, '<target>analytics__Dashboard</target>');
assert.fileContent(metaFile, 'targets="analytics__Dashboard"');
assert.fileContent(metaFile, '<hasStep>false</hasStep>');
assert.fileContent(
jsFile,
'export default class Foo extends LightningElement {'
);
assert.fileContent(jsFile, '@api getState;');
assert.fileContent(jsFile, '@api setState;');
}
);
test
.withOrg()
.withProject()
.stdout()
.command([
'force:lightning:component:create',
'--componentname',
'foo',
'--outputdir',
'lwc',
'--type',
'lwc',
'--template',
'analyticsDashboardWithStep'
])
.it(
'should create analyticsDashboardWithStep lwc files in the lwc output directory',
ctx => {
const jsFile = path.join('lwc', 'foo', 'foo.js');
const metaFile = path.join('lwc', 'foo', 'foo.js-meta.xml');
assert.file(metaFile);
assert.file(path.join('lwc', 'foo', 'foo.html'));
assert.file(jsFile);
assert.fileContent(metaFile, '<target>analytics__Dashboard</target>');
assert.fileContent(metaFile, 'targets="analytics__Dashboard"');
assert.fileContent(metaFile, '<hasStep>true</hasStep>');
assert.fileContent(
jsFile,
'export default class Foo extends LightningElement {'
);
assert.fileContent(jsFile, '@api getState;');
assert.fileContent(jsFile, '@api setState;');
assert.fileContent(jsFile, '@api results;');
assert.fileContent(jsFile, '@api metadata;');
assert.fileContent(jsFile, '@api selection;');
assert.fileContent(jsFile, '@api setSelection;');
assert.fileContent(jsFile, '@api selectMode;');
}
);
});
Expand Down Expand Up @@ -184,5 +319,46 @@ describe('Lightning component creation tests:', () => {
.it('should throw missing lwc parent folder error', ctx => {
expect(ctx.stderr).to.contain(messages.getMessage('MissingLWCFolder'));
});
test
.withOrg()
.withProject()
.stderr()
.command([
'force:lightning:component:create',
'--outputdir',
'lwc',
'--componentname',
'foo',
'--type',
'lwc',
'--template',
'foo'
])
.it('should throw invalid template error', ctx => {
expect(ctx.stderr).to.contain(messages.getMessage('InvalidTemplate'));
});
test
.withOrg()
.withProject()
.stderr()
.command([
'force:lightning:component:create',
'--outputdir',
'aura',
'--componentname',
'foo',
'--type',
'aura',
'--template',
'analyticsDashboard'
])
.it('should throw missing template error', ctx => {
expect(ctx.stderr).to.contain(
messages.getMessage('MissingLightningComponentTemplate', [
'analyticsDashboard',
'aura'
])
);
});
});
});
Loading

0 comments on commit b6b6e0f

Please sign in to comment.