Skip to content

Commit e51349b

Browse files
committed
feat: enhance component preview functionality and add counter component
- Constructed and logged the full URL for the component preview. - Added logic to conditionally open the browser based on the OPEN_BROWSER environment variable. - Introduced a new CounterComponent with increment, decrement, and reset functionalities. - Created associated HTML, JavaScript, and metadata files for the CounterComponent. - Added initial test setup for the CounterComponent.
1 parent 1f731b3 commit e51349b

File tree

5 files changed

+111
-2
lines changed

5 files changed

+111
-2
lines changed

src/commands/lightning/dev/component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,18 @@ export default class LightningDevComponent extends SfCommand<void> {
129129
targetOrgArg
130130
);
131131

132-
// Open the browser and navigate to the right page
133-
await this.config.runCommand('org:open', launchArguments);
132+
// Construct and log the full URL that will be opened
133+
const connection = targetOrg.getConnection();
134+
// Decode the path once to match what org:open actually opens
135+
const decodedPath = decodeURIComponent(launchArguments[1]);
136+
const fullUrl = `${connection.instanceUrl}/${decodedPath}`;
137+
this.log(`PreviewURL: ${fullUrl}`);
138+
139+
// Open the browser and navigate to the right page (unless OPEN_BROWSER is set to true)
140+
if (process.env.OPEN_BROWSER !== 'false') {
141+
await this.config.runCommand('org:open', launchArguments);
142+
} else {
143+
// this.log('Skipping browser open due to OPEN_BROWSER environment variable');
144+
}
134145
}
135146
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { createElement } from 'lwc';
2+
import CounterComponent from 'c/counterComponent';
3+
4+
describe('c-counter-component', () => {
5+
afterEach(() => {
6+
// The jsdom instance is shared across test cases in a single file so reset the DOM
7+
while (document.body.firstChild) {
8+
document.body.removeChild(document.body.firstChild);
9+
}
10+
});
11+
12+
it('TODO: test case generated by CLI command, please fill in test logic', () => {
13+
// Arrange
14+
const element = createElement('c-counter-component', {
15+
is: CounterComponent,
16+
});
17+
18+
// Act
19+
document.body.appendChild(element);
20+
21+
// Assert
22+
// const div = element.shadowRoot.querySelector('div');
23+
expect(1).toBe(1);
24+
});
25+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<template>
2+
<div class="slds-card">
3+
<div class="slds-card__header slds-grid">
4+
<header class="slds-media slds-media_center slds-has-flexi-truncate">
5+
<div class="slds-media__body">
6+
<h2 class="slds-card__header-title">
7+
<span>Counter Component</span>
8+
</h2>
9+
</div>
10+
</header>
11+
</div>
12+
<div class="slds-card__body slds-card__body_inner">
13+
<div class="slds-align_absolute-center slds-m-bottom_medium">
14+
<span class="{countClass}" style="font-size: 3rem; font-weight: bold"> {count} </span>
15+
</div>
16+
<div class="slds-grid slds-grid_align-center slds-gutters">
17+
<div class="slds-col">
18+
<lightning-button
19+
variant="destructive"
20+
label="Decrement"
21+
onclick="{decrement}"
22+
class="slds-m-horizontal_x-small"
23+
>
24+
</lightning-button>
25+
</div>
26+
<div class="slds-col">
27+
<lightning-button variant="neutral" label="Reset" onclick="{reset}" class="slds-m-horizontal_x-small">
28+
</lightning-button>
29+
</div>
30+
<div class="slds-col">
31+
<lightning-button variant="success" label="Increment" onclick="{increment}" class="slds-m-horizontal_x-small">
32+
</lightning-button>
33+
</div>
34+
<div>test</div>
35+
</div>
36+
</div>
37+
</div>
38+
</template>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { LightningElement } from 'lwc';
2+
3+
export default class CounterComponent extends LightningElement {
4+
count = 0;
5+
6+
increment() {
7+
this.count++;
8+
}
9+
10+
decrement() {
11+
this.count--;
12+
}
13+
14+
reset() {
15+
this.count = 0;
16+
}
17+
18+
get isNegative() {
19+
return this.count < 0;
20+
}
21+
22+
get isPositive() {
23+
return this.count > 0;
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>62.0</apiVersion>
4+
<isExposed>true</isExposed>
5+
<targets>
6+
<target>lightning__AppPage</target>
7+
<target>lightning__RecordPage</target>
8+
<target>lightning__HomePage</target>
9+
</targets>
10+
</LightningComponentBundle>

0 commit comments

Comments
 (0)