Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.

Commit c9b46ce

Browse files
authored
test: enable integration tests for lightning-empApi, lightning-formatted-address, and lightning-map (#266)
1 parent 3bf38e5 commit c9b46ce

File tree

19 files changed

+320
-2
lines changed

19 files changed

+320
-2
lines changed

integration-tests/environment/DefaultEnvironment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export default class DefaultEnvironment extends BaseEnvironment {
3636

3737
const project = new Project(this.projectPath);
3838
if (!project.configuration.api_version) {
39-
debug('no api version specified, using 49.0');
40-
project.configuration.api_version = '49.0';
39+
debug('no api version specified, using 50.0');
40+
project.configuration.api_version = '50.0';
4141
}
4242
if (
4343
project.configuration.port === undefined ||
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import PreviewPage from '../pageObjects/PreviewPage';
2+
3+
describe('lightning:empApi Component', () => {
4+
it('loads', async () => {
5+
let page = new PreviewPage('c', 'empApiLWC');
6+
await page.open();
7+
8+
// Verify the label input for 'Channel Name'
9+
const lightningInputLabel = await page.testComponent
10+
.then(el => el.shadow$('lightning-card'))
11+
.then(el => el.$('lightning-input'));
12+
expect(await lightningInputLabel.getText()).toBe('Channel Name');
13+
14+
// Verify the subscribe and unsubscribe lightning buttons are present
15+
const lightningButtons = await page.testComponent
16+
.then(el => el.shadow$('lightning-card'))
17+
.then(el => el.$$('lightning-button'));
18+
19+
expect(lightningButtons.length).toEqual(2);
20+
expect(
21+
await lightningButtons[0].shadow$('button[title="Subscribe"')
22+
).toBeTruthy();
23+
expect(
24+
await lightningButtons[1].shadow$('button[title="Unsubscribe"')
25+
).toBeTruthy();
26+
});
27+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<lightning-card title="EmpApi Example" icon-name="custom:custom14">
3+
<div class="slds-m-around_medium">
4+
<p>
5+
Use the buttons below to subscribe and unsubscribe to a
6+
streaming channel!
7+
</p>
8+
<lightning-input
9+
label="Channel Name"
10+
value={channelName}
11+
onchange={handleChannelName}
12+
></lightning-input>
13+
<lightning-button
14+
variant="success"
15+
label="Subscribe"
16+
title="Subscribe"
17+
onclick={handleSubscribe}
18+
disabled={isSubscribeDisabled}
19+
class="slds-m-left_x-small"
20+
></lightning-button>
21+
<lightning-button
22+
variant="destructive"
23+
label="Unsubscribe"
24+
title="Unsubscribe"
25+
onclick={handleUnsubscribe}
26+
disabled={isUnsubscribeDisabled}
27+
class="slds-m-left_x-small"
28+
></lightning-button>
29+
</div>
30+
</lightning-card>
31+
</template>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { LightningElement } from 'lwc';
2+
import { subscribe, unsubscribe, onError } from 'lightning/empApi';
3+
4+
export default class EmpApiLWC extends LightningElement {
5+
channelName = '/event/Test__e';
6+
isSubscribeDisabled = false;
7+
isUnsubscribeDisabled = !this.isSubscribeDisabled;
8+
9+
subscription = {};
10+
11+
// Tracks changes to channelName text field
12+
handleChannelName(event) {
13+
this.channelName = event.target.value;
14+
}
15+
16+
// Initializes the component
17+
connectedCallback() {
18+
// Register error listener
19+
this.registerErrorListener();
20+
}
21+
22+
// Handles subscribe button click
23+
handleSubscribe() {
24+
// Callback invoked whenever a new event message is received
25+
const messageCallback = function(response) {
26+
console.log('New message received: ', JSON.stringify(response));
27+
// Response contains the payload of the new message received
28+
};
29+
30+
// Invoke subscribe method of empApi. Pass reference to messageCallback
31+
subscribe(this.channelName, -1, messageCallback).then(response => {
32+
// Response contains the subscription information on subscribe call
33+
console.log(
34+
'Subscription request sent to: ',
35+
JSON.stringify(response.channel)
36+
);
37+
this.subscription = response;
38+
this.toggleSubscribeButton(true);
39+
});
40+
}
41+
42+
// Handles unsubscribe button click
43+
handleUnsubscribe() {
44+
this.toggleSubscribeButton(false);
45+
46+
// Invoke unsubscribe method of empApi
47+
unsubscribe(this.subscription, response => {
48+
console.log('unsubscribe() response: ', JSON.stringify(response));
49+
// Response is true for successful unsubscribe
50+
});
51+
}
52+
53+
toggleSubscribeButton(enableSubscribe) {
54+
this.isSubscribeDisabled = enableSubscribe;
55+
this.isUnsubscribeDisabled = !enableSubscribe;
56+
}
57+
58+
registerErrorListener() {
59+
// Invoke onError empApi method
60+
onError(error => {
61+
console.log('Received error from server: ', JSON.stringify(error));
62+
// Error contains the server-side error
63+
});
64+
}
65+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>50.0</apiVersion>
4+
<isExposed>true</isExposed>
5+
</LightningComponentBundle>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "emp-api-test",
3+
"version": "0.0.1",
4+
"description": "test",
5+
"author": "salesforce.com",
6+
"private": true
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"packageDirectories": [
3+
{
4+
"path": "force-app",
5+
"default": true,
6+
"package": "EmpApiTest",
7+
"versionName": "Winter '20",
8+
"versionNumber": "1.0.0.NEXT"
9+
}
10+
],
11+
"namespace": "",
12+
"sourceApiVersion": "50.0",
13+
"sfdcLoginUrl": "https://login.salesforce.com"
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import PreviewPage from '../pageObjects/PreviewPage';
2+
3+
describe('lightning:formatted-address Component', () => {
4+
it('loads', async () => {
5+
let page = new PreviewPage('c', 'formattedAddress');
6+
await page.open();
7+
8+
const formattedAddresses = await page.testComponent.then(el =>
9+
el.shadow$$('lightning-formatted-address')
10+
);
11+
expect(formattedAddresses.length).toBe(2);
12+
13+
// Verify address1 contains a google link
14+
const googleLinkElement = await formattedAddresses[0].shadow$('a');
15+
expect(await googleLinkElement.getText()).toBe(
16+
'121 Spear St.\nSan Francisco, CA 94105\nUS'
17+
);
18+
expect(await googleLinkElement.getAttribute('href')).toBe(
19+
'https://www.google.com/maps?q=121%20Spear%20St.%0ASan%20Francisco,%20CA%2094105%0AUS'
20+
);
21+
22+
// Verify address2 is plain text
23+
const plainTextElement = formattedAddresses[1];
24+
const children = await plainTextElement.shadow$$('*');
25+
expect(children.length).toBe(3);
26+
expect(await plainTextElement.$$('*').length).toBe(undefined);
27+
28+
// Verify address2 only contains children that are plain text
29+
expect(await children[0].getHTML()).toBe(
30+
'<div class="slds-truncate">121 Spear St.</div>'
31+
);
32+
expect(await children[1].getHTML()).toBe(
33+
'<div class="slds-truncate">San Francisco, CA 94105</div>'
34+
);
35+
expect(await children[2].getHTML()).toBe(
36+
'<div class="slds-truncate">US</div>'
37+
);
38+
});
39+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<template>
2+
<div class="slds-m-vertical_medium">
3+
<h1 class="slds-text-heading_small">Formatted Address</h1>
4+
<p class="slds-text-body_regular">
5+
This component formats an address and automatically links it to
6+
Google Maps.
7+
</p>
8+
</div>
9+
10+
<lightning-formatted-address
11+
street="121 Spear St."
12+
city="San Francisco"
13+
country="US"
14+
province="CA"
15+
postal-code="94105"
16+
></lightning-formatted-address>
17+
18+
<div class="slds-m-vertical_medium">
19+
<h1 class="slds-text-heading_small">Formatted Address in Plain Text</h1>
20+
<p class="slds-text-body_regular">
21+
This component formats an address but doesn't link to Google Maps.
22+
</p>
23+
</div>
24+
25+
<lightning-formatted-address
26+
street="121 Spear St."
27+
city="San Francisco"
28+
country="US"
29+
province="CA"
30+
postal-code="94105"
31+
disabled
32+
></lightning-formatted-address>
33+
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { LightningElement } from 'lwc';
2+
3+
export default class FormattedAddress extends LightningElement {}

0 commit comments

Comments
 (0)